Subject Re: [IBO] Transaction question
Author Jason Wharton
> My program processes data according to each records status. I take data
with
> status=1, do some stuff with it and set status=2. The transaction that is
> tied to my Query has AutoCommit=true and Isolation=tiCommited. The
> processing time for one record is less than 1 sec.
>
> Query->SQL("SELECT ... from mytable where Status=1")
>
> The method that is called in loop looks like:
> Query->RefreshKeys();
> Query->First();
> ....processing
> Query->Edit();
> Query("Status")->AsInterger=2;
> Query->Post();
>
> I had trouble with two users processing simultaniously. The data was
> processed twice. I don't think that they succeeded to press button exatcly
> the same second, probably I'm not using transactions correctly, so the one
> users changes are not seen to another user.

You have a couple of options. First of all I would like to make your code a
little more efficient:

> The method that is called in loop looks like:
{
Query->RefreshKeys();
Query->First();
}
Instead of above do this:
Query->Close();
Query->Open();
Query->First();

> ....processing

> Query->Edit();
> Query("Status")->AsInterger=2;
> Query->Post();

Or, simply set the BufferSynchroFlags property to include the bsfBeforeEdit
and don't even bother to close & open, just go to the first record and edit
it.

Is this like a queue where records are cycling through and as soon as a user
starts working on a record you want another user to get the next record? You
may want to use a customized LockSQL to change the record to indicate that
it is being edited and set PessimisticLocking to true so that it won't go
into edit state unless it really gets exclusive access to that record. The
change to it could also make it so that the next user gets the next record.
I think you will want to put in a AfterCancel event to reset the record so
it goes back into the queue. (If that is what you are doing.)

There is still more to it than this. What it seems you are tying to do isn't
especially easy in a multi-user environment.

HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com


----- Original Message -----
From: "Riho-Rene Ellermaa" <r.ellermaa@...>
To: "IBObject (E-mail)" <IBObjects@yahoogroups.com>
Sent: Friday, March 23, 2001 3:15 AM
Subject: [IBO] Transaction question


> Hi!
>
>
>
> Riho-Rene Ellermaa
> senior programmer
> Hansabank
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>