diff --git a/select-builder-pgsql.js b/select-builder-pgsql.js index 584c2e2..7108efd 100644 --- a/select-builder-pgsql.js +++ b/select-builder-pgsql.js @@ -1,6 +1,6 @@ // Простенький "селект билдер" по мотивам MediaWiki-овского, успешно юзаю подобный в PHP уже лет 8 // (c) Виталий Филиппов, 2019-2021 -// Версия 2021-09-14 +// Версия 2021-09-16 // В PHP, правда, прикольнее - там в массиве можно смешивать строковые и численные ключи, // благодаря чему можно писать $where = [ 't1.a=t2.a', 't2.b' => [ 1, 2, 3 ] ] @@ -288,7 +288,7 @@ function where_or_set(fields, for_where) } else { - if (k.indexOf('?') >= 0) + if (k.indexOf('?') >= 0 || v.length == 0) { // { expr: [ bind ] } // FIXME: check bind variable count @@ -722,7 +722,6 @@ class Connection extends ConnectionBase // Если уже кто-то активен - ждём его await new Promise((resolve, reject) => this.transaction_queue.push(resolve)); } - this.in_transaction = true; const r = await this._query(sql, bind); // Если есть ещё кто-то в очереди - пусть проходит this._next_txn(); @@ -754,6 +753,7 @@ class Connection extends ConnectionBase async _query(sql, bind) { + const do_lock = !this.in_transaction; if (!this.dbh) await this.connect(); if (this.in_transaction && this.connection_lost) @@ -770,6 +770,8 @@ class Connection extends ConnectionBase { start_time = Date.now(); } + if (do_lock) + this._in_transaction = true; const r = await this.dbh.query(sql); if (this.config.log_queries) {