What's the best way to detect changed records by other users

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
devweb
Posts: 16
Joined: Sat 02 Feb 2008 08:10

What's the best way to detect changed records by other users

Post by devweb » Wed 04 Mar 2009 15:23

Hello,

I'm looking for use UniDac with new application that will work in different databases mainly, Sql server & Mysql but more will be add later.

I'm looking for best way how to detect the changed record from other users, for example if Both A & B open the same records and modify it, then B commit it's modification to the server, what happen if A try to commit his modification now?, is there any thing in UniDac to handle it? and what's the best way to do that?

one of solution I'm thinking about to use timestamps and then compare between the values before commit, but not sure if there are any better ways that will work smoothly with different databases.

Thanks

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 05 Mar 2009 08:56

TUniQuery and TUniTable have the LockMode property. You can set this property to lmOptimistic or lmPessimistic to prevent several users from editing the same record.

If LockMode = lmPessimistic, UniDAC locks the record when editing begins. Other users cannot modify the record while the first user is editing it. The record is unlocked after the Post or Cancel method of dataset is called.

If LockMode = lmOptimistic, UniDAC locks the record when Post is called. At this time UniDAC also gets the current values for this record from database. If the record was changed by another user, an exception is raised. So several users can edit the record at the same time but only one user can post the changes. Other users will get an exception.

Post Reply