Lazarus

Programming => Databases => Topic started by: Knipfty on August 07, 2012, 04:43:49 pm

Title: [SOLVED]Transaction Control with TTable objects
Post by: Knipfty on August 07, 2012, 04:43:49 pm
Hi,

While programming last night I came across the following scenario:

Code: [Select]
Table1.Insert;
{FiledByName assignments}
Table1.Post;

Table2.Insert;
{FiledByName assignments}
Table2.Post;

Table2.Insert;  //Table two gets 2 records inserted (not a typo)
{FiledByName assignments}
Table2.Post;

That is basically what my code looks like.  Now if I were doing this in a stored procedure, I would have added "Begin Transaction" at the start and "Committ" at the end of the code.  But I am doing this in Lazarus. 

How can I accomplish this in Pascal/Lararus?
Title: Re: Transaction Control with TTable objects
Post by: teos on August 20, 2012, 11:39:20 pm
Transaction is in the Connection or Database component, if implemented.

I know for example that ZConnection1.StartTransaction and ZConnection.Commit, ZConnection.Rollback will do what you ask.

Normally this is not at the TDataset level.
Title: Re: Transaction Control with TTable objects
Post by: Knipfty on August 21, 2012, 01:51:21 pm
Thanks teo,

I will take a look at the connection object.  I didn't think to look there.  Hopefully Advantage implemented them.

Knipfty
Title: Re: Transaction Control with TTable objects
Post by: Knipfty on August 21, 2012, 07:11:42 pm
Hi teo,

Code: [Select]
  AdsConnection1.BeginTransaction;
  AdsConnection1.Commit;
  AdsConnection1.Rollback;
  AdsConnection1.CreateSavepoint();

I found the above on the connection object.  A Big Thanks!

I was looking on the TTable and TQuery objects and getting frustrated.  It just never dawned on me to look at the connection object. :-[

I was seriously looking at creating my type of transaction control.  You probably saved me days of work.

Knipfty
Title: Re: [SOLVED]Transaction Control with TTable objects
Post by: JD on August 21, 2012, 07:51:00 pm
@Knipfty
I'm interested in knowing what components you are using to connect to the Advantage DB server.  ;)
Title: Re: [SOLVED]Transaction Control with TTable objects
Post by: Knipfty on August 21, 2012, 07:59:17 pm
I downloaded them from Advantage and installed them as a package into the IDE.  See http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=18&Product=10&Platform=11 (http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=18&Product=10&Platform=11)  (I believe this is where I downloaded them from)

Anyway, I use Advantage locally and for free.  What I really like is the DB Manager that comes with Advantage.  It allows to to easily create and modify tables as I am developing.  It will also output the SQL schema generation code that I plan to use when deploying the application.

Does that answer your question?

Knipfty
Title: Re: [SOLVED]Transaction Control with TTable objects
Post by: JD on August 21, 2012, 10:18:45 pm
I downloaded them from Advantage and installed them as a package into the IDE.  See http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=18&Product=10&Platform=11 (http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=18&Product=10&Platform=11)  (I believe this is where I downloaded them from)

Anyway, I use Advantage locally and for free.  What I really like is the DB Manager that comes with Advantage.  It allows to to easily create and modify tables as I am developing.  It will also output the SQL schema generation code that I plan to use when deploying the application.

Does that answer your question?

Knipfty

Yes it does. I see that the Advantage Delphi Components v11 download also includes Lazarus/FPC components.

Thanks.

Title: Re: [SOLVED]Transaction Control with TTable objects
Post by: Knipfty on August 22, 2012, 01:56:04 am
I just realized I gave you a link to the latest version, v11.  I am using 10.1.  It looks like they made some nice enhancements.  I'm going to have to upgrade and try it out at some point.
TinyPortal © 2005-2018