From 88f12b70be8570945a0c178d25e1f0e5d6e4823b Mon Sep 17 00:00:00 2001 From: Terry Chow Date: Tue, 11 Jun 2024 14:07:08 -0700 Subject: [PATCH 1/3] Fixed timestamp string conversion error for cstmt --- .../com/microsoft/sqlserver/jdbc/dtv.java | 3 +++ .../CallableStatementTest.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java index 3c08a80cd..db9685e3d 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java @@ -24,6 +24,7 @@ import java.sql.Blob; import java.sql.Clob; import java.sql.SQLException; +import java.sql.Timestamp; import java.text.MessageFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -1643,6 +1644,8 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException { op.execute(this, ((Geometry) value).serialize()); } else if (JDBCType.GEOGRAPHY == jdbcType) { op.execute(this, ((Geography) value).serialize()); + } else if (JDBCType.TIMESTAMP == jdbcType) { + op.execute(this, Timestamp.valueOf((String) value)); } else { if (null != cryptoMeta) { // if streaming types check for allowed data length in AE diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index a399e53f7..42414e4d0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -65,6 +65,8 @@ public class CallableStatementTest extends AbstractTest { .escapeIdentifier(RandomUtil.getIdentifier("manyParam_Table")); private static String manyParamProc = AbstractSQLGenerator .escapeIdentifier(RandomUtil.getIdentifier("manyParam_Procedure")); + private static String currentTimeProc = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("currentTime_Procedure")); private static String manyParamUserDefinedType = AbstractSQLGenerator .escapeIdentifier(RandomUtil.getIdentifier("manyParam_definedType")); private static String zeroParamSproc = AbstractSQLGenerator @@ -108,6 +110,7 @@ public static void setupTest() throws Exception { createUserDefinedType(); createTableManyParams(); createProcedureManyParams(); + createProcedureCurrentTime(); createGetObjectOffsetDateTimeProcedure(stmt); createProcedureZeroParams(); createOutOfOrderSproc(); @@ -1224,6 +1227,17 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { } } + @Test + public void testTimestampStringConversion() throws SQLException { + try (CallableStatement stmt = connection.prepareCall("{call dbo.CurrentTime(?)}")) { + String timestamp = "2024-05-29 15:35:53.461"; + stmt.setObject(1, timestamp, Types.TIMESTAMP); + stmt.registerOutParameter(1, Types.TIMESTAMP); + stmt.execute(); + stmt.getObject("currentTimeStamp"); + } + } + /** * Cleanup after test * @@ -1242,6 +1256,7 @@ public static void cleanup() throws SQLException { TestUtils.dropProcedureIfExists(zeroParamSproc, stmt); TestUtils.dropProcedureIfExists(outOfOrderSproc, stmt); TestUtils.dropProcedureIfExists(byParamNameSproc, stmt); + TestUtils.dropProcedureIfExists(currentTimeProc, stmt); TestUtils.dropFunctionIfExists(userDefinedFunction, stmt); } } @@ -1294,6 +1309,15 @@ private static void createProcedureManyParams() throws SQLException { } } + private static void createProcedureCurrentTime() throws SQLException { + String type = manyParamUserDefinedType; + String sql = "CREATE PROCEDURE " + currentTimeProc + "@currentTimeStamp datetime = null OUTPUT " + + "AS BEGIN SET @currentTimeStamp = CURRENT_TIMESTAMP; END"; + try (Statement stmt = connection.createStatement()) { + stmt.execute(sql); + } + } + private static void createTableManyParams() throws SQLException { String type = manyParamUserDefinedType; String sql = "CREATE TABLE" + manyParamsTable + " (c1 " + type + " null, " + "c2 " + type + " null, " + "c3 " From 78face938dce03eb2c377466240ddec0a49be8fa Mon Sep 17 00:00:00 2001 From: Terry Chow Date: Thu, 13 Jun 2024 12:56:11 -0700 Subject: [PATCH 2/3] Code review comments p1 --- .../jdbc/callablestatement/CallableStatementTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 42414e4d0..2a2601d7d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1310,8 +1310,7 @@ private static void createProcedureManyParams() throws SQLException { } private static void createProcedureCurrentTime() throws SQLException { - String type = manyParamUserDefinedType; - String sql = "CREATE PROCEDURE " + currentTimeProc + "@currentTimeStamp datetime = null OUTPUT " + + String sql = "CREATE PROCEDURE " + currentTimeProc + " @currentTimeStamp datetime = null OUTPUT " + "AS BEGIN SET @currentTimeStamp = CURRENT_TIMESTAMP; END"; try (Statement stmt = connection.createStatement()) { stmt.execute(sql); From 676d7ee2515d90565dc95e99584bb77011dbfbba Mon Sep 17 00:00:00 2001 From: Terry Chow Date: Thu, 13 Jun 2024 13:02:37 -0700 Subject: [PATCH 3/3] Fixed sproc used in test --- .../sqlserver/jdbc/callablestatement/CallableStatementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 2a2601d7d..e4bebf9ac 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1229,7 +1229,7 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { @Test public void testTimestampStringConversion() throws SQLException { - try (CallableStatement stmt = connection.prepareCall("{call dbo.CurrentTime(?)}")) { + try (CallableStatement stmt = connection.prepareCall("{call " + currentTimeProc + "(?)}")) { String timestamp = "2024-05-29 15:35:53.461"; stmt.setObject(1, timestamp, Types.TIMESTAMP); stmt.registerOutParameter(1, Types.TIMESTAMP);