1

I am using Delphi 2010 with FIB Components like TpFIBDataset, TpFIBTransaction and TpFIBDataset with Firebird database.

I have already set TpFIBDataset's 'AutoCommit' property to 'False', then also when I execute below statement in the try..finally block and rollback the transaction data still get posted.

Code:

FIBDataset.Post;

Below is the sample code.

Code:

try
  FIBDatabase.StartTransaction;

       ....

          Block of Code;

       ...
    finally
      if saveALL then
        FIBDatabase.CommitRetaining
      else
        FIBDatabase.RollbackRetaining;
    end;
Roger Oliveira
  • 1,589
  • 1
  • 27
  • 55
Vishal Tiwari
  • 739
  • 2
  • 12
  • 28
  • 1
    why do you do "...retaining" ? why do you not close the transaction ? – Arioch 'The Jun 11 '15 at 12:47
  • 2
    also I think "StartTransaction" should go before TRY, in case there would be an exception *within* that call but before the real transaction in Firebird starts – Arioch 'The Jun 11 '15 at 12:48
  • 1
    ForceCloseTransactions doesn't display data in the grid then. If .Close is called the I get an error list index out of bound. – Vishal Tiwari Jun 11 '15 at 13:11
  • 1
    I do not talk about closing the dataset, which you do be calling TDataset.Close, I talk about closing the transaction! just call .Commit or .Rollback without "Retaining" suffix. – Arioch 'The Jun 11 '15 at 13:51
  • 1
    Hi, Please start with FIBPlus developer Guide, there is a good step by step explanation: http://www.devrace.com/en/fibplus/articles/4240.php – Alexey Kovyazin Jun 11 '15 at 20:00
  • 1
    @Alexey: I have already gone through that doc, but there is no sufficient info. I t is always pointing to Interbase API guid.pdf, I looked into it, but didn't get something related o this issue. – Vishal Tiwari Jun 12 '15 at 06:25
  • 1
    Well, it is hard to imagine what could the problem here... May be actual code is not trivial? – Alexey Kovyazin Jun 12 '15 at 15:37
  • @VishalTiwari Are you closing all the datasets before rollback as in my answer ? – Rohit Gupta Jun 17 '15 at 11:56
  • @VishalTiwari I don't use FIB but I have used other components with interbase and firebird. So I am extrapolating. I have just read the FIB guide and the APIGuide. What is Params set to ? If it is write then it should be fine. Otherwise you need to duplicate the issue with simpler code. The API Guide has everything to do with your issue in it. Chapter 5 explains it all. If you are going to do complicated transactions then you need to understand it. – Rohit Gupta Jun 17 '15 at 11:58

1 Answers1

0

The Transaction on the dataset must also be checked and changed

FIBDataset.AutoCommit := false;

You need to Close the query as well. In this case

FIBDataset.Close;
FIBDatabase.Rollback;

EDIT

I would also advise you to allocate the one transaction component to all the datasets (rather than the database). And use the start, commit, rollback methods of the transaction component. Further, you must assign the transaction component before you do any operations.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • I have already set AutoCommit to False, still it doesn't work. AutoCommit has to be False then only we could use transaction else it is automatically commit. – Vishal Tiwari Jun 17 '15 at 06:09
  • What about the Autocommit on the Database component ? What isolation have you used etc ? I think you need to post more of your code. – Rohit Gupta Jun 17 '15 at 06:46
  • There is no Autocommit property for TpFIBDatabase component not for TpFIBTransaction component, it's only for TpFIBDataSet component. There is huge code calculation happening instarting and rolling back transaction. In one transaction component's 'TRParams' property, i found below values: write, isc_tpb_nowait, read_committed, rec_version. For other transaction component there no values present. – Vishal Tiwari Jun 17 '15 at 09:33
  • First, are you doing the close of all datasets before rollback (or commit) ? – Rohit Gupta Jun 17 '15 at 11:48
  • That doesn't matter, once you say Dataset.Post then you could go for Commit/Rollback. I have tried closing dataset as well. – Vishal Tiwari Jun 18 '15 at 05:30
  • It DOES matter. If you do not close the dataset and rollback and then destroy the dataset, it can commit the operations. Which is precisely what you are seeing. But maybe, you are the expert :-) – Rohit Gupta Jun 18 '15 at 06:46
  • I am not the expert but i tried this in a sample project, i do not destroy the dataset and it is working fine with me. Might be the FIB components are expert. – Vishal Tiwari Jun 18 '15 at 07:13
  • @ Rohit Gupta: You Rocks Tiger !!!! You gave me the right answer in your edited part..... I was fighting with this issue from last one week... Yessss You Rock TIGER... You Said, "I would also advise you to allocate the one transaction component to all the datasets (rather than the database). And use the start, commit, rollback methods of the transaction component. Further, you must assign the transaction component before you do any operations." AND IT WORKED. – Vishal Tiwari Jun 18 '15 at 12:35
  • @VishalTiwari, would have got there faster if I had had more of your code to peruse. :-) – Rohit Gupta Jun 19 '15 at 05:10
  • @ Rohit Gupta: Ending is sweet, everything is sweet. but I was also trying to see what exactly is happening. Thank You so much Rohit, You just ROCKS TIGER. :) – Vishal Tiwari Jun 19 '15 at 05:54