From 6c054b3558d6089263ed10c926ff980eb611aa11 Mon Sep 17 00:00:00 2001 From: Olivier Cavadenti Date: Tue, 7 Dec 2021 22:51:15 +0100 Subject: [PATCH 1/2] ForUpdate array parameter --- lib/query/querybuilder.js | 6 +++++- test/unit/query/builder.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/query/querybuilder.js b/lib/query/querybuilder.js index 4b923879be..c70f4d9274 100644 --- a/lib/query/querybuilder.js +++ b/lib/query/querybuilder.js @@ -1233,7 +1233,11 @@ class Builder extends EventEmitter { // Set a lock for update constraint. forUpdate(...tables) { this._single.lock = lockMode.forUpdate; - this._single.lockTables = tables; + if (tables.length === 1 && Array.isArray(tables)) { + this._single.lockTables = tables[0]; + } else { + this._single.lockTables = tables; + } return this; } diff --git a/test/unit/query/builder.js b/test/unit/query/builder.js index c46f9d4cb8..c11047df24 100644 --- a/test/unit/query/builder.js +++ b/test/unit/query/builder.js @@ -6717,6 +6717,34 @@ describe('QueryBuilder', () => { ); }); + it('lock only some tables for update (with array #4878)', () => { + testsql( + qb() + .select('*') + .from('foo') + .where('bar', '=', 'baz') + .forUpdate(['lo', 'rem']), + { + mysql: { + sql: 'select * from `foo` where `bar` = ? for update', + bindings: ['baz'], + }, + pg: { + sql: 'select * from "foo" where "bar" = ? for update of "lo", "rem"', + bindings: ['baz'], + }, + mssql: { + sql: 'select * from [foo] with (UPDLOCK) where [bar] = ?', + bindings: ['baz'], + }, + oracledb: { + sql: 'select * from "foo" where "bar" = ? for update', + bindings: ['baz'], + }, + } + ); + }); + it('lock for update with skip locked #1937', () => { testsql(qb().select('*').from('foo').first().forUpdate().skipLocked(), { mysql: { From 80f1ffca571511a39e96c59342e0d1f0212f07d3 Mon Sep 17 00:00:00 2001 From: Olivier Cavadenti Date: Tue, 7 Dec 2021 23:05:10 +0100 Subject: [PATCH 2/2] bad indice array --- lib/query/querybuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/query/querybuilder.js b/lib/query/querybuilder.js index c70f4d9274..60c224b9f8 100644 --- a/lib/query/querybuilder.js +++ b/lib/query/querybuilder.js @@ -1233,7 +1233,7 @@ class Builder extends EventEmitter { // Set a lock for update constraint. forUpdate(...tables) { this._single.lock = lockMode.forUpdate; - if (tables.length === 1 && Array.isArray(tables)) { + if (tables.length === 1 && Array.isArray(tables[0])) { this._single.lockTables = tables[0]; } else { this._single.lockTables = tables;