[BUG] Parameter metadata checking incorrectly parses column names preceded by "(" parenthesis in WHERE clause
See original GitHub issueDriver 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
- Expected Behaviour: When executing the following query, return the correct data
SELECT Bar from Foo WHERE (Bar = 'test')
- Actual behaviour: Error thrown: “Incorrect syntax near the keyword ‘FROM’.”
- 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]
- 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
(
andBar
SELECT Bar from Foo WHERE ( Bar = 'test')
JDBC trace logs
Reproduction code
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Issue is being tracked in #927, closing this issue.
@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.