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.
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.
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.