Repository navigation
feat(sap): support locking in select - #11996
Conversation
User descriptionDescription of changeAdd locking support in Fixes #11985. Pull-Request Checklist
PR TypeEnhancement, Tests Description
Diagram Walkthroughflowchart LR
A["SelectQueryBuilder"] -->|"Add SAP HANA support"| B["createLockExpression"]
B -->|"pessimistic_read"| C["FOR SHARE LOCK"]
B -->|"pessimistic_write"| D["FOR UPDATE"]
B -->|"skip_locked"| E["IGNORE LOCKED"]
B -->|"nowait"| F["NOWAIT"]
G["Tests"] -->|"Validate SAP syntax"| H["Lock mode assertions"]
I["Documentation"] -->|"Update matrix"| J["SAP HANA row"]
|
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Tests |
| ||||
| Documentation |
|
PR Code Suggestions ✨Latest suggestions up to 99f2745
Previous suggestionsSuggestions up to commit 8baeee2
Suggestions up to commit 8174ff2
Suggestions up to commit a8e7fda
Suggestions up to commit f47549e
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewⓘ The new review experience is currently in Beta. Learn more Previous review resultsReview updated until commit 99f2745 Results up to commit 8baeee2
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewResults up to commit 8174ff2
1. Early return skips connections
|
commit: |
f47549e to
a8e7fda
Compare
|
Persistent review updated to latest commit a8e7fda |
gioboa
left a comment
There was a problem hiding this comment.
It looks great to me 👏 thanks
a8e7fda to
8174ff2
Compare
|
Persistent review updated to latest commit 8174ff2 |
| for (const connection of connections) { | ||
| if ( | ||
| DriverUtils.isSQLiteFamily(connection.driver) || | ||
| connection.driver.options.type === "spanner" | ||
| ) { | ||
| return | ||
| } |
There was a problem hiding this comment.
1. Early return skips connections 📘 Rule violation ⛯ Reliability
Several locking tests now use return inside a for (const connection of connections) loop, which exits the entire test on the first unsupported driver instead of skipping just that driver. This can hide failures on later connections and is inconsistent/bug-prone test control flow.
Agent Prompt
## Issue description
Several tests iterate over `connections` using `for (const connection of connections)` but use `return` to skip unsupported drivers. In a loop, `return` exits the entire test function, so subsequent connections are never validated.
## Issue Context
This refactor changes test behavior compared to the prior `connections.map(...)` approach where `return` only exited the callback for a single connection. This is likely unintentional and can mask failures.
## Fix Focus Areas
- test/functional/query-builder/locking/query-builder-locking.test.ts[33-51]
- test/functional/query-builder/locking/query-builder-locking.test.ts[328-342]
- test/functional/query-builder/locking/query-builder-locking.test.ts[344-420]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (this.expressionMap.lockTables) { | ||
| if ( | ||
| !( | ||
| DriverUtils.isPostgresFamily(driver) || | ||
| driver.options.type === "cockroachdb" | ||
| ) | ||
| ) { | ||
| if (!DriverUtils.isPostgresFamily(driver)) { | ||
| throw new TypeORMError( | ||
| "Lock tables not supported in selected driver", | ||
| ) | ||
| } | ||
| if (this.expressionMap.lockTables.length < 1) { | ||
| throw new TypeORMError("lockTables cannot be an empty array") | ||
| } | ||
| lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ") | ||
| lockTablesClause = | ||
| " OF " + | ||
| this.expressionMap.lockTables | ||
| .map((lockTable) => driver.escape(lockTable)) | ||
| .join(", ") |
There was a problem hiding this comment.
2. Double-escaped locktables 🐞 Bug ✓ Correctness
createLockExpression() now escapes lockTables, but the FindOptions path already stores escaped alias names, resulting in double-quoted identifiers (e.g., OF ""post"") and invalid SQL for Postgres/Cockroach when FindOptions.lock.tables is used.
Agent Prompt
### Issue description
`FindOptions.lock.tables` currently stores escaped alias names into `expressionMap.lockTables`, but `createLockExpression()` now escapes `lockTables` again. This produces invalid SQL (double quotes) for Postgres-family drivers when `tables` are provided.
### Issue Context
- `applyFindOptions()` maps `lock.tables` to `this.escape(tableAlias.name)`.
- `createLockExpression()` now maps `expressionMap.lockTables` through `driver.escape()`.
- On Postgres/Cockroach, `escape()` adds double quotes, so an already-escaped value becomes double-escaped.
### Fix Focus Areas
- src/query-builder/SelectQueryBuilder.ts[3457-3495]
- src/query-builder/SelectQueryBuilder.ts[2815-2829]
### Expected change
- In `applyFindOptions()`, pass raw alias names (e.g., `tableAlias.name`) to `setLock(...)` (do not pre-escape).
- Keep escaping in `createLockExpression()` (or use `this.escape(...)` to respect `disableEscaping`) so values are escaped exactly once.
- Add/adjust tests that exercise `FindOptions.lock.tables` to ensure the produced SQL uses a single escaping layer (e.g., `FOR UPDATE OF "post"`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
8174ff2 to
8baeee2
Compare
|
Persistent review updated to latest commit 8baeee2 |
8baeee2 to
99f2745
Compare
|
Persistent review updated to latest commit 99f2745 |
Description of change
Add locking support in
SELECTfor SAP HANA.Fixes #11985.
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)