[Tutor] Record Locking & Access - newbye
Lloyd Kvam
pythonTutor at venix.com
Thu Jun 24 10:51:10 EDT 2004
You can often handle this with a timestamp on the record. The database
should support a timestamp type that will NOT BE DUPLICATED on single
record updates within a table. The basic update algorithm is:
lock record (or table or block depending on DBMS)
read record
if record timestamp == user timestamp
do update
refresh user copy
unlock
else
unlock
notify user that record was modified by someone else
if the timestamp changed, be careful about automatically refreshing the
user's copy of the record and discarding the user's changes to the
original record.
We've been successful using this approach with MySQL.
On Sun, 2004-06-20 at 14:55, Miguel Lopes wrote:
> Hi,
>
> Here's my problem.
> Using python dbapi I get groups of records back from a database into a list
> for example to feed a "List Form" which is just a grid on a form (the db is
> about 9000 thousand records - so I suppose there's not a big problem to
> fetch all records in a go!).
>
> Now when a user selects a record from a grid on screen I can send him to
> another form "Record Form" where he can edit the record. This way I can have
> only one query to the database and have the users working locally on there
> record sets. But when a user edits an existing record I puzzled to think
> that another user might be changing that record at the same time (because
> they are not locking any records and are using lists with the record
> contents locally)! This could cause for example that user A changes record 1
> from "bar" to "foo" and updates the db, just after user A user B updates the
> db with a change in the same record from "bar" to "foobar" (never seeing
> user As changes)!!!
>
> I guess this is a very common problem with a standard solution. How can I
> avoid this?
>
> Best regards,
> Mekl
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 801-459-9582
More information about the Tutor
mailing list