Skip to content

A processing error "Incorrect syntax near '?'." occurred. in buildExecuteMetadata #848

@and-costea

Description

@and-costea

Driver version

7.0.0

SQL Server version

Microsoft SQL Server 2017 (RTM-CU10) (KB4342123) - 14.0.3037.1 (X64)
Jul 27 2018 09:40:27
Copyright (C) 2017 Microsoft Corporation
Express Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)

Client Operating System

Fedora 28

JAVA/JVM version

openjdk version "1.8.0_181"

Table schema

No schema is necessary.

Problem description

Incorrect syntax error is thrown when getting the metadata.

  1. Expected behaviour: query should work
  2. Actual behaviour: exception is thrown.
  3. Error message/stack trace:
A processing error "Incorrect syntax near '?'." occurred.
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:226) 
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildExecuteMetaData(SQLServerPreparedStatement.java:1089) 
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getMetaData(SQLServerPreparedStatement.java:1058)
...
  1. Any other details that can be helpful: see miinimized test case

JDBC trace logs

don't think they're necessary.

Reproduction code

Minimized test case of the function com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.replaceMarkerWithNull:

package com.microsoft.sqlserver.jdbc;

import static com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.replaceMarkerWithNull;

public class Something {
  public static void main(String[] args) {
    String x = "select (case when 1 = ? then 1 else 0 end) as [a '], (case when 1 = ? then 1 else 0 end) as [b ']";
    System.out.println(replaceMarkerWithNull(x));
  }
}

output:

select (case when 1 = null then 1 else 0 end) as [a '], (case when 1 = ? then 1 else 0 end) as [b ']

expected (I assume):

select (case when 1 = null then 1 else 0 end) as [a '], (case when 1 = null then 1 else 0 end) as [b ']

When we change the query to:

select (case when 1 = ? then 1 else 0 end) as [a ?], (case when 1 = ? then 1 else 0 end) as [b ']

we get

select (case when 1 = null then 1 else 0 end) as [a null], (case when 1 = null then 1 else 0 end) as [b ']

which I guess is also wrong since it will give a different column name in the metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in the driver. A high priority item that one can expect to be addressed quickly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions