Add prepareMethod=none execution path and tests#2890
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2890 +/- ##
============================================
+ Coverage 58.87% 59.40% +0.52%
- Complexity 4778 4811 +33
============================================
Files 151 151
Lines 34748 34786 +38
Branches 5827 5829 +2
============================================
+ Hits 20457 20663 +206
+ Misses 11502 11324 -178
- Partials 2789 2799 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new prepareMethod=none connection property option that always uses literal parameter substitution and SQL Batch execution for all prepared statements, regardless of whether temporary tables are present. This differs from the existing scopeTempTablesToConnection option (introduced in PR #2844), which only uses direct SQL execution when temporary table operations are detected.
Changes:
- Added
NONE("none")enum value to thePrepareMethodenum inSQLServerDriver.java - Updated execution logic in
SQLServerPreparedStatement.javato handle the new prepare method in three key areas: request type selection, statement handle caching, and batch execution - Added comprehensive test coverage for basic functionality and SQL batch execution scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java | Added NONE enum value to PrepareMethod and included it in the available choices array for the prepareMethod connection property |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java | Added isPrepareMethodNone flag checks in doExecutePreparedStatement, reuseCachedHandle, doPrepExec, and doExecutePreparedStatementBatch to enable direct SQL execution path for the new prepare method |
| src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java | Added tests to verify the none prepare method can be set via connection property and works for basic insert operations |
| src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java | Added 14 comprehensive tests covering basic functionality (temp table persistence, CRUD operations, batch execution, multiple data types, NULL values, SELECT queries) and SQL batch execution patterns (multiple parameterized statements, non-parameterized statements, parameter mapping, error handling, large batches) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
Outdated
Show resolved
Hide resolved
...om/microsoft/sqlserver/jdbc/unit/statement/PrepareMethodScopeTempTablesToConnectionTest.java
Show resolved
Hide resolved
…eCachedHandle() and doPrepExec() methods. Added 4 more tests using prepareMethod=none via connection string property
Summary
This PR introduces a new prepareMethod=none connection property option that uses literal parameter substitution + SQL Batch execution for all prepared statements.
When prepareMethod=none is set, the driver always uses literal parameter substitution + SQL Batch for ALL prepared statements, bypassing server-side prepared statement handles (sp_prepexec/sp_prepare). This provides server-side visibility for performance tuning and query analysis.
Changes
Added NONE("none") to PrepareMethod enum in SQLServerDriver.java
Added isPrepareMethodNone execution path in SQLServerPreparedStatement.java
Tests
Basic Functionality Tests:
testBasicOperationsWithPrepareMethodNone - Tests basic CRUD operations with direct SQL execution
testBatchExecutionWithPrepareMethodNone - Validates batch insert operations work correctly
testMultipleDataTypesWithPrepareMethodNone - Tests literal parameter substitution for INT, BIGINT, DECIMAL, FLOAT, VARCHAR, NVARCHAR, BIT, DATE, DATETIME2
testNullValuesWithPrepareMethodNone - Ensures NULL values are correctly substituted in SQL
testSelectQueryWithPrepareMethodNone - Tests parameterized SELECT queries with LIKE and comparison operators
SQL Batch Execution Tests:
testBatchMultipleParameterizedStatementsWithNone - Multiple INSERT statements with parameters in single batch
testBatchNonParameterizedBetweenParameterizedWithNone - Non-parameterized statement (DELETE) between parameterized INSERTs
testBatchMultipleParametersPerStatementWithNone - Verifies correct parameter-to-position mapping across multiple statements
testBatchOnlyNonParameterizedStatementsWithNone - Batch execution with no parameters
testBatchWithStringLiteralsAndCommentsWithNone - SQL parsing edge cases - semicolons in string literals, comments
testBatchParameterMappingCorrectnessWithNone - Validates exact parameter values are inserted in correct tables/columns
testBatchCombinedWithErrorsWithNone - Error handling - duplicate key violation throws SQLException
testLargeBatchWithNone - Scalability test with 100 batch statements