Handle SQL Comments at Start of Query in getGenerateKeys() Method#2731
Merged
Handle SQL Comments at Start of Query in getGenerateKeys() Method#2731
Conversation
…h a comment close #2729
machavan
approved these changes
Aug 7, 2025
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2731 +/- ##
============================================
- Coverage 51.66% 51.51% -0.15%
+ Complexity 4112 4067 -45
============================================
Files 149 149
Lines 34240 34242 +2
Branches 5718 5719 +1
============================================
- Hits 17690 17641 -49
- Misses 14110 14112 +2
- Partials 2440 2489 +49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
divang
approved these changes
Aug 7, 2025
muskan124947
approved these changes
Aug 7, 2025
David-Engel
approved these changes
Aug 8, 2025
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.
Summary
This update addresses a bug where getGeneratedKeys() fails for INSERT statements that begin with SQL comments (e.g., /* ... */ INSERT ...). The method previously relied on a naive string check that only matched queries starting directly with "INSERT", causing errors or missing generated keys. This PR revises the logic to correctly identify and handle INSERT statements even when preceded by comments.
Background (Issue #2729)
Issue: When executing an INSERT statement that begins with a comment and requesting generated keys, the call to getGeneratedKeys() fails with an unrelated error:
.
What Changed
Updated the logic in SQLServerStatement (within the getGenerateKeys() handling) to use the internal isInsert() utility method, which:
This change ensures that identity retrieval is correctly triggered for valid INSERT statements even if comments precede them.
Impact
Fixes getGeneratedKeys() issue when SQL statements have leading comments.
Resolves the user-reported bug in #2729, aligning behavior with user expectations.
Testing
Manually tested locally and added a test case with an INSERT statement that starts with a comment:
Now, the generated keys are returned as intended
Closes: Issue #2729