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

Unable to update an Always Encrypted char/varchar column when sendStringParameterAsUnicode=false #2303

Open
tkyc opened this issue Jan 17, 2024 · 0 comments
Labels
Backlog The topic in question has been recognized and added to development backlog Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects

Comments

@tkyc
Copy link
Member

tkyc commented Jan 17, 2024

Driver version

All driver versions since AE and sendStringParametersAsunicode support.

SQL Server version

SQL Servers that support AE.

Client Operating System

Discovered on Windows 10.

JAVA/JVM version

Discovered on JDK 21

Table schema

Bug/issue applies to char/varchar types

CREATE TABLE [dbo].[YOUR-TABLE-NAME](
	[c1] [char](30) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [YOUR-CEK-NAME], ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL
) ON [PRIMARY]

Problem description

When updating an existing encrypted value on a char or varchar column and while sendStringParameterAsUnicode=false, the update fails. This works when sendStringParameterAsUnicode=true.

Expected behavior

The row update should succeed, and the new value should be in the table.

Actual behavior

Errors outs with the following message: The string is not in a valid hex format.

     [java] 			com.microsoft.sqlserver.jdbc.SQLServerException: The string is not in a valid hex format.
     [java] 				at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:233)
     [java] 				at com.microsoft.sqlserver.jdbc.ParameterUtils.hexToBin(ParameterUtils.java:21)
     [java] 				at com.microsoft.sqlserver.jdbc.AppDTVImpl$SetValueOp.execute(dtv.java:2043)
     [java] 				at com.microsoft.sqlserver.jdbc.DTV.executeOp(dtv.java:1661)
     [java] 				at com.microsoft.sqlserver.jdbc.AppDTVImpl.setValue(dtv.java:2296)
     [java] 				at com.microsoft.sqlserver.jdbc.DTV.setValue(dtv.java:149)
     [java] 				at com.microsoft.sqlserver.jdbc.Column.updateValue(Column.java:371)
     [java] 				at com.microsoft.sqlserver.jdbc.SQLServerResultSet.updateValue(SQLServerResultSet.java:3172)
     [java] 				at com.microsoft.sqlserver.jdbc.SQLServerResultSet.updateString(SQLServerResultSet.java:3486)
     [java] 				at BugFixTests.AE_update_varchar8000_value_longer_than8000(BugFixTests.java:364)
     [java] 				at BugFixTests.test_AE_update_varchar8000_value_longer_than8000(BugFixTests.java:85)
     [java] 				at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
     [java] 				at java.base/java.lang.reflect.Method.invoke(Method.java:580)
     [java] 				at CVariation.execute(CVariation.java:68)
     [java] 				at CTestItem.Execute(CTestItem.java:208)
     [java] 				at TestDriver.runItem(TestDriver.java:106)
     [java] 				at TestDriver.runItem(TestDriver.java:112)
     [java] 				at TestDriver.runItem(TestDriver.java:112)
     [java] 				at TestDriver.run(TestDriver.java:81)
     [java] 				at TestDriver.main(TestDriver.java:253)

Repro code

The connection string needs sendStringParameterAsUnicode=false.

            try (Statement queryStmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, con.getHoldability());
                    ResultSet rs = queryStmt.executeQuery("SELECT * FROM " + tableName3)) {

                rs.next();
                rs.updateString(1, "NEW STRING");
                rs.updateRow();
            }
@tkyc tkyc added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Jan 17, 2024
@lilgreenbird lilgreenbird added this to Under Investigation in MSSQL JDBC via automation Jan 19, 2024
@lilgreenbird lilgreenbird moved this from Under Investigation to Backlog in MSSQL JDBC Apr 3, 2024
@lilgreenbird lilgreenbird added the Backlog The topic in question has been recognized and added to development backlog label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog The topic in question has been recognized and added to development backlog Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
MSSQL JDBC
  
Backlog
Development

No branches or pull requests

2 participants