StartTransaction(AutoCommit: Boolean): IConnectionTransaction;
AutoCommit. Parameter that is responsible for automatic saving of changed data on DB server.
The StartTransaction method initiates a new transaction with DB.
If the AutoCommit parameter is set to True, and there is no visible call of the Commit or the Rollback methods, when terminating the transaction the Commit method is called automatically to save all changed data. If the AutoCommit parameter is set to False, in case of similar conditions the Rollback method is called to roll back all changes.
The transaction is terminated when the Dispose statement is explicitly used for the corresponding object in the code. Incomplete transactions are also terminated by a garbage collector when completing code execution.
Sub Main;
Var
MB: IMetabase;
DB: IDatabaseInstance;
Connect: ISecurityConnection;
Command: IDalCommand;
Tran: IConnectionTransaction;
Begin
MB := MetabaseClass.Active;
DB := MB.ItemById("BD").Open(Null) As IDatabaseInstance;
Connect := DB.Connection;
Command := Connect.CreateCommand("Insert Into Table_1 values ('A',1)");
Tran := Connect.StartTransaction(False);
Try
Command.Execute;
Tran.Commit;
Except
Tran.Rollback;
End Try;
Command.Close;
End Sub Main;
After executing the example, connection to the DB server, on which the BD repository database is set, established. The SQL query that inserts a new record in the table with the Table_1 physical name is created and executed for this connection. If there is any unsaved data, it is saved on the server.
See also: