Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public String toString() {
enum PrepareMethod {
PREPEXEC("prepexec"), // sp_prepexec, default prepare method
PREPARE("prepare"),
EXEC("exec"); // direct execution without preparation, for Sybase migration compatibility
EXEC("exec");

private final String value;

Expand Down Expand Up @@ -841,7 +841,7 @@ public final class SQLServerDriver implements java.sql.Driver {
SQLServerDriverStringProperty.SERVER_CERTIFICATE.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.PREPARE_METHOD.toString(),
SQLServerDriverStringProperty.PREPARE_METHOD.getDefaultValue(), false,
new String[] {PrepareMethod.PREPEXEC.toString(), PrepareMethod.PREPARE.toString()}),
new String[] {PrepareMethod.PREPEXEC.toString(), PrepareMethod.PREPARE.toString(), PrepareMethod.EXEC.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(),
SQLServerDriverStringProperty.FAILOVER_PARTNER.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,28 @@ public void testCallableStatementSpPrepareAE() throws SQLException {
}
}

@Test
public void testCallableStatementExecAE() throws SQLException {
AETestConnectionString += ";prepareMethod=exec;";

try (Statement statement = PrepUtil.getConnection(AETestConnectionString, AEInfo).createStatement();) {
statement.executeUpdate("create procedure " + prepareMethodProcedure + " as select 1 --");

try (CallableStatement callableStatement = PrepUtil.getConnection(AETestConnectionString, AEInfo)
.prepareCall("{call " + prepareMethodProcedure + "}")) {
try (ResultSet rs = callableStatement.executeQuery()) {
rs.next();
assertEquals(1, rs.getInt(1), TestResource.getResource("R_setDataNotEqual"));
}

try (ResultSet rs = callableStatement.executeQuery()) {
rs.next();
assertEquals(1, rs.getInt(1), TestResource.getResource("R_setDataNotEqual"));
}
}
}
}

private static void dropProcedures() throws SQLException {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropProcedureIfExists(multiStatementsProcedure, stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ public void testCallableStatementSpPrepare() throws SQLException {
}
}

@Test
public void testCallableStatementExec() throws SQLException {
connection.setPrepareMethod("exec");

try (Statement statement = connection.createStatement();) {
statement.executeUpdate("create procedure " + procName + " as select 1 --");

try (CallableStatement callableStatement = connection.prepareCall("{call " + procName + "}")) {
try (ResultSet rs = callableStatement.executeQuery()) {
rs.next();
assertEquals(1, rs.getInt(1), TestResource.getResource("R_setDataNotEqual"));
}

try (ResultSet rs = callableStatement.executeQuery()) {
rs.next();
assertEquals(1, rs.getInt(1), TestResource.getResource("R_setDataNotEqual"));
}
} finally {
TestUtils.dropProcedureIfExists(procName, statement);
}
}
}

/**
* Tests CallableStatement.getString() with uniqueidentifier parameter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ public void testBatchUpdateCountTrueOnFirstPstmtSpPrepare() throws Exception {
testBatchUpdateCountWith(5, 4, true, "prepare", expectedUpdateCount);
}

/**
* This tests the updateCount when the error query does cause a SQL state HY008.
*
* @throws Exception
*/
@Test
public void testBatchUpdateCountFalseOnFirstPstmtExec() throws Exception {
long[] expectedUpdateCount = {1, 1, 1, 1, -3, -3, -3, -3, -3, -3};
testBatchUpdateCountWith(10, 6, false, "exec", expectedUpdateCount);
}

/**
* This tests the updateCount when the error query does cause a SQL state HY008.
*
* @throws Exception
*/
@Test
public void testBatchUpdateCountTrueOnFirstPstmtExec() throws Exception {
long[] expectedUpdateCount = {1, 1, -3, -3, -3};
testBatchUpdateCountWith(5, 4, true, "exec", expectedUpdateCount);
}

@Test
public void testSqlServerBulkCopyCachingPstmtLevel() throws Exception {
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Expand Down Expand Up @@ -526,6 +548,15 @@ public void testBatchSpPrepare() throws Exception {
testExecuteBatch1UseBulkCopyAPI();
}

@Test
public void testBatchExec() throws Exception {
connectionString += ";prepareMethod=exec;";
testAddBatch1();
testExecuteBatch1();
testAddBatch1UseBulkCopyAPI();
testExecuteBatch1UseBulkCopyAPI();
}

@Test
public void testBatchStatementCancellation() throws Exception {
String testTable = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("test_table"));
Expand Down
Loading