Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Bugfix for Native Query: "?" in SQL comments is treated as bindable query parameter #852

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rfelcman
Copy link
Contributor

Bugfix + unit test for a bug #822 .

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
* @return Query string without line comments.
*/
private String removeLineComments(String queryString) {
StringTokenizer multiLineTokenizer = new StringTokenizer(queryString, "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work for windows line endings (\r\n) as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that it is tested at NamedNativeQueryJUnitTest.java line 175

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>

while (multiLineTokenizer.hasMoreTokens()) {
String s = multiLineTokenizer.nextToken();
if (!"--".equals(s.trim().substring(0,2)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about comments at the end of the line?

insert into table_name (col1, col2)
  values
     (1,2), -- a comment is also possible here, right?
     (3,4);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also -- can be part of a string, e.g.

-- valid comment ? (1)
insert into table_name (textCol)
  values -- valid comment ? (2)
     ('test test -- no comment ?
-- no comment ? test test
test test');

Above code would remove comment (1), not detect comment (2) and accidentally remove the second "no comment" line inside a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants