Skip to content

Commit 0fdfe9c

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

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
@@ -77,10 +77,6 @@ protected function _fromTables(): string
7777

7878
foreach ($this->QBFrom as $value) {
7979
if (str_starts_with($value, '(SELECT')) {
80-
if ($this->QBLockForUpdate) {
81-
throw new DatabaseException('SQLSRV does not support lockForUpdate() on subqueries.');
82-
}
83-
8480
$from[] = $value;
8581

8682
continue;
@@ -697,10 +693,20 @@ protected function compileSelect($selectOverride = false): string
697693
*/
698694
protected function compileLockForUpdate(): string
699695
{
700-
if ($this->QBLockForUpdate && $this->QBFrom === []) {
696+
if (! $this->QBLockForUpdate) {
697+
return '';
698+
}
699+
700+
if ($this->QBFrom === []) {
701701
throw new DatabaseException('SQLSRV does not support lockForUpdate() without a FROM table.');
702702
}
703703

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

‎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)