Skip to content

Commit ee044a8

Browse files
tkycJeffery-Wasty
andauthored
Fixed timestamp string conversion error for cstmt (#2449) (#2455)
* Fixed timestamp string conversion error for cstmt * Code review comments p1 * Fixed sproc used in test Co-authored-by: Jeff Wasty <v-jeffwasty@microsoft.com>
1 parent df57d98 commit ee044a8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

+3
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;
@@ -1627,6 +1628,8 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException {
16271628
op.execute(this, ((Geometry) value).serialize());
16281629
} else if (JDBCType.GEOGRAPHY == jdbcType) {
16291630
op.execute(this, ((Geography) value).serialize());
1631+
} else if (JDBCType.TIMESTAMP == jdbcType) {
1632+
op.execute(this, Timestamp.valueOf((String) value));
16301633
} else {
16311634
if (null != cryptoMeta) {
16321635
// if streaming types check for allowed data length in AE

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

+23
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class CallableStatementTest extends AbstractTest {
7070
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_Table"));
7171
private static String manyParamProc = AbstractSQLGenerator
7272
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_Procedure"));
73+
private static String currentTimeProc = AbstractSQLGenerator
74+
.escapeIdentifier(RandomUtil.getIdentifier("currentTime_Procedure"));
7375
private static String manyParamUserDefinedType = AbstractSQLGenerator
7476
.escapeIdentifier(RandomUtil.getIdentifier("manyParam_definedType"));
7577
private static String zeroParamSproc = AbstractSQLGenerator
@@ -114,6 +116,7 @@ public static void setupTest() throws Exception {
114116
createUserDefinedType();
115117
createTableManyParams();
116118
createProcedureManyParams();
119+
createProcedureCurrentTime();
117120
createGetObjectOffsetDateTimeProcedure(stmt);
118121
createProcedureZeroParams();
119122
createOutOfOrderSproc();
@@ -1260,6 +1263,17 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException {
12601263
}
12611264
}
12621265

1266+
@Test
1267+
public void testTimestampStringConversion() throws SQLException {
1268+
try (CallableStatement stmt = connection.prepareCall("{call " + currentTimeProc + "(?)}")) {
1269+
String timestamp = "2024-05-29 15:35:53.461";
1270+
stmt.setObject(1, timestamp, Types.TIMESTAMP);
1271+
stmt.registerOutParameter(1, Types.TIMESTAMP);
1272+
stmt.execute();
1273+
stmt.getObject("currentTimeStamp");
1274+
}
1275+
}
1276+
12631277
/**
12641278
* Cleanup after test
12651279
*
@@ -1278,6 +1292,7 @@ public static void cleanup() throws SQLException {
12781292
TestUtils.dropProcedureIfExists(zeroParamSproc, stmt);
12791293
TestUtils.dropProcedureIfExists(outOfOrderSproc, stmt);
12801294
TestUtils.dropProcedureIfExists(byParamNameSproc, stmt);
1295+
TestUtils.dropProcedureIfExists(currentTimeProc, stmt);
12811296
TestUtils.dropProcedureIfExists(conditionalSproc, stmt);
12821297
TestUtils.dropFunctionIfExists(userDefinedFunction, stmt);
12831298
}
@@ -1331,6 +1346,14 @@ private static void createProcedureManyParams() throws SQLException {
13311346
}
13321347
}
13331348

1349+
private static void createProcedureCurrentTime() throws SQLException {
1350+
String sql = "CREATE PROCEDURE " + currentTimeProc + " @currentTimeStamp datetime = null OUTPUT " +
1351+
"AS BEGIN SET @currentTimeStamp = CURRENT_TIMESTAMP; END";
1352+
try (Statement stmt = connection.createStatement()) {
1353+
stmt.execute(sql);
1354+
}
1355+
}
1356+
13341357
private static void createConditionalProcedure() throws SQLException {
13351358
String sql = "CREATE PROCEDURE " + conditionalSproc + " @param0 INT, @param1 INT, @maybe bigint = 2 " +
13361359
"AS BEGIN IF @maybe >= 2 BEGIN SELECT 5 END END";

0 commit comments

Comments
 (0)