Transactions
Posted: Sun 15 Jul 2007 16:48
Hi!
Normally, I'm using direct sql commands like:
DBQuery.SQL.Text:='...';
DBQuery.ExecSQL;
Now I'm experimenting with transactions, and I seem to have found a solution that works, but I'm not sure if there are any drawbacks that I don't see now, or if there is a "more elegant" version of this?
The thing I don't understand is having to call "Transaction.commit" before changing autocommit to false, since all my transactions are direct, and committed straight after calling... (as mentioned above)
Both DBConnection and DBQuery (using DBConnection) are set to Autocommit:=true!
Here is the code:
DBQuery.Transaction.Commit;
DBQuery.AutoCommit:=false;
DBQuery.Transaction.StartTransaction;
DBQuery.SQL.Text:='DELETE FROM ... ';
DBQuery.ParamByName('...').AsInteger:=...;
DBQuery.ExecSQL;
DBQuery.SQL.Text:='INSERT INTO ...';
DBQuery.ParamByName('...').AsInteger:=...;
DBQuery.ExecSQL;
DBQuery.Transaction.Commit;
DBQuery.AutoCommit:=true;
Am I using the default transaction with this code? Won't I have to create a separate transaction?
Thank you!
Normally, I'm using direct sql commands like:
DBQuery.SQL.Text:='...';
DBQuery.ExecSQL;
Now I'm experimenting with transactions, and I seem to have found a solution that works, but I'm not sure if there are any drawbacks that I don't see now, or if there is a "more elegant" version of this?
The thing I don't understand is having to call "Transaction.commit" before changing autocommit to false, since all my transactions are direct, and committed straight after calling... (as mentioned above)
Both DBConnection and DBQuery (using DBConnection) are set to Autocommit:=true!
Here is the code:
DBQuery.Transaction.Commit;
DBQuery.AutoCommit:=false;
DBQuery.Transaction.StartTransaction;
DBQuery.SQL.Text:='DELETE FROM ... ';
DBQuery.ParamByName('...').AsInteger:=...;
DBQuery.ExecSQL;
DBQuery.SQL.Text:='INSERT INTO ...';
DBQuery.ParamByName('...').AsInteger:=...;
DBQuery.ExecSQL;
DBQuery.Transaction.Commit;
DBQuery.AutoCommit:=true;
Am I using the default transaction with this code? Won't I have to create a separate transaction?
Thank you!