Add support for transactions in TODBCConnection
Original Reporter info from Mantis: lacak @lacak.sk
-
Reporter name: LacaK
Original Reporter info from Mantis: lacak @lacak.sk
- Reporter name: LacaK
Description:
ODBC API works by default in auto-commit mode (commit on every statement) , but can be switched to manual-commit mode.
function TODBCConnection.StartDBTransaction(trans: TSQLHandle; AParams:string): boolean;
var AutoCommit: SQLINTEGER;
begin
// set some connection attributes
if Params.Values['AUTOCOMMIT']='0' then
AutoCommit:=SQL_AUTOCOMMIT_OFF
else
AutoCommit:=SQL_AUTOCOMMIT_ON;
ODBCCheckResult(
SQLSetConnectAttr(FDBCHandle, SQL_ATTR_AUTOCOMMIT, SQLPOINTER(AutoCommit), SQL_IS_UINTEGER),
SQL_HANDLE_DBC,FDBCHandle,'Could not start transaction!'
);
Result:=true;
end;
function TODBCConnection.Commit(trans: TSQLHandle): boolean;
begin
ODBCCheckResult(
SQLEndTran(SQL_HANDLE_DBC, FDBCHandle, SQL_COMMIT),
SQL_HANDLE_DBC, FDBCHandle, 'Could not commit!'
);
Result:=true;
end;
function TODBCConnection.Rollback(trans: TSQLHandle): boolean;
begin
ODBCCheckResult(
SQLEndTran(SQL_HANDLE_DBC, FDBCHandle, SQL_ROLLBACK),
SQL_HANDLE_DBC, FDBCHandle, 'Could not rollback!'
);
Result:=true;
end;
procedure TODBCConnection.CommitRetaining(trans: TSQLHandle);
begin
Commit(trans);
end;
procedure TODBCConnection.RollbackRetaining(trans: TSQLHandle);
begin
Rollback(trans);
end;