Re: HELP!!! Pessimistic locking using ODBC
Posted in 1997
In article <342AA49D.35AE@systeam.co.uk>, fa87@systeam.co.uk says... >How can I lock a row in a table? > >The Borland documentation suggests only optimistic locking can be done on SQL database >connections- but my users are likely to find this unacceptable. Is there a solution? You should be able to do this by calling the ODBC driver directly. You need to be within a transaction; I don't know how Delphi starts/commits a transaction, or whether it assumes you're always in one. If Delphi doesn't provide a way of controlling this, you should be able to set it by calling SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF). There is an ODBC call you can make (SQLSetConnectOption) that should then let you control more precisely how rows you read from the database are locked. If I read your wishes correctly, you probably want SQLSetConnectOption(hdbc, SQL_TXN_ISOLATION, SQL_TXN_REPEATABLE_READ). hdbc is the ODBC connection handle; I don't know how you gain access to it in Delphi. The other symbolic constants are from Microsoft's ODBC SDK, and should be somewhere in Delphi's include files. -- William Harris william@carsinfo.com Check out the NAGS spam filter. http://www.nags.org