Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver not handling properly result set with VARCHAR or CHAR types #439

Closed
rodionstl opened this issue Aug 12, 2017 · 3 comments
Closed
Assignees

Comments

@rodionstl
Copy link

Driver version or jar name

6.3.0.jre8-preview

SQL Server version

Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)

Client operating system

Ubuntu 16.04.2 LTS

Java/JVM version

openjdk version "1.8.0_131"

Problem description

ResultSet.next() method fails with "java.lang.IllegalArgumentException: Invalid SQL Server data type 0" if the previous row contains either VARCHAR or CHAR types.

It starts working if you comment out the following line
https://github.com/Microsoft/mssql-jdbc/blob/ca55cc340969fbf6f1787c69a0cd52d9856a74c4/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java#L4208-L4208

Repro code

Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE sql_var_tab(val sql_variant)");
PreparedStatement prepStmt = conn.prepareStatement("INSERT INTO sql_var_tab VALUES (?)");
prepStmt.setObject(1, "abc", Types.VARCHAR);
prepStmt.execute();
prepStmt.setObject(1, 42, Types.INTEGER);
prepStmt.execute();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM sql_var_tab ORDER BY val");
while (resultSet.next()) {
    resultSet.getObject(1);
}
@AfsanehR-zz
Copy link
Contributor

Thanks @rodionstl for opening this issue and mentioning the fix. We created pr #442 to fix this issue.

@rodionstl
Copy link
Author

There is another similar issue.

ResultSet resultSet = stmt.executeQuery("SELECT cast('abc' as sql_variant) UNION ALL SELECT cast(42 as sql_variant)");
while (resultSet.next()) {
    resultSet.getObject(1);
}

Removing this line solves it.
https://github.com/Microsoft/mssql-jdbc/blob/ca55cc340969fbf6f1787c69a0cd52d9856a74c4/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java#L4184

@AfsanehR-zz
Copy link
Contributor

@rodionstl appreciate the testing. Will put the fix in the same pr #442. Please feel free to share other findings. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants