Browse Source

+ tested edit and insert methods

michael 26 years ago
parent
commit
6e68ef88c5
6 changed files with 127 additions and 32 deletions
  1. 18 3
      fcl/db/Makefile
  2. 4 1
      fcl/db/Makefile.fpc
  3. 20 11
      fcl/db/README
  4. 24 2
      fcl/db/dataset.inc
  5. 3 0
      fcl/db/ddg_ds.pp
  6. 58 15
      fcl/db/tested.pp

+ 18 - 3
fcl/db/Makefile

@@ -1,5 +1,5 @@
 #
 #
-# Makefile generated by fpcmake v0.99.13 on 1999-11-25 23:49
+# Makefile generated by fpcmake v0.99.13 on 1999-12-01 21:32
 #
 #
 
 
 defaultrule: all
 defaultrule: all
@@ -138,7 +138,7 @@ endif
 # Targets
 # Targets
 
 
 override UNITOBJECTS+=db ddg_ds ddg_rec mysqldb
 override UNITOBJECTS+=db ddg_ds ddg_rec mysqldb
-override EXAMPLEOBJECTS+=testds createds mtest
+override EXAMPLEOBJECTS+=testds createds mtest tested
 
 
 # Clean
 # Clean
 
 
@@ -168,7 +168,9 @@ endif
 
 
 # Packages
 # Packages
 
 
+override PACKAGES+=mysql
 override NEEDUNITDIR+=$(FPCDIR)/fcl/$(OS_TARGET)
 override NEEDUNITDIR+=$(FPCDIR)/fcl/$(OS_TARGET)
+override NEEDUNITDIR+=$(addprefix $(PACKAGEDIR)/,$(PACKAGES))
 
 
 # Libraries
 # Libraries
 
 
@@ -691,7 +693,18 @@ fcl_package:
 endif
 endif
 endif
 endif
 
 
-.PHONY:  rtl_package fcl_package
+PACKAGEMYSQL=1
+ifdef PACKAGEMYSQL
+ifneq ($(wildcard $(PACKAGEDIR)/mysql),)
+ifeq ($(wildcard $(PACKAGEDIR)/mysql/$(FPCMAKED)),)
+override COMPILEPACKAGES+=mysql
+mysql_package:
+	$(MAKE) -C $(PACKAGEDIR)/mysql all
+endif
+endif
+endif
+
+.PHONY:  rtl_package fcl_package mysql_package
 
 
 #####################################################################
 #####################################################################
 # Units
 # Units
@@ -1023,6 +1036,8 @@ ddg_ds$(PPUEXT): db$(PPUEXT) ddg_rec$(PPUEXT) ddg_ds$(PASEXT)
 
 
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 
 
+tested$(EXEEXT): ddg_ds$(PPUEXT) tested$(PASEXT)
+
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 
 
 mysqldb$(PPUEXT): db$(PPUEXT) mysqldb$(PASEXT)
 mysqldb$(PPUEXT): db$(PPUEXT) mysqldb$(PASEXT)

+ 4 - 1
fcl/db/Makefile.fpc

@@ -4,10 +4,11 @@
 
 
 [targets]
 [targets]
 units=db ddg_ds ddg_rec mysqldb
 units=db ddg_ds ddg_rec mysqldb
-examples=testds createds mtest
+examples=testds createds mtest tested
 
 
 [packages]
 [packages]
 fcl=1
 fcl=1
+packages=mysql 
 
 
 [dirs]
 [dirs]
 fpcdir=../..
 fpcdir=../..
@@ -28,6 +29,8 @@ ddg_ds$(PPUEXT): db$(PPUEXT) ddg_rec$(PPUEXT) ddg_ds$(PASEXT)
 
 
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 
 
+tested$(EXEEXT): ddg_ds$(PPUEXT) tested$(PASEXT)
+
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 
 
 mysqldb$(PPUEXT): db$(PPUEXT) mysqldb$(PASEXT)
 mysqldb$(PPUEXT): db$(PPUEXT) mysqldb$(PASEXT)

+ 20 - 11
fcl/db/README

@@ -1,19 +1,26 @@
 This is the Database directory of the Free Component Library.
 This is the Database directory of the Free Component Library.
 
 
-At the moment, there is a read-only implementation of TDataset.
-Also, there is no (tested) blob support yet.
+At the moment, there is a read/write implementation of TDataset.
+The blob support is not tested yet.
 
 
-Compiling:
+Compiling the units:
 
 
-Just run 'make' and all should go fine, provided
-1) The mysql unit is in the compiler path
-2) the mysqlclient library is in /usr/lib
+Just run 'make all' and all should go fine, provided
+1) The mysql unit is in the compiler path (the makefile will try to compile
+   it in the packages mysql subdirectory)
+2) the mysqlclient library is in /usr/lib (if you want to compile the mtest 
+   program)
 if these conditions are not satisfied, you should edit the makefile
 if these conditions are not satisfied, you should edit the makefile
 and add -Fl/path/to/libmysqlclient to NEEDOPTS as well as
 and add -Fl/path/to/libmysqlclient to NEEDOPTS as well as
 the -Fu/path/to/mysql/unit option.
 the -Fu/path/to/mysql/unit option.
 
 
+Compiling the examples:
 
 
-there are 2 descendents to demonstrate/test the TDataset:
+If the units compile fine, then the examples can be compiled by doing
+'make examples'. see also the above remarks.
+
+there are 2 descendents of TDataset to demonstrate/test the 
+TDataset implementation.
 
 
 TddgDataset : 
 TddgDataset : 
 
 
@@ -22,15 +29,18 @@ TddgDataset :
   To test it, do a 
   To test it, do a 
    createds filename
    createds filename
    testds filename
    testds filename
+   tested filename
   the first creates a flat file, filled with 100 records;
   the first creates a flat file, filled with 100 records;
-  the second tests the methods of TDataset on this file.
+  the second tests the navigation methods of TDataset on this file.
+  the third tests the editing methods of TDataset (Append,Insert 
+  and edit)
 
 
 TMySQLdataset :
 TMySQLdataset :
   Implemented in mysqldb. You need the mysql units for this.
   Implemented in mysqldb. You need the mysql units for this.
   This is a temporary implementation based on the code from
   This is a temporary implementation based on the code from
      Rangel Gustavo Reale ([email protected]) 
      Rangel Gustavo Reale ([email protected]) 
   it will be used as a base for the DBdataset scalable dataset
   it will be used as a base for the DBdataset scalable dataset
-  implemntation.
+  implementation.
   To test it, do a 
   To test it, do a 
      mtest db user pwd SQL
      mtest db user pwd SQL
   this will run the query SQL on the database db with user
   this will run the query SQL on the database db with user
@@ -40,8 +50,7 @@ TMySQLdataset :
   that comes with the Free Pascal mysql unit, I did a
   that comes with the Free Pascal mysql unit, I did a
       mtest test michael pwd 'select * from FPdev'
       mtest test michael pwd 'select * from FPdev'
 
 
-  I haven't tested Date or time fields yes, just string,float and
-  integer fields.
+I haven't implemented/tested blob fields yet.
 
 
 Enjoy !
 Enjoy !
 
 

+ 24 - 2
fcl/db/dataset.inc

@@ -930,7 +930,7 @@ begin
     // need to scroll up al buffers after current one,
     // need to scroll up al buffers after current one,
     // but copy current bookmark to insert buffer.
     // but copy current bookmark to insert buffer.
     BookBeforeInsert:=Bookmark;
     BookBeforeInsert:=Bookmark;
-    ShiftBuffers(FActiveRecord,1);
+    ShiftBuffers(1,FActiveRecord);
     // Active buffer is now edit buffer. Initialize.
     // Active buffer is now edit buffer. Initialize.
     InitRecord(ActiveBuffer);
     InitRecord(ActiveBuffer);
     // Put bookmark in edit buffer.
     // Put bookmark in edit buffer.
@@ -1267,11 +1267,23 @@ Procedure TDataset.Post;
 begin
 begin
   if State in [dsEdit,dsInsert] then
   if State in [dsEdit,dsInsert] then
     begin
     begin
+{$ifdef dsdebug}    
+    writeln ('Post: checking required fields');
+{$endif}
     CheckRequired;
     CheckRequired;
     DoBeforePost;
     DoBeforePost;
     If Not TryDoing(@InternalPost,OnPostError) then exit;
     If Not TryDoing(@InternalPost,OnPostError) then exit;
+{$ifdef dsdebug}    
+    writeln ('Post: Internalpost succeeded');
+{$endif}
     FreeFieldBuffers;
     FreeFieldBuffers;
+{$ifdef dsdebug}    
+    writeln ('Post: Freeing field buffers');
+{$endif}
     SetState(dsBrowse);
     SetState(dsBrowse);
+{$ifdef dsdebug}    
+    writeln ('Post: Browse mode set');
+{$endif}
     Resync([]);
     Resync([]);
     DoAfterPost;
     DoAfterPost;
     end;
     end;
@@ -1359,12 +1371,19 @@ Var Retry : TDataAction;
 begin
 begin
   {$ifdef dsdebug}
   {$ifdef dsdebug}
   Writeln ('Trying to do');
   Writeln ('Trying to do');
+  If P=Nil then writeln ('Procedure to call is nil !!!');
   {$endif dsdebug}
   {$endif dsdebug}
   Result:=True;
   Result:=True;
   Retry:=daRetry;
   Retry:=daRetry;
   while Retry=daRetry do
   while Retry=daRetry do
     Try 
     Try 
+  {$ifdef dsdebug}
+  Writeln ('Trying : updatecursorpos');
+  {$endif dsdebug}
       UpdateCursorPos;
       UpdateCursorPos;
+  {$ifdef dsdebug}
+  Writeln ('Trying to do it');
+  {$endif dsdebug}
       P;
       P;
       exit;
       exit;
     except
     except
@@ -1456,7 +1475,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.5  1999-11-12 22:53:32  michael
+  Revision 1.6  1999-12-01 22:11:02  michael
+  + tested edit and insert methods
+
+  Revision 1.5  1999/11/12 22:53:32  michael
   + Added append() insert() tested append. Datetime as string works now
   + Added append() insert() tested append. Datetime as string works now
 
 
   Revision 1.4  1999/11/11 17:31:09  michael
   Revision 1.4  1999/11/11 17:31:09  michael

+ 3 - 0
fcl/db/ddg_ds.pp

@@ -441,6 +441,9 @@ procedure TDDGDataSet.InternalPost;
 var
 var
   RecPos, InsPos: Integer;
   RecPos, InsPos: Integer;
 begin
 begin
+ {$ifdef dsdebug}
+  Writeln ('Starting internal post.');
+ {$endif}
   if FRecordPos = -1 then
   if FRecordPos = -1 then
     RecPos := 0
     RecPos := 0
   else begin
   else begin

+ 58 - 15
fcl/db/tested.pp

@@ -75,6 +75,19 @@ begin
     end;
     end;
 end;
 end;
 
 
+procedure DumpFields (DS : TDataset);
+
+Var I : longint;
+
+begin
+  With DS do 
+    begin
+    Writeln('Dumping fields');
+    For I:=0 to FieldCount-1 do
+      DumpFieldData(Fields[i]);
+    end;
+end;
+
 Var 
 Var 
   Data : TDDGdataset;
   Data : TDDGdataset;
   I,Count : longint;
   I,Count : longint;
@@ -144,21 +157,21 @@ begin
     FieldByName('DateTimeField').AsDateTime:=Now;
     FieldByName('DateTimeField').AsDateTime:=Now;
     FieldByName('DateField').AsDateTime:=Date;
     FieldByName('DateField').AsDateTime:=Date;
     FieldByName('TimeField').AsDateTime:=Time;
     FieldByName('TimeField').AsDateTime:=Time;
+    Writeln ('End of append, going to post');
     Post;
     Post;
+    DumpFields(Data);
     Writeln ('Doing Last');
     Writeln ('Doing Last');
     Writeln ('----------');
     Writeln ('----------');
     Last;
     Last;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Prior');
     Writeln ('Doing Prior');
     Writeln ('----------');
     Writeln ('----------');
     Prior;
     Prior;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
-    Writeln ('Doing Insert at position 5');
+    DumpFields(Data);
+    Writeln ('Doing Insert at position 8');
     writeln ('--------------------------');
     writeln ('--------------------------');
     first;
     first;
-    for I:=1 to 4 do 
+    for I:=1 to 7 do 
       Next;
       Next;
     Insert;
     Insert;
     FieldByName('Name').AsString:='Insertname';
     FieldByName('Name').AsString:='Insertname';
@@ -173,30 +186,60 @@ begin
     Post;
     Post;
     Writeln ('Doing field dump');
     Writeln ('Doing field dump');
     writeln ('----------------');
     writeln ('----------------');
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Prior');
     Writeln ('Doing Prior');
     Writeln ('-----------');
     Writeln ('-----------');
     Prior;
     Prior;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Next');
     Writeln ('Doing Next');
     Writeln ('----------');
     Writeln ('----------');
     Next;
     Next;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Next');
     Writeln ('Doing Next');
     Writeln ('----------');
     Writeln ('----------');
     Next;
     Next;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
+    Writeln ('Doing Edit at position 5');
+    writeln ('-------------------------');
+    first;
+    for I:=1 to 4 do 
+      Next;
+    Edit;
+    FieldByName('Name').AsString:='Editname';
+    FieldByName('Height').AsFloat:=3.33E3;
+    FieldByName('LongField').AsLongInt:=333;
+    FieldByName('ShoeSize').AsLongInt:=333;
+    FieldByName('WordField').AsLongInt:=333;
+    FieldByName('BooleanField').AsBoolean:=False;
+    FieldByName('DateTimeField').AsDateTime:=Now;
+    FieldByName('DateField').AsDateTime:=Date;
+    FieldByName('TimeField').AsDateTime:=Time;
+    Post;
+    Writeln ('Doing field dump');
+    writeln ('----------------');
+    DumpFields(Data);
+    Writeln ('Doing Prior');
+    Writeln ('-----------');
+    Prior;
+    DumpFields(Data);
+    Writeln ('Doing Next');
+    Writeln ('----------');
+    Next;
+    DumpFields(Data);
+    Writeln ('Doing Next');
+    Writeln ('----------');
+    Next;
+    DumpFields(Data);
     Writeln ('Closing.');   
     Writeln ('Closing.');   
     Close;
     Close;
     end;
     end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.2  1999-12-01 10:11:58  michael
+  Revision 1.3  1999-12-01 22:11:02  michael
+  + tested edit and insert methods
+
+  Revision 1.2  1999/12/01 10:11:58  michael
   + test of insert works now
   + test of insert works now
 
 
   Revision 1.1  1999/11/14 19:26:17  michael
   Revision 1.1  1999/11/14 19:26:17  michael