New to Transactions
Posted: Tue  08 Aug 2006 13:29
				
				Hi there,
I've been using MyDAC for Borland Builder 6 for a while now, but I've just started a new project which uses elements I've never used before in any form - namely transactions.
I'd like a little help to get me started please.
The following is some basic test code:
I don't understand why this code fires even if I comment the Commit line out.
The following is from the Borland help files:
I've tried emulating the first part:
but the compiler throws it out as it doesn't know what a TTransactionDesc is.  I originally thought I must be missing an include file, but can't seem to find any useful information anywhere on that.
If anyone can point me in the direction of a Borland based tutorial for DB transaction handlers I would very much appreciate it.
Many thanks in advance.
			I've been using MyDAC for Borland Builder 6 for a while now, but I've just started a new project which uses elements I've never used before in any form - namely transactions.
I'd like a little help to get me started please.
The following is some basic test code:
Code: Select all
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
    if (!MyConnection1->InTransaction)
    {
        MyConnection1->StartTransaction();
        MyQuery1->SQL->Text = "SELECT * FROM cvbs c;";
        MyQuery1->Execute();
        MyConnection1->Commit();
     }
}
The following is from the Borland help files:
Code: Select all
void __fastcall TForm1::TransferButtonClick(TObject *Sender)
{
  if (!SQLConnection1->InTransaction)
  {
    TTransactionDesc TD;
    TD.TransactionID = 1;
    TD.IsolationLevel = xilREADCOMMITTED;
    SQLConnection1->StartTransaction(TD);
    try
    {
      int Amt = StrToInt(AmtEdit->Text);
      Debit->Params->ParamValues["Amount"] = Amt;
      Credit->Params->ParamValues["Amount"] = Amt;
      SQLConnection1->Commit(TD); // on success, commit the changes;
    }
    catch (...)
    {
      SQLConnection1->Rollback(TD); // on failure, undo the changes
      ShowMessage("Transfer failed")
    }
  }
}
Code: Select all
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
    if (!MyConnection1->InTransaction)
    {
        TTransactionDesc TD;
        TD.TransactionID = 1;
        TD.IsolationLevel = xilREADCOMMITTED;
        MyConnection1->StartTransaction(TD);
        MyQuery1->SQL->Text = "SELECT * FROM cvbs c;";
        MyQuery1->Execute(); // this line required?
        MyConnection1->Commit(TD);
     }
}
If anyone can point me in the direction of a Borland based tutorial for DB transaction handlers I would very much appreciate it.
Many thanks in advance.