Skip to content
Merged
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 @@ -528,7 +528,7 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
}

String dbName = connection.getSCatalog();
boolean needsPrepare = false;
boolean needsPrepare = true;
// Retry execution if existing handle could not be re-used.
for (int attempt = 1; attempt <= 2; ++attempt) {
try {
Expand All @@ -548,7 +548,7 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
getNextResult();
}
catch (SQLException e) {
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt))
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare))
continue;
else
throw e;
Expand All @@ -566,13 +566,13 @@ else if (EXECUTE_UPDATE == executeMethod && null != resultSet) {

/** Should the execution be retried because the re-used cached handle could not be re-used due to server side state changes? */
private boolean retryBasedOnFailedReuseOfCachedHandle(SQLException e,
int attempt) {
int attempt, boolean needsPrepare) {
// Only retry based on these error codes and if statementPooling is enabled:
// 586: The prepared statement handle %d is not valid in this context. Please verify that current database, user default schema, and
// ANSI_NULLS and QUOTED_IDENTIFIER set options are not changed since the handle is prepared.
// 8179: Could not find prepared statement with handle %d.
// 99586: Error used for testing.
return 1 == attempt && (586 == e.getErrorCode() || 8179 == e.getErrorCode() || 99586 == e.getErrorCode()) && connection.isStatementPoolingEnabled();
if(needsPrepare) return false;
return 1 == attempt && (586 == e.getErrorCode() || 8179 == e.getErrorCode()) && connection.isStatementPoolingEnabled();
}

/**
Expand Down Expand Up @@ -2629,7 +2629,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
}

String dbName = connection.getSCatalog();
boolean needsPrepare = false;
boolean needsPrepare = true;
// Retry execution if existing handle could not be re-used.
for (int attempt = 1; attempt <= 2; ++attempt) {
try {
Expand Down Expand Up @@ -2692,7 +2692,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
throw e;

// Retry if invalid handle exception.
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt)) {
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare)) {
// reset number of batches prepare
numBatchesPrepared = numBatchesExecuted;
retry = true;
Expand Down Expand Up @@ -2723,7 +2723,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
}
}
catch (SQLException e) {
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt) && connection.isStatementPoolingEnabled()) {
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare) && connection.isStatementPoolingEnabled()) {
// Reset number of batches prepared.
numBatchesPrepared = numBatchesExecuted;
continue;
Expand Down