Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread startTransaction for multiple appends to same table
Thu, Apr 6 2006 4:11 AMPermanent Link

Dhaval Shah
Hi peers & Tim,
I'm appending multiple records from a memory table to another table
due to the validations, some records don't validate and the loop stands
still.
I'm wondering if StartTransaction..commit..rollback would help me with that.
But again, will it "rollback" the "posted" record(s) too??
for ex.
With memoryTable do
While not eof do
  begin
    Table2.append;
    Table2.FieldbyName....
    Table2.Post; <--
    Next;
  end;

If i put this in the database transaction try..except it'd be
if not Database.Intransaction then
Database.StartTransaction;
try
With memoryTable do
While not eof do
  begin
    Table2.append;
    Table2.FieldbyName....
    Table2.Post; <--
    Next;
  end;
Database.Commit;
except
Database.Rollback;
end;

Will that revert the previous posted records IF any of the records
throws an exception??
for ex.
record 1 - OK (appended and posted)
record 2 - OK (appended and posted)
record 3 - value(s) didn't validate and so threw an exception

Regards

---
Dhaval Shah
Sr. Software Developer
Perth, Australia
Thu, Apr 6 2006 4:40 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Dhaval,

<< Will that revert the previous posted records IF any of the records throws
an exception?? >>

Yep, as long as you throw a valid Exception or descendant that triggers the
except block and executes the rollback.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, May 1 2006 2:52 AMPermanent Link

Dhaval Shah
Tim Young [Elevate Software] wrote:
> Dhaval,
>
> << Will that revert the previous posted records IF any of the records throws
> an exception?? >>
>
> Yep, as long as you throw a valid Exception or descendant that triggers the
> except block and executes the rollback.
>

cool. Smile
thanks Tim (sorry for the late response)

---
Dhaval Shah
Sr. Software Developer
Perth, Australia
Image