@Michl:
In MSEgui sieht es ähnlich aus:
Code: Alles auswählen
procedure TSQLTransaction.StartTransaction;
var
db: tcustomsqlconnection;
int1: integer;
begin
if Active then begin
DatabaseError(SErrTransAlreadyActive);
end;
db:= tcustomsqlconnection(database);
if Db = nil then begin
DatabaseError(SErrDatabasenAssigned);
end;
inc(fstartcount);
int1:= fstartcount;
if checkcanevent(self,tmethod(fonbeforestart)) then begin
fonbeforestart(self);
end;
if not Db.Connected then begin
Db.Open;
end;
if (int1 <> fstartcount) or not db.connected then begin
exit;
end;
if not assigned(FTrans) then begin
FTrans:= Db.AllocateTransactionHandle;
end;
if (tao_fake in foptions) or
Db.StartdbTransaction(FTrans,FParams) then begin
OpenTrans;
end;
if checkcanevent(self,tmethod(fonafterstart)) then begin
fonafterstart(self);
end;
end;
Für MySQL ist Ftrans immer nil, fixes_2_6/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc:
Code: Alles auswählen
function TConnectionName.AllocateTransactionHandle: TSQLHandle;
begin
// Result:=TTransactionName.Create;
Result := nil;
end;
und darf daher im MySQL code nirgends verwendet werden. Das heisst, ob FTrans nil ist oder nicht hängt von der Datenbank ab und sollte nicht für Entscheidungen herangezogen werden.
Code: Alles auswählen
procedure TSQLTransaction.StartTransaction;
[...]
if not assigned(FTrans) then FTrans := Db.AllocateTransactionHandle;
if Db.StartdbTransaction(FTrans,FParams.CommaText) then OpenTrans; <<<---
Obenstehendes funktioniert, da FTrans in MySQL StartdbTransaction() nicht verwendet wird.
fixes_2_6/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc:
Code: Alles auswählen
function TConnectionName.StartdbTransaction(trans: TSQLHandle; AParams : string): boolean;
begin
Result := mysql_query(FMySQL, 'START TRANSACTION') = 0;
if not Result then
MySQLError(FMySQL, SErrExecuting, Self);
end;
In MSEgui habe ich eine neue einheitliche tmysqlconnection für alle MySQL Versionen ab 5.0 gemacht. Dort sieht es so aus:
Code: Alles auswählen
function tmysqlconnection.AllocateTransactionHandle: TSQLHandle;
begin
// Result:=tmysqltransaction.Create;
Result:= tmysqltrans.create;
end;
function tmysqlconnection.StartdbTransaction(const trans: TSQLHandle;
const AParams: tstringlist): boolean;
begin
with tmysqltrans(trans) do begin
if fconn = nil then begin
if not ftransactionconnectionused then begin
fconn:= self.fmysql1;
ftransactionconnectionused:= true;
end
else begin
openconnection(fconn);
end;
end;
begintrans(fconn,aparams.text);
end;
result:= true;
end;
procedure tmysqlconnection.begintrans(const aconnection: pmysql;
const aparams: ansistring);
var
str1: ansistring;
begin
str1:= 'START TRANSACTION '+aparams;
if mysql_real_query(aconnection,pointer(str1),length(str1)) <> 0 then begin
checkerror(serrstarttransaction,aconnection);
end;
end;