Skip to content

Add prepareMethod=none execution path and tests#2890

Open
divang wants to merge 6 commits intomainfrom
dev/divang/preparemethod-none
Open

Add prepareMethod=none execution path and tests#2890
divang wants to merge 6 commits intomainfrom
dev/divang/preparemethod-none

Conversation

@divang
Copy link
Contributor

@divang divang commented Feb 2, 2026

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

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.40%. Comparing base (dfdadee) to head (134b11a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 91.66% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the PrepareMethod enum in SQLServerDriver.java
  • Updated execution logic in SQLServerPreparedStatement.java to 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…eCachedHandle() and doPrepExec() methods. Added 4 more tests using prepareMethod=none via connection string property
@divang divang added this to the 13.3.2 milestone Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants