Recent

Author Topic: [SOLVED]Transaction Control with TTable objects  (Read 5033 times)

Knipfty

  • Full Member
  • ***
  • Posts: 230
[SOLVED]Transaction Control with TTable objects
« 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?
« Last Edit: August 21, 2012, 07:12:02 pm by Knipfty »
32-bit Lazarus 1.0 FPC 2.6.0, 64-bit Win 7, Advantage DB 10.10

teos

  • Full Member
  • ***
  • Posts: 145
Re: Transaction Control with TTable objects
« Reply #1 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.

Knipfty

  • Full Member
  • ***
  • Posts: 230
Re: Transaction Control with TTable objects
« Reply #2 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
32-bit Lazarus 1.0 FPC 2.6.0, 64-bit Win 7, Advantage DB 10.10

Knipfty

  • Full Member
  • ***
  • Posts: 230
Re: Transaction Control with TTable objects
« Reply #3 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
32-bit Lazarus 1.0 FPC 2.6.0, 64-bit Win 7, Advantage DB 10.10

JD

  • Hero Member
  • *****
  • Posts: 1758
Re: [SOLVED]Transaction Control with TTable objects
« Reply #4 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.  ;)
Windows (10, 7) - Lazarus 2.0RC3/FPC 3.2, NewPascal, Delphi

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

Knipfty

  • Full Member
  • ***
  • Posts: 230
Re: [SOLVED]Transaction Control with TTable objects
« Reply #5 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  (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
32-bit Lazarus 1.0 FPC 2.6.0, 64-bit Win 7, Advantage DB 10.10

JD

  • Hero Member
  • *****
  • Posts: 1758
Re: [SOLVED]Transaction Control with TTable objects
« Reply #6 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  (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.

Windows (10, 7) - Lazarus 2.0RC3/FPC 3.2, NewPascal, Delphi

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

Knipfty

  • Full Member
  • ***
  • Posts: 230
Re: [SOLVED]Transaction Control with TTable objects
« Reply #7 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.
32-bit Lazarus 1.0 FPC 2.6.0, 64-bit Win 7, Advantage DB 10.10