Recent

Author Topic: what's the Transaction for ?  (Read 2869 times)

mirce.vladimirov

  • Sr. Member
  • ****
  • Posts: 259
what's the Transaction for ?
« on: May 10, 2012, 03:36:19 pm »
I've been reading http://wiki.freepascal.org/Working_With_TSQLQuery  and there is a short example of how to insert rows in a database, which is exactly the same that i am doing, and my applications work fine, but there is one more line of code in the example that confuses me:
Code: [Select]
sql_temp.sql.text := 'insert into PRODUCTS (ITEMNR,DESCRIPTION) values (:OURITEMNR,:OURDESCRIPTION)'
 ...
 sql_temp.Params.ParamByName('OURITEMNR').AsString := 'XXXX';
 sql_temp.Params.ParamByName('OURDESCRIPTION').AsString := 'description';
 sql_temp.ExecSQL;
 SQLTransaction1.Commit; //or possibly CommitRetaining, depending on how your application is set up
and that's the line that contains the "SQLTransaction1.commit"
What is this for ?
I repeat, my applications are working with "query.ExecSQL;"

Leledumbo

  • Hero Member
  • *****
  • Posts: 8798
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: what's the Transaction for ?
« Reply #1 on: May 10, 2012, 04:20:56 pm »
I forgot what the real term is, but it's some kind of exception handler and checkpoint (AFAIK not all DMBS supports). First you "Start" the transaction, and if everything goes fine, you "Commit" the transaction, marking it as OK (and also marking it as a checkpoint). Otherwise, you could "Rollback" the transaction, restoring values you've changed before the rollback to the last checkpoint.

 

TinyPortal © 2005-2018