Repository navigation
fix(mssql): place lock hint inside nested join parentheses (issue #12764) - #12785
HosnainRafi wants to merge 1 commit into
Conversation
…eorm#12764) When using lock modes (NOLOCK, HOLDLOCK, UPDLOCK) with nested JOINs in MSSQL, the lock hint was incorrectly placed after the closing parenthesis of nested joins, producing invalid SQL. The lock hint must be placed immediately after the table alias, before any child joins. Fixes typeorm#12764
Code Review by Qodo
1. Issue test added under github-issues
|
|
This repository was recently restructured into a pnpm workspace, and the If your branch has diverged enough that a full rebase isn't worth it, Sorry for the disruption, and thanks for your patience. |
Summary
When using lock modes (
pessimistic_read,pessimistic_write, ordirty_read) with nested JOINs in MSSQL, TypeORM generates invalid SQL because the lock hint (WITH (NOLOCK),WITH (HOLDLOCK, ROWLOCK), orWITH (UPDLOCK, ROWLOCK)) is incorrectly placed after the closing parenthesis of nested joins.Buggy Output (Before Fix)
The lock hint appears after the closing
)of the nested join group, which is invalid MSSQL syntax.Correct Output (After Fix)
The lock hint appears immediately after the table alias, before any child joins.
Root Cause
In
buildJoinClause()inSelectQueryBuilder.ts, the lock expression was appended afterchildJoinsand the closing parenthesis (postfix), rather than before them. In MSSQL, theWITH (...)lock hint must immediately follow the table name/alias it applies to.Fix
Moved
this.createTableLockExpression()to appear after the table alias but beforechildJoinsandpostfix.Tests
Added a new test file at
test/github-issues/12764/issue-12764.test.tswith entity definitions and test cases that verify:dirty_readlock placesWITH (NOLOCK)correctly inside nested joinspessimistic_readlock placesWITH (HOLDLOCK, ROWLOCK)correctly inside nested joinspessimistic_writelock placesWITH (UPDLOCK, ROWLOCK)correctly inside nested joinsThese tests require an MSSQL connection and will be validated by CI.
Fixes #12764