Errors in getParameterMetaData() when non-space characters in query
See original GitHub issueI discovered a variety of scenarios where PreparedStatement.getParameterMetaData()
either throws an exception or returns an incorrect parameter count in a subsequent call to getParameterCount()
, all of which appear to be related to the presence or absence of whitespace characters (spaces, newlines, tabs).
Below is a test suite Gist which demonstrates some of the issues. Five of the seven tests fail for me (the other two are just to demonstrate that the errors are only due to whitespace differences). Note that each test first executes the statement to prove that the statement really works and is not the problem; only fetching the parameter metadata is the problem. Please note that most of the issues with with line breaks also occur with tabs.
https://gist.github.com/chadberchek/1d0c686890a69e171e6e01d0ec6fffdb#file-experiment-java
Here is a summary of my results:
Test | Result |
---|---|
insertWithLineBreakBeforeTableName (build of 8103dc386f1210f93216c8a37fa4e018f98bdf38) | SQLServerException: Incorrect syntax near the keyword ‘WHERE’. |
insertWithLineBreakBeforeTableName (6.1.0.jre8) | SQLServerException: Unable to identify the table insert into experiment (id) values (?) for the metadata. |
insertWithNoSpaceAfterTableName | SQLServerException: Invalid column name ‘id’. |
updateWithLineBreakAfterWhere | SQLServerException: Incorrect syntax near the keyword ‘where’. |
updateWithLineBreakBeforeFirstParameter | Parameter count mismatch Expected :2 Actual :0 |
updateWithLineBreakAfterUpdate | SQLServerException: Unable to identify the table update experiment set id = ? where id = ? for the metadata. |
Tested with driver 6.1.0.jre8 and also a local build of 8103dc386f1210f93216c8a37fa4e018f98bdf38 (for JDK8) against Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64).
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hello @chadberchek , I created a PR #351 to fix the issues you found.
Thank you very much for providing the test code, it really helped a lot! Would you mind if I add your test code to the PR as one of the unit tests?
@ajlam I ran these tests with 4.0.2206.100 (from Maven, ‘com.microsoft.sqlserver:sqljdbc4:4.0.2206.100’) and got the same results.