Revert "Handled sp_prepexec call for Column encryption enabled (#2663)" #2675
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.
This reverts commit 52303d8.
Issues Summary:
The incident involved unexpected behavior when inserting using Always Encrypted with Secure Enclaves in Azure SQL DB.
Issue in details at code level:
The doExecutePreparedStatement() method invokes buildPreparedStrings(), which updates the preparedSQL and preparedTypeDefinitions, and also returns a flag indicating whether preparedTypeDefinitions was modified.
The issue arises because the method is expected to use only the result of the first buildPreparedStrings() call to determine the hasNewTypeDefinitions flag. This flag is crucial, as it helps decide whether to initiate the sp_prepexec call—based on its value in combination with other conditions.
However, the current implementation updates the hasNewTypeDefinitions variable on each buildPreparedStrings() call. This leads to incorrect behavior: if later calls do not indicate a type definition change, the earlier (valid) indication of change is overwritten, and the sp_prepexec call is incorrectly skipped when parameter type definitions actually change.
Revert reason:
In the buildPreparedStrings method, caching the preparedTypeDefinitions variable in preparedTypeDefinitionsPrev to prevent it from being overwritten is both unnecessary and not an appropriate solution to the underlying issue. A more accurate and effective resolution has been identified (below one) and will be implemented in a follow-up PR.
Resolution details:
The issue was resolved by ensuring that the hasNewTypeDefinitions flag is set only once, based on the result of the first call to buildPreparedStrings().
Subsequent calls to buildPreparedStrings() are now used solely to update the preparedSQL variable and are no longer allowed to overwrite the hasNewTypeDefinitions flag. This guarantees that any change in parameter type definitions detected during the first evaluation is preserved, ensuring that the sp_prepexec call is correctly triggered when required.
This change aligns with the intended design and prevents silent failures due to skipped sp_prepexec calls when parameter type definitions change.