Subject Re: [IBO] Transaction question
Author Harald Klomann
Riho-Rene Ellermaa wrote:
>
>
> 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();
>

Hi Riho,

in your loop:

Query->RefreshKeys()
--------------------
this only checks if records are inserted/deleted,
to syncronize the keybuffers. Data buffers are not refreshed here !
This is fact when Query->FetchWholeRows=False.
If FetchWholeRows=True, just a Query->Refresh() is done.

Query->First
------------
ok, but you could also set Query->RefreshAction to RaOpen. (Does the same)

> ....processing
----------------
Here is your big problem !
The other client could have processed this row after you started
your transaction, so you donĀ“t know anything about here.
Before processing of each row, you have to re-fetch this individual row
from the server again.

I would do like this :

* set the transaction to LockWait
(so you dont get troubles, if diff. clients want to process the row at same time)

* set Query->BufferSyncronFlags to bsBeforeEdit
(causes the row to be refreshed before editing, so you see changes made by other clients)


* Loop

Query->RefreshKeys();
Query->First();

Query->Edit(); // now you can be shure, your Data is reflecting changes !!

If (Query("Status")->AsInterger==1) {
...processing
Query("Status")->AsInterger=2;
Query->Post();
}
else
Query->Cancel();



Hope this helps

Harald