Skip to content

Commit 9754078

Browse files
authored
Fixed timestamp string conversion error for cstmt (#2449)
* Fixed timestamp string conversion error for cstmt * Code review comments p1 * Fixed sproc used in test
1 parent e8f09c2 commit 9754078

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/main/java/com/microsoft/sqlserver/jdbc/dtv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.sql.Blob;
2525
import java.sql.Clob;
2626
import java.sql.SQLException;
27+
import java.sql.Timestamp;
2728
import java.text.MessageFormat;
2829
import java.time.LocalDate;
2930
import java.time.LocalDateTime;
@@ -1643,6 +1644,8 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException {
16431644
op.execute(this, ((Geometry) value).serialize());
16441645
} else if (JDBCType.GEOGRAPHY == jdbcType) {
16451646
op.execute(this, ((Geography) value).serialize());
1647+
} else if (JDBCType.TIMESTAMP == jdbcType) {
1648+
op.execute(this, Timestamp.valueOf((String) value));
16461649
} else {
16471650
if (null != cryptoMeta) {
16481651
// if streaming types check for allowed data length in AE

src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public class CallableStatementTest extends AbstractTest {
6565
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_Table"));
6666
private static String manyParamProc = AbstractSQLGenerator
6767
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_Procedure"));
68+
private static String currentTimeProc = AbstractSQLGenerator
69+
.escapeIdentifier(RandomUtil.getIdentifier("currentTime_Procedure"));
6870
private static String manyParamUserDefinedType = AbstractSQLGenerator
6971
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_definedType"));
7072
private static String zeroParamSproc = AbstractSQLGenerator
@@ -108,6 +110,7 @@ public static void setupTest() throws Exception {
108110
createUserDefinedType();
109111
createTableManyParams();
110112
createProcedureManyParams();
113+
createProcedureCurrentTime();
111114
createGetObjectOffsetDateTimeProcedure(stmt);
112115
createProcedureZeroParams();
113116
createOutOfOrderSproc();
@@ -1224,6 +1227,17 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {
12241227
}
12251228
}
12261229

1230+
@Test
1231+
public void testTimestampStringConversion() throws SQLException {
1232+
try (CallableStatement stmt = connection.prepareCall("{call " + currentTimeProc + "(?)}")) {
1233+
String timestamp = "2024-05-29 15:35:53.461";
1234+
stmt.setObject(1, timestamp, Types.TIMESTAMP);
1235+
stmt.registerOutParameter(1, Types.TIMESTAMP);
1236+
stmt.execute();
1237+
stmt.getObject("currentTimeStamp");
1238+
}
1239+
}
1240+
12271241
/**
12281242
* Cleanup after test
12291243
*
@@ -1242,6 +1256,7 @@ public static void cleanup() throws SQLException {
12421256
TestUtils.dropProcedureIfExists(zeroParamSproc, stmt);
12431257
TestUtils.dropProcedureIfExists(outOfOrderSproc, stmt);
12441258
TestUtils.dropProcedureIfExists(byParamNameSproc, stmt);
1259+
TestUtils.dropProcedureIfExists(currentTimeProc, stmt);
12451260
TestUtils.dropFunctionIfExists(userDefinedFunction, stmt);
12461261
}
12471262
}
@@ -1294,6 +1309,14 @@ private static void createProcedureManyParams() throws SQLException {
12941309
}
12951310
}
12961311

1312+
private static void createProcedureCurrentTime() throws SQLException {
1313+
String sql = "CREATE PROCEDURE " + currentTimeProc + " @currentTimeStamp datetime = null OUTPUT " +
1314+
"AS BEGIN SET @currentTimeStamp = CURRENT_TIMESTAMP; END";
1315+
try (Statement stmt = connection.createStatement()) {
1316+
stmt.execute(sql);
1317+
}
1318+
}
1319+
12971320
private static void createTableManyParams() throws SQLException {
12981321
String type = manyParamUserDefinedType;
12991322
String sql = "CREATE TABLE" + manyParamsTable + " (c1 " + type + " null, " + "c2 " + type + " null, " + "c3 "

0 commit comments

Comments
 (0)