浏览代码

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 年之前
父节点
当前提交
2c0bd0fe59
共有 1 个文件被更改,包括 13 次插入14 次删除
  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;
     Function AddFilter(SQLstr : string) : string;
   protected
+    Function Cursor : TSQLCursor;
+    Function LogEvent(EventType : TDBEventType) : Boolean;
+    Procedure Log(EventType : TDBEventType; Const Msg : String); virtual;
     // abstract & virtual methods of TBufDataset
     function Fetch : boolean; override;
-    Function Cursor : TSQLCursor;
     function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
     procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); override;
     procedure ApplyRecUpdate(UpdateKind : TUpdateKind); override;
@@ -430,9 +432,6 @@ type
     class function FieldDefsClass : TFieldDefsClass; override;
     // IProviderSupport methods
     function PSGetUpdateException(E: Exception; Prev: EUpdateError): EUpdateError; override;
-
-    Function LogEvent(EventType : TDBEventType) : Boolean;
-    Procedure Log(EventType : TDBEventType; Const Msg : String); virtual;
   public
     constructor Create(AOwner : TComponent); override;
     destructor Destroy; override;
@@ -2063,9 +2062,9 @@ procedure TCustomSQLQuery.Prepare;
 
 begin
   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;
 
 procedure TCustomSQLQuery.UnPrepare;
@@ -2117,6 +2116,11 @@ begin
   Result:=Transaction as TSQLTransaction;
 end;
 
+function TCustomSQLQuery.Cursor: TSQLCursor;
+begin
+  Result:=FStatement.Cursor;
+end;
+
 function TCustomSQLQuery.Fetch : boolean;
 begin
   if Not Assigned(Cursor) then
@@ -2129,11 +2133,6 @@ begin
   Result := not FIsEOF;
 end;
 
-function TCustomSQLQuery.Cursor: TSQLCursor;
-begin
-  Result:=FStatement.Cursor;
-end;
-
 procedure TCustomSQLQuery.Execute;
 begin
   FStatement.Execute;
@@ -2189,11 +2188,11 @@ begin
 
   try
     FieldDefs.Clear;
-    if not Assigned(Database) then DatabaseError(SErrDatabasenAssigned);
+    Prepare;
     SQLConnection.AddFieldDefs(Cursor,FieldDefs);
   finally
     FLoadingFieldDefs := False;
-    if Assigned(Cursor) then Cursor.FInitFieldDef := false;
+    if assigned(Cursor) then Cursor.FInitFieldDef := False;
   end;
 end;