question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Parameter metadata checking incorrectly parses column names preceded by "(" parenthesis in WHERE clause

See original GitHub issue

Driver version

7.0.0

SQL Server version

Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64) Jun 28 2012 08:36:30 Copyright © Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)

Client Operating System

Mac OS Mojave

JAVA/JVM version

jre8

Table schema

CREATE TABLE Foo
(
  Bar VARCHAR(50) NOT NULL
)

Problem description

  1. Expected Behaviour: When executing the following query, return the correct data SELECT Bar from Foo WHERE (Bar = 'test')
  2. Actual behaviour: Error thrown: “Incorrect syntax near the keyword ‘FROM’.”
  3. Error message/stack trace: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'FROM'. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1608) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:859) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:759) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:243) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:218) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:688) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:653) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3057) ~[mssql-jdbc-7.0.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3068) ~[mssql-jdbc-7.0.0.jre8.jar:na] at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221) ~[tomcat-dbcp.jar:7.0.92] at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221) ~[tomcat-dbcp.jar:7.0.92]
  4. Any other details that can be helpful: It looks like the parser for getting the metadata is including preceding parenthesis when it parses for column names. If turn off metadata checking, it works just fine with the preceding parenthesis When I re-enable metadata checking, the following SQL statement works just fine, returning rows. Note the space between ( and Bar SELECT Bar from Foo WHERE ( Bar = 'test')

JDBC trace logs

Reproduction code

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peterbaecommented, Jan 9, 2019

Issue is being tracked in #927, closing this issue.

0reactions
drewclausoncommented, Jan 8, 2019

@peterbae - Thanks. Looks to me like the opening parenthesis just may need to be included in the delimiter string in the StringTokenizer here. Hope that helps. For now, I’ll just not get the metadata.

Edit: to put in permalink to code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
Parameterize an SQL IN clause - Stack Overflow
(For the examples here, I use a literal string value in place of the column name.) A row with a Name value of...
Read more >
2 Server Error Message Reference - MySQL :: Developer Zone
Message: Incorrect table definition; there can be only one auto column ... Check the 'Function Name Parsing and Resolution' section in the Reference...
Read more >
An error occurred while checking the query syntax. Errors ...
You had a ',' character after last column (l.timeStamp - it needs to be removed). I only use square brackets if there's a...
Read more >
Legacy SQL Functions and Operators | BigQuery - Google Cloud
When referencing columns from a table, you can use the simple column name or you can ... A subquery is a nested SELECT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found