Handled sp_prepexec call for Column encryption enabled#2663
Merged
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2663 +/- ##
============================================
+ Coverage 51.62% 51.70% +0.08%
- Complexity 4008 4030 +22
============================================
Files 147 147
Lines 33800 33804 +4
Branches 5650 5652 +2
============================================
+ Hits 17448 17479 +31
+ Misses 13888 13881 -7
+ Partials 2464 2444 -20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
ADO pipeline is successful. |
David-Engel
reviewed
May 14, 2025
Collaborator
David-Engel
left a comment
There was a problem hiding this comment.
No general objections to these changes. But we should add tests to cover the scenario this is fixing.
added 4 commits
May 15, 2025 16:02
…rypted columns can handle string values of varying sizes correctly
David-Engel
reviewed
May 16, 2025
…ressionAlwaysEncryptedTest.java Co-authored-by: David Engel <[email protected]>
…om/microsoft/mssql-jdbc into user/divang/Encrypted_Column_issue
Contributor
Author
|
ADO pipeline is successful. |
…t be encrypted using deterministic encryption.
David-Engel
previously approved these changes
May 19, 2025
…lue is not set for the parameter numbers
…SQLServerPreparedStatement.java
Contributor
Author
|
Successful run ADO pipeline |
machavan
approved these changes
May 21, 2025
muskan124947
approved these changes
May 21, 2025
divang
added a commit
that referenced
this pull request
Jun 9, 2025
…" (#2675) This reverts commit 52303d8. Co-authored-by: Divang Sharma <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
The incident involved unexpected behavior when inserting strings using Always Encrypted with Secure Enclaves in Azure SQL DB.
Unexpected insert results when using Always Encrypted.
Subsequent inserts into encrypted columns fail after initial successful inserts.
Issue in details at code level:
The buildPreparedStrings method compares the last prepared statement with the current one to be executed. If both statements are identical, it signals that calling sp_prepexec is unnecessary. Otherwise, sp_prepexec will be invoked later in the driver's execution flow. However, multiple calls to buildPreparedStrings overwrite the preparedTypeDefinitions variable, which stores the current prepared statement. As a result, repeated invocations can lead to the loss of the original statement, affecting the logic that determines whether sp_prepexec should be called with updated data types and lengths.
Resolution details:
Within the buildPreparedStrings method, the preparedTypeDefinitions variable is cached in preparedTypeDefinitionsPrev to prevent it from being overwritten. If isAEv2() is enabled, renewDefinition is false, and isInternalEncryptionQuery is true, then the driver caches the preparedTypeDefinitions value into preparedTypeDefinitionsPrev. In subsequent calls to buildPreparedStrings, if isAEv2() is still enabled, renewDefinition is true, and isInternalEncryptionQuery is false, the driver restores preparedTypeDefinitions from the cached preparedTypeDefinitionsPrev. This caching mechanism prevents the loss of the original statement and ensures the correct signal is returned regarding whether to invoke sp_prepexec.
Testing