Purpose
Locks the current record to prevent updates by other users.
The Lock method provides a way for applications to control concurrency on connections that do not support transactions. Generally, data sources that support concurrency levels and transactions will not support the Lock method.
To simulate a transaction, an application uses the Lock method to lock each of the rows in the transaction. It then uses the Update or Delete methods to update or delete each row. When all operations in the transaction have completed, the application uses the Unlock method to unlock each row.
A row locked with the Lock method remains locked until the application calls the Unlock method or until the statement is closed.
Syntax
DBStatement.Lock
Compliance:
Some level 2 drivers
Example
The following example locks the current record, updates it and then unlocks it so that it is available for other users to modify.
Sub Main()
Dim cnct As DBConnection
Dim stmt As DBStatement
cnct.OpenConnection("MyDSN") 'Open the data source "MyDSN"
stmt.OpenStatement(cnct, dbKeyset, dbRowver)
stmt.ExecuteSQL("SELECT * FROM My Table WHERE CustNum = 12345")
stmt.Lock
stmt.Column("CustName") = "Harold"
stmt.Column("CustAddr") = "99 Main Street"
stmt.Column("CustLastContact") = Today
stmt.Update 'Write new data to database
stmt.Unlock
stmt.CloseStatement
cnct.CloseConnection 'Close the connection
End Sub
|