Skip to content

Commit

Permalink
Merge pull request #220 from v-xiangs/reuse-encryption-metadata
Browse files Browse the repository at this point in the history
retrieve paramater encryption metadata if they are not retrieved yet
  • Loading branch information
Suraiya Hameed authored Mar 30, 2017
2 parents 82c62ec + 277b50e commit 5885874
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS

/** Flag set to true when statement execution is expected to return the prepared statement handle */
private boolean expectPrepStmtHandle = false;

/**
* Flag set to true when all encryption metadata of inOutParam is retrieved
*/
private boolean encryptionMetadataIsRetrieved = false;

// Internal function used in tracing
String getClassNameInternal() {
Expand Down Expand Up @@ -202,6 +207,7 @@ final void closeInternal() {
* @param sql
*/
/* L0 */ final void initParams(String sql) {
encryptionMetadataIsRetrieved = false;
int nParams = 0;

// Figure out the expected number of parameters by counting the
Expand All @@ -219,6 +225,7 @@ final void closeInternal() {
/* L0 */ public final void clearParameters() throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "clearParameters");
checkClosed();
encryptionMetadataIsRetrieved = false;
int i;
if (inOutParam == null)
return;
Expand Down Expand Up @@ -413,16 +420,25 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}

boolean hasNewTypeDefinitions = buildPreparedStrings(inOutParam, false);
boolean hasNewTypeDefinitions = true;
if (!encryptionMetadataIsRetrieved) {
hasNewTypeDefinitions = buildPreparedStrings(inOutParam, false);
}

if ((Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < inOutParam.length) && !isInternalEncryptionQuery) {
getParameterEncryptionMetadata(inOutParam);

// maxRows is set to 0 when retreving encryption metadata,
// need to set it back
setMaxRowsAndMaxFieldSize();
// retrieve paramater encryption metadata if they are not retrieved yet
if (!encryptionMetadataIsRetrieved) {
getParameterEncryptionMetadata(inOutParam);
encryptionMetadataIsRetrieved = true;

// maxRows is set to 0 when retreving encryption metadata,
// need to set it back
setMaxRowsAndMaxFieldSize();
}

// fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on Connection
buildPreparedStrings(inOutParam, true);
hasNewTypeDefinitions = buildPreparedStrings(inOutParam, true);
}

// Start the request and detach the response reader so that we can
Expand Down

0 comments on commit 5885874

Please sign in to comment.