Skip to content

Commit 3f76f4e

Browse files
committed
docs(database): refine lockForUpdate driver warnings
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 2cce641 commit 3f76f4e

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

system/Database/SQLSRV/Builder.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ protected function _fromTables(): string
7979

8080
foreach ($this->QBFrom as $value) {
8181
if (str_starts_with($value, '(SELECT')) {
82-
if ($this->QBLockForUpdate) {
83-
throw new DatabaseException('SQLSRV does not support lockForUpdate() on subqueries.');
84-
}
85-
8682
$from[] = $value;
8783

8884
continue;
@@ -699,10 +695,20 @@ protected function compileSelect($selectOverride = false): string
699695
*/
700696
protected function compileLockForUpdate(): string
701697
{
702-
if ($this->QBLockForUpdate && $this->QBFrom === []) {
698+
if (! $this->QBLockForUpdate) {
699+
return '';
700+
}
701+
702+
if ($this->QBFrom === []) {
703703
throw new DatabaseException('SQLSRV does not support lockForUpdate() without a FROM table.');
704704
}
705705

706+
foreach ($this->QBFrom as $value) {
707+
if (str_starts_with($value, '(SELECT')) {
708+
throw new DatabaseException('SQLSRV does not support lockForUpdate() on subqueries.');
709+
}
710+
}
711+
706712
return '';
707713
}
708714

user_guide_src/source/database/query_builder.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,13 @@ This method is supported by the **MySQLi**, **Postgre**, **OCI8**, and
780780
**SQLSRV** drivers. Unsupported drivers throw a ``DatabaseException``. See the
781781
following notes for OCI8 and SQLSRV driver-specific behavior.
782782

783-
.. note:: SQLSRV uses SQL Server table hints instead of a trailing ``FOR UPDATE``
783+
.. warning:: SQLSRV uses SQL Server table hints instead of a trailing ``FOR UPDATE``
784784
clause. The hint is applied to table references in the ``FROM`` clause;
785785
joined tables are not hinted. Its exact lock granularity depends on SQL
786786
Server's execution plan and transaction isolation level. SQLSRV does not
787787
support ``lockForUpdate()`` without a ``FROM`` table or on subqueries.
788788

789-
.. note:: OCI8 does not support ``lockForUpdate()`` together with ``limit()`` or
789+
.. warning:: OCI8 does not support ``lockForUpdate()`` together with ``limit()`` or
790790
``offset()`` because Oracle does not allow ``FOR UPDATE`` with row
791791
limiting.
792792

0 commit comments

Comments
 (0)