Recent

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

Knipfty

  • Full Member
  • ***
  • Posts: 232
[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 »
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

teos

  • Full Member
  • ***
  • Posts: 157
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: 232
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
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Knipfty

  • Full Member
  • ***
  • Posts: 232
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
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

JD

  • Hero Member
  • *****
  • Posts: 1848
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 - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Knipfty

  • Full Member
  • ***
  • Posts: 232
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
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

JD

  • Hero Member
  • *****
  • Posts: 1848
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 - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Knipfty

  • Full Member
  • ***
  • Posts: 232
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.
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

 

TinyPortal © 2005-2018