Browse Source

* Patches from Joost van der Sluis
interbase.pp:
* Removed unused Fprepared
* Changed the error message 'database connect string not filled
in' to 'database connect string (databasename) not filled in'
* Preparestatement and execute now checks if transaction is
assigned (in stead of crashing if it isn't) and if the
transaction isn't started, it calls starttransaction.

dataset.inc:
* In DoInternalOpen the buffers are now initialised before the
dataset is set into browse-state

database.inc and db.pp:
* If the dataset is created from a stream, the database is opened
after the dataset is read completely

michael 21 years ago
parent
commit
c1e1d4f8d8
4 changed files with 129 additions and 19 deletions
  1. 32 3
      fcl/db/database.inc
  2. 48 12
      fcl/db/dataset.inc
  3. 20 1
      fcl/db/db.pp
  4. 29 3
      fcl/db/interbase/interbase.pp

+ 32 - 3
fcl/db/database.inc

@@ -36,7 +36,8 @@ end;
 procedure TDataBase.Loaded;
 
 begin
-  //!! To be implemented.
+  inherited;
+  if FOpenAfterRead then SetConnected(true);
 end;
 
 procedure TDataBase.SetConnected (Value : boolean);
@@ -45,11 +46,21 @@ begin
   If Value<>FConnected then
     begin
     If Value then
-      DoInternalConnect
+      begin
+      if csLoading in ComponentState then
+        begin
+        FOpenAfterRead := true;
+        exit;
+        end
+      else
+        DoInternalConnect;
+      end
     else
       begin
       Closedatasets;
       DoInternalDisConnect;
+      if csloading in ComponentState then
+        FOpenAfterRead := false;
       end;
     FConnected:=Value;
     end;
@@ -193,7 +204,25 @@ end;
 
 {
   $Log$
-  Revision 1.4  2003-08-16 16:42:21  michael
+  Revision 1.5  2004-07-25 11:32:40  michael
+  * Patches from Joost van der Sluis
+    interbase.pp:
+        * Removed unused Fprepared
+        * Changed the error message 'database connect string not filled
+          in' to 'database connect string (databasename) not filled in'
+        * Preparestatement and execute now checks if transaction is
+          assigned (in stead of crashing if it isn't) and if the
+          transaction isn't started, it calls starttransaction.
+
+     dataset.inc:
+        * In DoInternalOpen the buffers are now initialised before the
+          dataset is set into browse-state
+
+     database.inc and db.pp:
+        * If the dataset is created from a stream, the database is opened
+          after the dataset is read completely
+
+  Revision 1.4  2003/08/16 16:42:21  michael
   + Fixes in TDBDataset etc. Changed MySQLDb to use database as well
 
   Revision 1.3  2002/09/07 15:15:22  peter

+ 48 - 12
fcl/db/dataset.inc

@@ -323,9 +323,8 @@ begin
     InternalOpen;
     FBOF:=True;
 {$ifdef dsdebug}
-    Writeln ('Setting state to browse');
+    Writeln ('Setting buffer size');
 {$endif}
-    SetState(dsBrowse);
 {$ifdef dsdebug}
     Writeln ('Setting buffer size');
 {$endif}
@@ -338,6 +337,10 @@ begin
     *)
     RecalcBufListSize;
     //SetBufferCount(DefaultBufferCount);
+{$ifdef dsdebug}
+    Writeln ('Setting state to browse');
+{$endif}
+    SetState(dsBrowse);
     DoAfterOpen;
     DoAfterScroll;
   except
@@ -573,7 +576,7 @@ Var Shifted : boolean;
 
 begin
 {$ifdef dsdebug}
-  Writeln ('Getting previous record');
+  Writeln ('GetPriorRecord: Getting previous record');
 {$endif}
   Shifted:=FRecordCount>0;
   If Shifted Then
@@ -1076,7 +1079,7 @@ begin
     SetBookMarkFlag(Buffer,bfEOF);
     FRecordCount:=1;
 {$ifdef dsdebug}
-    Writeln ('getting prior records');
+    Writeln ('DoInsertAppend: getting prior records');
 {$endif}
     GetPriorRecords;
     // update active record.
@@ -1535,25 +1538,37 @@ Var Count,ShiftCount : Longint;
 
 begin
   // See if we can find the requested record.
+{$ifdef dsdebug}
+    Writeln ('Resync called');
+{$endif}
   If rmExact in Mode then
     begin
+{$ifdef dsdebug}
+    Writeln ('Exact resync');
+{$endif}
     { throw an exception if not found.
       Normally the descendant should do this if DoCheck is true. }
-    If GetRecord(Fbuffers[FRecordCount],gmcurrent,True)<>grOk Then
+    If GetRecord(Fbuffers[FRecordCount-1],gmcurrent,True)<>grOk Then
       DatabaseError(SNoSuchRecord,Self);
     end
   else
     { Can we find a record in the neighbourhood ?
       Use Shortcut evaluation for this, or we'll have some funny results. }
-    If (GetRecord(Fbuffers[FRecordCount],gmcurrent,True)<>grOk) and
-       (GetRecord(Fbuffers[FRecordCount],gmprior,True)<>grOk) and
-       (GetRecord(Fbuffers[FRecordCount],gmprior,True)<>grOk) then
+    If (GetRecord(Fbuffers[FRecordCount-1],gmcurrent,True)<>grOk) and
+       (GetRecord(Fbuffers[FRecordCount-1],gmprior,True)<>grOk) and
+       (GetRecord(Fbuffers[FRecordCount-1],gmprior,True)<>grOk) then
        begin
+{$ifdef dsdebug}
+       Writeln ('Resync: fuzzy resync');
+{$endif}
        // nothing found, invalidate buffer and bail out.
        ClearBuffers;
        DataEvent(deDatasetChange,0);
        Exit;
        end;
+{$ifdef dsdebug}
+   Writeln ('Resync: Center in  resync: ',(rmCenter in Mode));
+{$endif}
   If (rmCenter in Mode) then
     ShiftCount:=FbufferCount div 2
   else
@@ -1561,17 +1576,23 @@ begin
     ShiftCount:=FActiveRecord;
   // Reposition on 0
   ShiftBuffers(0,FRecordCount-1);
+{$ifdef dsdebug}
+    Writeln ('Resync: activating buffers');
+{$endif}
   ActivateBuffers;
   try
     Count:=0;
 {$ifdef dsdebug}
-    Writeln ('Getting previous',ShiftCount,' records');
+    Writeln ('Resync: Getting previous ',ShiftCount,' records');
 {$endif}
     While (Count<ShiftCount) and GetPriorRecord do
       Inc(Count);
     FActiveRecord:=Count;
     // fill rest of buffers, adjust ActiveBuffer.
-    SetCurrentRecord(FRecordCount);
+{$ifdef dsdebug}
+    Writeln ('Resync: Set current record to ',FRecordCount,' records');
+{$endif}
+    SetCurrentRecord(FRecordCount-1);
     GetNextRecords;
     Inc(FActiveRecord,GetPriorRecords);
   finally
@@ -1719,8 +1740,23 @@ end;
 
 {
   $Log$
-  Revision 1.14  2004-07-16 19:37:40  michael
-  + Fix in resync for empty table
+  Revision 1.15  2004-07-25 11:32:40  michael
+  * Patches from Joost van der Sluis
+    interbase.pp:
+        * Removed unused Fprepared
+        * Changed the error message 'database connect string not filled
+          in' to 'database connect string (databasename) not filled in'
+        * Preparestatement and execute now checks if transaction is
+          assigned (in stead of crashing if it isn't) and if the
+          transaction isn't started, it calls starttransaction.
+
+     dataset.inc:
+        * In DoInternalOpen the buffers are now initialised before the
+          dataset is set into browse-state
+
+     database.inc and db.pp:
+        * If the dataset is created from a stream, the database is opened
+          after the dataset is read completely
 
   Revision 1.13  2004/05/02 21:23:18  peter
     * use ptrint

+ 20 - 1
fcl/db/db.pp

@@ -1207,6 +1207,7 @@ type
     FOnLogin : TLoginEvent;
     FParams : TStrings;
     FSQLBased : Boolean;
+    FOpenAfterRead : boolean;
     Function GetDataSetCount : Longint;
     Function GetDataset(Index : longint) : TDBDataset;
     procedure SetConnected (Value : boolean);
@@ -1499,7 +1500,25 @@ end.
 
 {
   $Log$
-  Revision 1.18  2004-07-19 20:27:28  michael
+  Revision 1.19  2004-07-25 11:32:40  michael
+  * Patches from Joost van der Sluis
+    interbase.pp:
+        * Removed unused Fprepared
+        * Changed the error message 'database connect string not filled
+          in' to 'database connect string (databasename) not filled in'
+        * Preparestatement and execute now checks if transaction is
+          assigned (in stead of crashing if it isn't) and if the
+          transaction isn't started, it calls starttransaction.
+
+     dataset.inc:
+        * In DoInternalOpen the buffers are now initialised before the
+          dataset is set into browse-state
+
+     database.inc and db.pp:
+        * If the dataset is created from a stream, the database is opened
+          after the dataset is read completely
+
+  Revision 1.18  2004/07/19 20:27:28  michael
   + Fixes from Jesus Reyes to implement DisplayWith, DisplayLabel, Visibility
 
   Revision 1.17  2004/07/18 13:16:50  michael

+ 29 - 3
fcl/db/interbase/interbase.pp

@@ -204,7 +204,6 @@ type
     FRecordSize          : word;
     FCurrentRecord       : integer;
     FSQL                 : TStrings;
-    FPrepared            : boolean;
     FIsEOF               : boolean;
     FStatementType       : TStatementType;
     FLoadingFieldDefs    : boolean;
@@ -416,7 +415,7 @@ begin
     DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
 
   if (DatabaseName = '') then
-    raise EInterBaseError.Create('TIBDatabase.Open: Database connect string not filled in!');
+    raise EInterBaseError.Create('TIBDatabase.Open: Database connect string (DatabaseName) not filled in!');
   FIBDatabaseHandle := nil;
   if isc_attach_database(@FStatus, Length(DatabaseName), @DatabaseName[1], @FIBDatabaseHandle,
          Length(DPB), @DPB[1]) <> 0 then
@@ -635,6 +634,11 @@ var
   x   : integer;
   tr  : pointer;
 begin
+  if FTransaction = nil then
+    raise EDatabaseError.Create('TIBQuery.Execute: Transaction not set');
+  if not FTransaction.Active then
+    FTransaction.StartTransaction;
+
   tr := FTransaction.GetHandle;
 
   for x := 0 to FSQL.Count - 1 do
@@ -861,6 +865,10 @@ procedure TIBQuery.Execute;
 var
   tr : pointer;
 begin
+  if FTransaction = nil then
+    raise EDatabaseError.Create('TIBQuery.Execute: Transaction not set');
+  if not FTransaction.Active then
+    FTransaction.StartTransaction;
   tr := FTransaction.GetHandle;
   if isc_dsql_execute(@FStatus, @tr, @FStatement, 1, nil) <> 0 then
     CheckError('TIBQuery.Execute', FStatus);
@@ -1200,7 +1208,25 @@ end.
 
 {
   $Log$
-  Revision 1.12  2004-05-01 23:56:59  michael
+  Revision 1.13  2004-07-25 11:32:40  michael
+  * Patches from Joost van der Sluis
+    interbase.pp:
+        * Removed unused Fprepared
+        * Changed the error message 'database connect string not filled
+          in' to 'database connect string (databasename) not filled in'
+        * Preparestatement and execute now checks if transaction is
+          assigned (in stead of crashing if it isn't) and if the
+          transaction isn't started, it calls starttransaction.
+
+     dataset.inc:
+        * In DoInternalOpen the buffers are now initialised before the
+          dataset is set into browse-state
+
+     database.inc and db.pp:
+        * If the dataset is created from a stream, the database is opened
+          after the dataset is read completely
+
+  Revision 1.12  2004/05/01 23:56:59  michael
   + Published TDataset properties
 
   Revision 1.11  2003/12/07 23:13:34  sg