InTransaction: Boolean;
The InTransaction method returns whether the transaction with the database was initialized.
To initialize the transaction, use the IDalConnection.StartTransaction method. If the transaction is initialized and can be used at the moment, the InTransaction methods returns True. If the transaction is not available (completed earlier, closed by timeout, not initialized for some reason, and so on), the method returns False.
To apply the changes executed within the transaction, use the IDalConnection.Commit method, to rollback the changes, use the IDalConnection.Rollback method.
Sub UserProc;
Var
Driver: IDalDriver;
Connect: IDalConnection;
Command: IDalCommand;
ConnectDesc: IDalConnectionDescriptor;
ConnectDescParams: IDalConnectionDescriptorParams;
Begin
Driver := New DalOrcl8Driver.Create;
ConnectDesc := Driver.CreateDescriptor;
//Connection parameters
ConnectDescParams := ConnectDesc.Params;
ConnectDescParams.Find("User Name").Value := "User";
ConnectDescParams.Find("Password").Value := "Password";
ConnectDescParams.Find("Host BSTR").Value := "OrclServer";
ConnectDescParams.Find("Schema").Value := "Repository";
//Create a connection
Connect := ConnectDesc.CreateConnection;
Command := Connect.CreateCommand;
//Command
Command.SQL := "Insert Into Table_1 values ('AA','BB',11,22,'12.12.2002')";
//Initialize initialization
Connect.StartTransaction;
If Connect.InTransaction Then
Command.Execute;
//Finish transaction with data saving
Connect.Commit;
End If;
Command.Close;
Connect.Close;
End Sub UserProc;
On executing the example the repository connection is established with specified location parameters. After that the transaction is initialized. If no errors have been occurred, and the transaction has been initialized, the SQL query is executed that adds a new record to the Table_1 table.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.PiLibNet.Utils;
Sub UserProc();
Var
Driver: DalOrcl8Driver = ComCreator.Instance.CoCreate<DalOrcl8DriverClass>();
Connect: IDalConnection;
Command: IDalCommand;
ConnectDesc: IDalConnectionDescriptor;
ConnectDescParams: IDalConnectionDescriptorParams;
Begin
ConnectDesc := Driver.CreateDescriptor();
//Connection parameters
ConnectDescParams := ConnectDesc.Params;
ConnectDescParams.Find("User Name").Value := "User";
ConnectDescParams.Find("Password").Value := "Password";
ConnectDescParams.Find("Host BSTR").Value := "OrclServer";
ConnectDescParams.Find("Schema").Value := "Repository";
//Create a connection
Connect := ConnectDesc.CreateConnection();
Command := Connect.CreateCommand();
//Command
Command.SQL := "Insert Into Table_1 values ('AA','BB',11,22,'12.12.2002')";
//Initialize initialization
Connect.StartTransaction();
If Connect.InTransaction() Then
Command.Execute();
//Finish transaction with data saving
Connect.Commit();
End If;
Command.Close();
Connect.Close();
End Sub;
See also: