Bladeren bron

fcl-db: sqldb: when TSQLQuery.FieldDefs.Update is called (is used by IDE Field editor for "Add fields ...") for closed (never prepared) dataset then Cursor is nil, and is passed to TSQLConnection.AddFieldDefs where AV can occurs.
So call Prepare before ...
Bug #25829

git-svn-id: trunk@27021 -

lacak 11 jaren geleden
bovenliggende
commit
2c0bd0fe59
1 gewijzigde bestanden met toevoegingen van 13 en 14 verwijderingen
  1. 13 14
      packages/fcl-db/src/sqldb/sqldb.pp

+ 13 - 14
packages/fcl-db/src/sqldb/sqldb.pp

@@ -403,9 +403,11 @@ type
     procedure ApplyFilter;
     procedure ApplyFilter;
     Function AddFilter(SQLstr : string) : string;
     Function AddFilter(SQLstr : string) : string;
   protected
   protected
+    Function Cursor : TSQLCursor;
+    Function LogEvent(EventType : TDBEventType) : Boolean;
+    Procedure Log(EventType : TDBEventType; Const Msg : String); virtual;
     // abstract & virtual methods of TBufDataset
     // abstract & virtual methods of TBufDataset
     function Fetch : boolean; override;
     function Fetch : boolean; override;
-    Function Cursor : TSQLCursor;
     function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
     function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
     procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); override;
     procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); override;
     procedure ApplyRecUpdate(UpdateKind : TUpdateKind); override;
     procedure ApplyRecUpdate(UpdateKind : TUpdateKind); override;
@@ -430,9 +432,6 @@ type
     class function FieldDefsClass : TFieldDefsClass; override;
     class function FieldDefsClass : TFieldDefsClass; override;
     // IProviderSupport methods
     // IProviderSupport methods
     function PSGetUpdateException(E: Exception; Prev: EUpdateError): EUpdateError; override;
     function PSGetUpdateException(E: Exception; Prev: EUpdateError): EUpdateError; override;
-
-    Function LogEvent(EventType : TDBEventType) : Boolean;
-    Procedure Log(EventType : TDBEventType; Const Msg : String); virtual;
   public
   public
     constructor Create(AOwner : TComponent); override;
     constructor Create(AOwner : TComponent); override;
     destructor Destroy; override;
     destructor Destroy; override;
@@ -2063,9 +2062,9 @@ procedure TCustomSQLQuery.Prepare;
 
 
 begin
 begin
   FStatement.Prepare;
   FStatement.Prepare;
-  If Assigned(Fstatement.FCursor) then
-    With FStatement.FCursor do
-      FInitFieldDef:=FSelectable;
+  if Assigned(FStatement.FCursor) then
+    with FStatement.FCursor do
+      FInitFieldDef := FSelectable;
 end;
 end;
 
 
 procedure TCustomSQLQuery.UnPrepare;
 procedure TCustomSQLQuery.UnPrepare;
@@ -2117,6 +2116,11 @@ begin
   Result:=Transaction as TSQLTransaction;
   Result:=Transaction as TSQLTransaction;
 end;
 end;
 
 
+function TCustomSQLQuery.Cursor: TSQLCursor;
+begin
+  Result:=FStatement.Cursor;
+end;
+
 function TCustomSQLQuery.Fetch : boolean;
 function TCustomSQLQuery.Fetch : boolean;
 begin
 begin
   if Not Assigned(Cursor) then
   if Not Assigned(Cursor) then
@@ -2129,11 +2133,6 @@ begin
   Result := not FIsEOF;
   Result := not FIsEOF;
 end;
 end;
 
 
-function TCustomSQLQuery.Cursor: TSQLCursor;
-begin
-  Result:=FStatement.Cursor;
-end;
-
 procedure TCustomSQLQuery.Execute;
 procedure TCustomSQLQuery.Execute;
 begin
 begin
   FStatement.Execute;
   FStatement.Execute;
@@ -2189,11 +2188,11 @@ begin
 
 
   try
   try
     FieldDefs.Clear;
     FieldDefs.Clear;
-    if not Assigned(Database) then DatabaseError(SErrDatabasenAssigned);
+    Prepare;
     SQLConnection.AddFieldDefs(Cursor,FieldDefs);
     SQLConnection.AddFieldDefs(Cursor,FieldDefs);
   finally
   finally
     FLoadingFieldDefs := False;
     FLoadingFieldDefs := False;
-    if Assigned(Cursor) then Cursor.FInitFieldDef := false;
+    if assigned(Cursor) then Cursor.FInitFieldDef := False;
   end;
   end;
 end;
 end;