From c1935de5632168e7b05bb2f47121cd96f21a3387 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 7 Apr 2015 13:09:56 +0000 Subject: [PATCH] * Patch from Laco to fix assigning transaction/database when database/transaction does not match git-svn-id: trunk@30483 - --- packages/fcl-db/src/sqldb/sqldb.pp | 65 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/fcl-db/src/sqldb/sqldb.pp b/packages/fcl-db/src/sqldb/sqldb.pp index 5194ac15e2..d386a8019f 100644 --- a/packages/fcl-db/src/sqldb/sqldb.pp +++ b/packages/fcl-db/src/sqldb/sqldb.pp @@ -861,12 +861,27 @@ begin begin FDatabase.FreeNotification(Self); FDatabase.RegisterStatement(Self); - if (Transaction=nil) and (Assigned(FDatabase.Transaction)) then - transaction := FDatabase.Transaction; + if not Assigned(Transaction) or (Transaction.DataBase <> FDatabase) then + Transaction := FDatabase.Transaction; OnChangeSQL(Self); end; end; +procedure TCustomSQLStatement.SetTransaction(AValue: TSQLTransaction); +begin + if FTransaction=AValue then Exit; + UnPrepare; + if Assigned(FTransaction) then + FTransaction.RemoveFreeNotification(Self); + FTransaction:=AValue; + if Assigned(FTransaction) then + begin + FTransaction.FreeNotification(Self); + if Database <> FTransaction.DataBase then + Database := Transaction.Database as TSQLConnection; + end; +end; + procedure TCustomSQLStatement.SetDataSource(AValue: TDataSource); begin @@ -894,21 +909,6 @@ begin FSQL.Assign(AValue); end; -procedure TCustomSQLStatement.SetTransaction(AValue: TSQLTransaction); -begin - if FTransaction=AValue then Exit; - UnPrepare; - if Assigned(FTransaction) then - FTransaction.RemoveFreeNotification(Self); - FTransaction:=AValue; - if Assigned(FTransaction) then - begin - FTransaction.FreeNotification(Self); - If (Database=Nil) then - Database:=Transaction.Database as TSQLConnection; - end; -end; - Procedure TCustomSQLStatement.DoExecute; begin FRowsAffected:=-1; @@ -2293,31 +2293,30 @@ end; procedure TCustomSQLQuery.SetTransaction(Value: TDBTransaction); begin + if Transaction = Value then Exit; UnPrepare; inherited; If Assigned(FStatement) then - FStatement.Transaction:=TSQLTransaction(Value); - If (Transaction<>Nil) and (Database=Nil) then - Database:=SQLTransaction.Database; + FStatement.Transaction := TSQLTransaction(Value); + If Assigned(Transaction) and (SQLTransaction.DataBase<>Database) then + Database := Transaction.Database; end; procedure TCustomSQLQuery.SetDatabase(Value : TDatabase); -var db : tsqlconnection; +var DB : TSQLConnection; begin - if (Database <> Value) then - begin - if assigned(value) and not (Value is TSQLConnection) then - DatabaseErrorFmt(SErrNotASQLConnection,[value.Name],self); - UnPrepare; - db := TSQLConnection(Value); - If Assigned(FStatement) then - FStatement.Database:=DB; - inherited setdatabase(value); - if assigned(value) and (Transaction = nil) and (Assigned(db.Transaction)) then - transaction := Db.Transaction; - end; + if Database = Value then Exit; + if Assigned(Value) and not (Value is TSQLConnection) then + DatabaseErrorFmt(SErrNotASQLConnection, [Value.Name], Self); + UnPrepare; + DB := TSQLConnection(Value); + If Assigned(FStatement) then + FStatement.Database := DB; + inherited; + if Assigned(DB) and Assigned(DB.Transaction) and (not Assigned(Transaction) or (Transaction.DataBase<>Value)) then + Transaction := DB.Transaction; end; function TCustomSQLQuery.IsPrepared: Boolean;