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..e4bebf9ac 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 " + currentTimeProc + "(?)}")) { + 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,14 @@ private static void createProcedureManyParams() throws SQLException { } } + private static void createProcedureCurrentTime() throws SQLException { + 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 "