Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Syntax:<br />
This is for experts only!<br />
DML statements<br />
The need for a pessimistic lock in <strong>Firebird</strong> is very rare indeed and should be well understood before use of<br />
this extension is considered.<br />
It is essential to understand the effects of transaction isolation and other transaction attributes before attempting<br />
to implement explicit locking in your application.<br />
SELECT ... FROM single_table<br />
[WHERE ...]<br />
[FOR UPDATE [OF ...]]<br />
WITH LOCK<br />
If the WITH LOCK clause succeeds, it will secure a lock on the selected rows and prevent any other transaction<br />
from obtaining write access to any of those rows, or their dependants, until your transaction ends.<br />
If the FOR UPDATE clause is included, the lock will be applied to each row, one by one, as it is fetched into<br />
the server-side row cache. It becomes possible, then, that a lock which appeared to succeed when requested<br />
will nevertheless fail subsequently, when an attempt is made to fetch a row which becomes locked by another<br />
transaction.<br />
WITH LOCK can only be used with a top-level, single-table SELECT statement. It is not available:<br />
• in a subquery specification;<br />
• for joined sets;<br />
• with the DISTINCT operator, a GROUP BY clause or any other aggregating operation;<br />
• with a view;<br />
• with the output of a selectable stored procedure;<br />
• with an external table.<br />
A lengthier, more in-depth discussion of “SELECT ... WITH LOCK” is included in the Notes. It is a must-read<br />
for everybody who considers using this feature.<br />
Available in: DSQL, ESQL, PSQL<br />
UPDATE<br />
Description: Changes values in a table (or in one or more tables underlying a view). The columns affected are<br />
specified in the SET clause; the rows affected may be limited by the WHERE and ROWS clauses.<br />
Syntax:<br />
UPDATE [TRANSACTION name] {tablename | viewname} [[AS] alias]<br />
SET col = newval [, col = newval ...]<br />
[WHERE {search-conditions | CURRENT OF cursorname}]<br />
[PLAN plan_items]<br />
[ORDER BY sort_items]<br />
[ROWS [TO ]]<br />
[RETURNING values [INTO ]]<br />
, ::= Any expression evaluating to an integer.<br />
::= :varname [, :varname ...]<br />
84