Subject RE: [firebird-support] get_lock / release_lock
Author Helen Borrie
At 04:49 PM 31/07/2008, you wrote:
>This in the link to the my Sql online manual:
>http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function
>_get-lock
>
>It is like a flag that can be seen by any user.

Forget it, Doru. Firebird is a transactional database engine with optimistic locking by default. That means that you have locking done for you automatically: as soon as one transaction posts its intention to alter or delete a record, all other transactions trying to alter or delete that record will be refused.

ISAM databases don't have optimistic locking. In Firebird, the "equivalent" to testing for an ISAM lock would be to attempt the operation and intercept the lock conflict exception. A number of client data access layers, including IBObjects for Delphi, implement a "pessimistic locking" feature for use in the rare circumstances when it is actually needed. It is achieved by performing a "dummy update" on the record just before the record is put into what Delphi calls "Edit mode" - thus ensuring that other transactions cannot obtain a lock on this record until the lock-holder transaction has either committed or rolled back.

Pessimistic locking is unnatural to Firebird. However, for situations where it really is needed (RARE!) a form of pessimistic locking is implemented in the SELECT syntax (the FOR UPDATE [WITH LOCK] clause mentioned by Alexandre) but it's to be avoided unless you are very well acquainted with how Firebird's locking works and you are sure it is what you need.

./heLen