Driver version
7.2.0 jre11
SQL Server version
Any
Client Operating System
Any Windows
JAVA/JVM version
OpenJDK 11
Problem description
For some reason only fist prepared statement query is parsed correctly
UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE code=:S1 AND (cnt=-1 OR cnt=-2 OR addedCnt<cnt)
and
UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE (cnt=-1 OR cnt=-2 OR addedCnt<cnt) AND code=:S1
- Expected behaviour: Both queries are parsed and works equal
- Actual behaviour: First prepared statement parse does not find parameters at all
- Error message/stack trace:
While trying to set parameter value following error has been thrown
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range.
at com.microsoft.sqlserver//com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:228)
at com.microsoft.sqlserver//com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:1124)
at com.microsoft.sqlserver//com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:1138)
at com.microsoft.sqlserver//com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(SQLServerPreparedStatement.java:1683)
PS: Both one works nicely in 7.1.4
Reproduction code
PreparedStatement st1 = conn.prepareStatement(
"UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE code=? AND (cnt=-1 OR cnt=-2 OR addedCnt<cnt)");
PreparedStatement st2 = conn.prepareStatement(
"UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE (cnt=-1 OR cnt=-2 OR addedCnt<cnt) AND code=?");
st1.setString(1, "x");
//This one fails
st2.setString(1, "x");
Driver version
7.2.0 jre11
SQL Server
versionAny
Client Operating System
Any Windows
JAVA/JVM version
OpenJDK 11
Problem description
For some reason only fist prepared statement query is parsed correctly
UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE code=:S1 AND (cnt=-1 OR cnt=-2 OR addedCnt<cnt)and
UPDATE TxCounter SET addedCnt=addedCnt+1 OUTPUT INSERTED.addedCnt WHERE (cnt=-1 OR cnt=-2 OR addedCnt<cnt) AND code=:S1While trying to set parameter value following error has been thrown
PS: Both one works nicely in 7.1.4
Reproduction code