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

Fixed timestamp string conversion error for cstmt #2449

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +110,7 @@ public static void setupTest() throws Exception {
createUserDefinedType();
createTableManyParams();
createProcedureManyParams();
createProcedureCurrentTime();
createGetObjectOffsetDateTimeProcedure(stmt);
createProcedureZeroParams();
createOutOfOrderSproc();
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -1294,6 +1309,15 @@ private static void createProcedureManyParams() throws SQLException {
}
}

private static void createProcedureCurrentTime() throws SQLException {
String type = manyParamUserDefinedType;
tkyc marked this conversation as resolved.
Show resolved Hide resolved
String sql = "CREATE PROCEDURE " + currentTimeProc + "@currentTimeStamp datetime = null OUTPUT " +
"AS BEGIN SET @currentTimeStamp = CURRENT_TIMESTAMP; END";
tkyc marked this conversation as resolved.
Show resolved Hide resolved
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 "
Expand Down
Loading