Jump to content

FireDAC Transactions in MySQL and UniGUI


Osama Ghazal

Recommended Posts

Hi All,

I have a big problem in FireDAC Transactions With UniGUI and MySQL

The Problem is that the Connection does not commit the transaction until I close the program and re-open it or until i add another voucher.

for example,

If I have two users working on the same database, every user open the program on his browser.

If (User 1) add new voucher let's say the new VoucherID will be 125, after seconds (User 2) wants also to add a new voucher, the fdquery can't find that the (User 1) added voucherID Number 125, so it will gives him that the new VoucherID also 125 not 126. This happened when I have many queries executed with one transaction.

I did't face this problem when I work on Normal Desktop Application in delphi, only when I use UniGUI Trial Version:1.90.0 build 1564 and older

The MySQL Database is on Outside Server with Mochahost and I am using Delphi 10.3

My Code is like the following:

var

VoucherID : Integer;

Begin

  qryGetVoucherID.Close;

  qryGetVoucherID.Open;

VoucherID :=   qryGetVoucherIDNewID.Value; // the query statement is: Select IfNull((Select Max(VoucherID) + 1 From vouchersheaders),1) as NewID;

  qryVouchersHeaders.Append;

  qryVouchersHeadersVoucherID.Value := VoucherID; //

.......

.....

  FDConnection.StartTransaction;

try

  qryVouchersHeaders.Post;

....

....

 qrysaveCheques_payments.execute(chRecCount,0);

 qrysaveWallets_payments.execute(chRecCount,0); 

qrysaveAccountingEntries.execute(chRecCount,0);

FDConnection.Commit;

qryVouchersHeaders.Refresh;
qryCheques_Payments.Refresh;
qryWallets_Payments.Refresh;

qryAccounting_Entries.Refresh;

except

FDConnection.rollback

end;

 

End;

Link to comment
Share on other sites

1 hour ago, asapltda said:

could you add :

  Except
    on E: Exception do begin
      ShowMessage(E.Message);
  end;

 

then Try again 

I did it already, but this code is abridgement code, and it did commit but no effect until append a new record or log out from the program.

it didn't run exception or rollback, it run commit and save the voucher

Link to comment
Share on other sites

what i see is when I make the voucher cash payment it will execute the post command and  qrysaveAccountingEntries.execute(chRecCount,0);

and it goes ok, and other user can found the voucher directly, but if the payments id cheques or e-wallets and run many execute commands on many tables this cause that the new voucher does not appeared on the other user until the first user add another voucher or logout from his program.

only the last voucher don't appeared on other users, it seems that it stored in cache, put the cache update always false not true

Link to comment
Share on other sites

How about check "InTransaction" ?

 

  if  FDConnection.InTransaction then
  begin
    ShowmessageN('Last Transaction is not finish');
    Exit;
  end;

 

  FDConnection.StartTransaction;

  try

      ...

      FDConnection.Commit;

  except

      FDConnection.Rollback;

  end;

Link to comment
Share on other sites

On 10/23/2022 at 1:31 PM, Osama Ghazal said:

Hi All,

 

Hello,

1. Your VoucherID should be  into your Global Transaction :

 

FDConnection.StartTransaction;

try

VoucherID:=

Select IfNull((Select Max(VoucherID) + 1 From vouchersheaders),1) as NewID;

....

2. It seems to me you forgot to commit

FDConnection.Commit;

except

FDConnection.rollback

end;

__________________

I am not using FireDac. Instead i use devart technology (so easy, light and robust)

That said, you can read :

http://www.unigui.com/doc/online_help/index.html?firedac.htm

Link to comment
Share on other sites

  • 2 weeks later...
On 10/24/2022 at 10:29 PM, Abaksoft said:

 

Hello,

1. Your VoucherID should be  into your Global Transaction :

 

FDConnection.StartTransaction;

try

VoucherID:=

Select IfNull((Select Max(VoucherID) + 1 From vouchersheaders),1) as NewID;

....

2. It seems to me you forgot to commit

FDConnection.Commit;

except

FDConnection.rollback

end;

__________________

I am not using FireDac. Instead i use devart technology (so easy, light and robust)

That said, you can read :

http://www.unigui.com/doc/online_help/index.html?firedac.htm

Thank you for your answer.

but Only Now I Found the problem.

the problem is that When I Open a Cheques Form by Mistake I forget to delete StartTransaction from Onshow.

so there is two starttransaction, one when save the voucher and other when show the cheques form.

thank you again

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...