Conversation
- Add EXEC enum value to PrepareMethod for direct execution without preparation
- Implement Sybase DYNAMIC_PREPARE=false equivalent functionality
- Update reuseCachedHandle to disable caching for exec method
- Modify doPrepExec to bypass statement preparation when using exec method
- Add comprehensive tests for temp table persistence and parameter binding
- Update resource strings for proper documentation
This enables seamless migration from Sybase applications by providing
direct statement execution without preparation, ensuring temp tables
persist across executions as expected by legacy Sybase applications.
Connection usage:
String url = "jdbc:sqlserver://server:1433;databaseName=mydb;prepareMethod=exec";
DataSource usage:
SQLServerDataSource ds = new SQLServerDataSource();
ds.setPrepareMethod("exec");
This reverts commit f8811ea.
- Implemented SqlServerPreparedStatementExpander utility class for expanding prepared statement placeholders with actual parameter values - Added support for prepareMethod=exec to enable direct execution mode similar to Sybase's DYNAMIC_PREPARE=false - Handles proper SQL syntax parsing to avoid replacing placeholders inside strings, comments, or delimited identifiers - Implements smart NULL handling with operator rewrites (= ? -> IS NULL, <> ? -> IS NOT NULL, != ? -> IS NOT NULL, IS ? -> IS NULL, IS NOT ? -> IS NOT NULL) - Formats various data types: strings (with single quote escaping), numbers, booleans (as 1/0), dates/times, byte arrays (as hex), CLOBs, BLOBs - Added comprehensive JUnit test suite (23 test cases) covering all scenarios - Added demo class for manual testing and verification - Updated SQLServerConnection to use the new expander when useDirectValues=true in replaceParameterMarkers
- Fix operator detection to check for two-char operators (!=, <>) before single-char
- Fix spacing issues when replacing operators with IS NULL/IS NOT NULL
- Fix string literal parsing to properly handle escaped quotes ('')
- All 23 tests now pass successfully
…ev/divang/sybase-migration-dynamic-prepare
* Add comprehensive test coverage for EXEC prepare method * commented testFourPartSyntaxCallEscapeSyntax due to linked server error
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
machavan
reviewed
Nov 26, 2025
machavan
reviewed
Nov 26, 2025
- Moved expandSQLWithParameters() and helper methods from SqlServerPreparedStatementExpander to SQLServerConnection - Converted from static utility class pattern to instance methods - Deleted obsolete SqlServerPreparedStatementExpander class and associated test files - Simplified replaceParameterMarkers() to call expandSQLWithParameters() directly - Reduced code duplication by ~280 lines
…improve numeric formatting - Check sendStringParametersAsUnicode config before adding N prefix to string literals - Improve Float/Double formatting using BigDecimal to avoid precision loss - Separate integer type handling from floating-point types for better precision control
…g formatting - Updated Clob value formatting to respect sendStringParametersAsUnicode setting - Updated fallback case (toString) to respect sendStringParametersAsUnicode setting
- Simplified replaceParameterMarkers when useDirectValues=true by directly iterating paramPositions array instead of complex SQL parsing - Removed expandSQLWithParameters() method which is no longer needed - Uses existing paramPositions array to replace ? markers with formatted values
…rely after encountering a single statement error, instead of marking the failed statement with EXECUTE_FAILED (-3) and continuing with remaining statements.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2844 +/- ##
============================================
+ Coverage 58.98% 59.05% +0.06%
- Complexity 4739 4807 +68
============================================
Files 151 151
Lines 34575 34748 +173
Branches 5776 5827 +51
============================================
+ Hits 20395 20519 +124
- Misses 11404 11488 +84
+ Partials 2776 2741 -35 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
machavan
reviewed
Dec 5, 2025
…ToConnection - Updated exception message checking to traverse the entire exception cause chain - Changed from simple message check to comprehensive search through all causes - Now checks for 'CHECK constraint' or 'constraint' in any exception in the chain - Fixes test failure in testConstraintViolationBasicPrepareStatementScopeTemp - Applied fix to both Use Case 1 and Use Case 3 for consistency
- Added hasConstraintViolationMessage() helper to check multiple keywords - Added getExceptionMessageChain() helper for better error diagnostics - Now checks for: 'check constraint', 'constraint', 'violated', 'check', and SQL error code 547 - Uses case-insensitive matching for more robust detection - Provides full exception chain in assertion message for debugging - Applied to both Use Case 1 and Use Case 3 consistently
…nBasicPrepareStatementScopeTemp
Contributor
muskan124947
left a comment
There was a problem hiding this comment.
Posted some cleanup related comments
…odScopeTempTablesToConnectionTest, PreparedStatementTest
Ananya2
reviewed
Jan 16, 2026
…QLServerPreparedStatement and fix the test cases acordingly
machavan
reviewed
Jan 16, 2026
… add regression test
…lse-negative when ## precedes #TempTable
…pTablesToConnection in BatchCombinedExecutionTest class
…sToConnectionTest and remove redundant test classes
028219d to
599457b
Compare
machavan
reviewed
Jan 19, 2026
…bles and consolidate batch tests
…to enable scopeTempTablesToConnection
machavan
reviewed
Jan 20, 2026
machavan
approved these changes
Jan 20, 2026
muskan124947
approved these changes
Jan 20, 2026
Ananya2
approved these changes
Jan 20, 2026
…ration-dynamic-prepare
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.
Objective:
Enable prepared statements to work correctly with temporary tables by providing an alternative execution method that uses literal parameter substitution instead of server-side prepared statement handles. This addresses scenarios where temporary tables created within prepared statements are not visible in subsequent executions due to session scoping issues with sp_prepexec.
Solution:
New value: Added scopeTempTablesToConnection as a new option to the existing connection property (alongside prepexec and prepare)
Temporary table detection: Implemented logic to automatically detect temporary table operations (#temp, not global temp table) in SQL statements
Literal parameter substitution: When [prepareMethod=scopeTempTablesToConnection] is set and temp tables are detected, the driver replaces parameter markers (?) with properly formatted literal values directly in the SQL string
Parameter formatting: Implemented comprehensive formatLiteralValue() method in SQLServerConnection to handle:
Smart fallback: Automatically falls back to standard prepared statement execution when no temp tables are detected
Batch execution fixes: Improved batch update count handling for comma-separated SQL statements and proper error handling (EXECUTE_FAILED=-3) for individual statement failures
Testing:
PrepareMethodExecTest: Comprehensive tests covering various data types and scenarios
SQLServerPreparedStatementTempTableTest: Tests for temporary table scoping and detection logic
BatchExecutionTest: Enhanced batch execution tests with temp table scenarios
FormatLiteralValueNumericTest: Tests for numeric value formatting
FormatLiteralValueDateTimeTest: Tests for date/time value formatting
CallableStatementTest enhancements: Added tests for callable statement parameter handling