我尝试使用连接到MySQL 5.6.13的Delphi XE3中的dbExpress来执行嵌套事务。
以下是我执行嵌套事务的示例代码:
...
dbxTransaction := _connection.BeginTransaction(TDBXIsolations.ReadCommitted);
// just to check if nested is suported
supportsNestedBol := dbxTransaction.Connection.DatabaseMetaData.SupportsNestedTransactions;
try
_sqlQuery.Close;
_sqlQuery.SQL.Clear;
_sqlQuery.SQL.Add('INSERT INTO test(cod, name) VALUES(:cod, :name)');
_sqlQuery.ParamByName('cod').AsInteger := Test.Cod;
_sqlQuery.ParamByName('name').AsAnsiString := Test.Name;
_sqlQuery.ExecSQL(False);
//calls a nested function that has another transaction
Employee.Save();
_connection.CommitFreeAndNil(dbxTransaction);
Result := True;
except
on Exc:Exception do
begin
_connection.RollBackFreeAndNil(dbxTransaction);
raise Exc;
Result := False;
end;
end;
...
function Employee.Save():Boolean;
begin
...
dbxTransaction02 := _connection.BeginTransaction(TDBXIsolations.ReadCommitted);
try
_sqlQuery.Close;
_sqlQuery.SQL.Clear;
_sqlQuery.SQL.Add('INSERT INTO employee(cod, name) VALUES(:cod, :name)');
_sqlQuery.ParamByName('cod').AsInteger := Employee.Cod;
_sqlQuery.ParamByName('name').AsAnsiString := Employee.Name;
_sqlQuery.ExecSQL(False);
_connection.CommitFreeAndNil(dbxTransaction02);
Result := True;
except
on Exc:Exception do
begin
_connection.RollBackFreeAndNil(dbxTransaction02);
raise Exc;
Result := False;
end;
end;
end;
...
如果我设置了断点并检查变量supportsNestedBol
,则值为False
。
所以,我不确定是否是连接器" libmysql.dll"我使用的不支持嵌套交易,或者我是否尝试这样做。
一些帮助?