Uniloader With Transactions?
Posted: Tue 24 Sep 2013 12:59
I have read several places that uniloader can be used just like
any other "set of insertions", inside a transaction.
But I have not yet been able to get the expected ROLLBACK behavior.
Maybe there is a special step I am missing. Below is a simple example.
I expect the table to be empty but the data has been transferred despite the ROLLBACK.
procedure Teditfloat.Button10Click(Sender: TObject);
var
q1: txquery;
uniloader: tuniloader;
begin
uniloader:= tuniloader.create(nil);
q1:=txquery.create(nil);
try
q1.sqlconnection:=mconnection;
uniloader.connection:=mconnection;
uniloader.TableName:='dd_master';
//
q1.sql.add('delete from dd_master'); //CLEARS DD_MASTER
q1.execsql;
q1.sql.clear;
q1.sql.add('select * from md_master'); //GRABS DATA RECORDS
MCONNECTION.STARTTRANSACTION;
uniloader.loadfromdataset(q1); //FILLS DD_MASTER
IF MCONNECTION.INTRANSACTION THEN
MCONNECTION.ROLLBACK; //SHOULD RETURN DD_MASTER BACK TO ORIGINAL STATE - EMPTY
finally
q1.free;
uniloader.free;
end;
end;
any other "set of insertions", inside a transaction.
But I have not yet been able to get the expected ROLLBACK behavior.
Maybe there is a special step I am missing. Below is a simple example.
I expect the table to be empty but the data has been transferred despite the ROLLBACK.
procedure Teditfloat.Button10Click(Sender: TObject);
var
q1: txquery;
uniloader: tuniloader;
begin
uniloader:= tuniloader.create(nil);
q1:=txquery.create(nil);
try
q1.sqlconnection:=mconnection;
uniloader.connection:=mconnection;
uniloader.TableName:='dd_master';
//
q1.sql.add('delete from dd_master'); //CLEARS DD_MASTER
q1.execsql;
q1.sql.clear;
q1.sql.add('select * from md_master'); //GRABS DATA RECORDS
MCONNECTION.STARTTRANSACTION;
uniloader.loadfromdataset(q1); //FILLS DD_MASTER
IF MCONNECTION.INTRANSACTION THEN
MCONNECTION.ROLLBACK; //SHOULD RETURN DD_MASTER BACK TO ORIGINAL STATE - EMPTY
finally
q1.free;
uniloader.free;
end;
end;