Comments in named queries?

Have read several posts here that seem to clearly state that comments (in the SQL) cause problems, errors, index out of range etc.

I’m assuming this is still the case?

And that the (Settings) tab’s (Description) field is the next best and safest place to add, what would be, comments to your SQL?

Comments are fine, it’s just that our parser is (currently) too dumb to distinguish a commented parameter from a legitimate one, so:

SELECT * FROM TABLE WHERE 
A = :param
--AND B = :param2

Should be fine, but is what currently throws an error, because the parser thinks it needs an additional value for param2.

2 Likes

Well, the JDBC spec does not explicitly say comments are allowed, just that at least single statements are accepted. Some drivers accept more, or even SQL scripts.

1 Like

Hi togehter,
I found this topic, because suddenly I had the same issue.
I have a small script in a Named query where I have a comment with an existing param, I have already used at another line in this script (:varOrderNumber).

It worked fine the last months (Ignition version 8.1.25)
Today I noticed, that the query faults with the error message: "The index 3 is out of range."

As you mentioned,I can get rid of this error by deleting the comment.
But contrary to what you described, changing the param to an unknown param like :abc does also work.

The only thing I changed in the last days: I updated our gateway to version 8.1.33.
Could it be, that this caused my problem ?

Now I have to control every script, if I have a comment with an existing param.
I thought an update would improve the performance and offers new features instead of additional bugs.

The issue is known for 3 years and still exists :open_mouth:

Sometimes Ignition causes a lot of gray hairs.

IA attempted to fix the parser to skip comments, but it broke other people's legitimate single-statement, standard JDBC queries. So that was reverted. 8.1.25 must be in the middle of that version span.

JDBC does not support SQL scripts. Some JDBC drivers do. JDBC does not support colon-delimited named parameters. Ignition's Named Query system patches colon-delimited parameters to be question marks and assembles the values for them in order. Anything less than a full brand-specific SQL language parser will have problems doing that conditionally.

Don't expect this to ever be fixed in Ignition. Don't use features of SQL scripts, like comments, in Ignition, if you wish to future-proof your code.

Hopefully, some future JDBC spec will provide tools for named parameters, but I wouldn't hold my breath waiting.

3 Likes