[fpc-devel]Fixes for interbase/db

Joost van der Sluis joost at cnoc.nl
Sat Jul 24 17:21:44 CEST 2004


Hi all,

i have some fixes for the database implementation in FCL. 

Changes in 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.

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

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

-- 
Joost van der Sluis <joost at cnoc.nl>
CNOC
-------------- next part --------------
***************
*** 1200,1205 ****
--- 1200,1206 ----
      FOnLogin : TLoginEvent;
      FParams : TStrings;
      FSQLBased : Boolean;
+     FOpenAfterRead : boolean;
      Function GetDataSetCount : Longint;
      Function GetDataset(Index : longint) : TDBDataset;
      procedure SetConnected (Value : boolean);
-------------- next part --------------
***************
*** 204,210 ****
      FRecordSize          : word;
      FCurrentRecord       : integer;
      FSQL                 : TStrings;
-     FPrepared            : boolean;
      FIsEOF               : boolean;
      FStatementType       : TStatementType;
      FLoadingFieldDefs    : boolean;
--- 204,209 ----
***************
*** 416,422 ****
      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!');
    FIBDatabaseHandle := nil;
    if isc_attach_database(@FStatus, Length(DatabaseName), @DatabaseName[1], @FIBDatabaseHandle,
           Length(DPB), @DPB[1]) <> 0 then
--- 415,421 ----
      DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
  
    if (DatabaseName = '') then
!     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,640 ****
--- 634,644 ----
    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,866 ****
--- 865,874 ----
  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);
-------------- next part --------------
***************
*** 36,42 ****
  procedure TDataBase.Loaded;
  
  begin
!   //!! To be implemented.
  end;
  
  procedure TDataBase.SetConnected (Value : boolean);
--- 36,43 ----
  procedure TDataBase.Loaded;
  
  begin
!   inherited;
!   if FOpenAfterRead then SetConnected(true);
  end;
  
  procedure TDataBase.SetConnected (Value : boolean);
***************
*** 45,55 ****
    If Value<>FConnected then
      begin
      If Value then
-       DoInternalConnect
-     else
        begin
        Closedatasets;
        DoInternalDisConnect;
        end;
      FConnected:=Value;
      end;
--- 46,66 ----
    If Value<>FConnected then
      begin
      If Value then
        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;
-------------- next part --------------
***************
*** 323,331 ****
      InternalOpen;
      FBOF:=True;
  {$ifdef dsdebug}
!     Writeln ('Setting state to browse');
  {$endif}
-     SetState(dsBrowse);
  {$ifdef dsdebug}
      Writeln ('Setting buffer size');
  {$endif}
--- 323,327 ----
      InternalOpen;
      FBOF:=True;
  {$ifdef dsdebug}
!     Writeln ('Setting buffer size');
  {$endif}
***************
*** 338,343 ****
--- 334,343 ----
      *)
      RecalcBufListSize;
      //SetBufferCount(DefaultBufferCount);
+ {$ifdef dsdebug}
+     Writeln ('Setting state to browse');
+ {$endif}
+     SetState(dsBrowse);
      DoAfterOpen;
      DoAfterScroll;
    except


More information about the fpc-devel mailing list