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
@@ -138,7 +138,7 @@ endif
 # Targets
 
 override UNITOBJECTS+=db ddg_ds ddg_rec mysqldb
-override EXAMPLEOBJECTS+=testds createds mtest
+override EXAMPLEOBJECTS+=testds createds mtest tested
 
 # Clean
 
@@ -168,7 +168,9 @@ endif
 
 # Packages
 
+override PACKAGES+=mysql
 override NEEDUNITDIR+=$(FPCDIR)/fcl/$(OS_TARGET)
+override NEEDUNITDIR+=$(addprefix $(PACKAGEDIR)/,$(PACKAGES))
 
 # Libraries
 
@@ -691,7 +693,18 @@ fcl_package:
 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
@@ -1023,6 +1036,8 @@ ddg_ds$(PPUEXT): db$(PPUEXT) ddg_rec$(PPUEXT) ddg_ds$(PASEXT)
 
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 
+tested$(EXEEXT): ddg_ds$(PPUEXT) tested$(PASEXT)
+
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 
 mysqldb$(PPUEXT): db$(PPUEXT) mysqldb$(PASEXT)

+ 4 - 1
fcl/db/Makefile.fpc

@@ -4,10 +4,11 @@
 
 [targets]
 units=db ddg_ds ddg_rec mysqldb
-examples=testds createds mtest
+examples=testds createds mtest tested
 
 [packages]
 fcl=1
+packages=mysql 
 
 [dirs]
 fpcdir=../..
@@ -28,6 +29,8 @@ ddg_ds$(PPUEXT): db$(PPUEXT) ddg_rec$(PPUEXT) ddg_ds$(PASEXT)
 
 testds$(EXEEXT): ddg_ds$(PPUEXT) testds$(PASEXT)
 
+tested$(EXEEXT): ddg_ds$(PPUEXT) tested$(PASEXT)
+
 createds$(EXEEXT): createds$(PASEXT) ddg_rec$(PPUEXT)
 
 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.
 
-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
 and add -Fl/path/to/libmysqlclient to NEEDOPTS as well as
 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 : 
 
@@ -22,15 +29,18 @@ TddgDataset :
   To test it, do a 
    createds filename
    testds filename
+   tested filename
   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 :
   Implemented in mysqldb. You need the mysql units for this.
   This is a temporary implementation based on the code from
      Rangel Gustavo Reale ([email protected]) 
   it will be used as a base for the DBdataset scalable dataset
-  implemntation.
+  implementation.
   To test it, do a 
      mtest db user pwd SQL
   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
       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 !
 

+ 24 - 2
fcl/db/dataset.inc

@@ -930,7 +930,7 @@ begin
     // need to scroll up al buffers after current one,
     // but copy current bookmark to insert buffer.
     BookBeforeInsert:=Bookmark;
-    ShiftBuffers(FActiveRecord,1);
+    ShiftBuffers(1,FActiveRecord);
     // Active buffer is now edit buffer. Initialize.
     InitRecord(ActiveBuffer);
     // Put bookmark in edit buffer.
@@ -1267,11 +1267,23 @@ Procedure TDataset.Post;
 begin
   if State in [dsEdit,dsInsert] then
     begin
+{$ifdef dsdebug}    
+    writeln ('Post: checking required fields');
+{$endif}
     CheckRequired;
     DoBeforePost;
     If Not TryDoing(@InternalPost,OnPostError) then exit;
+{$ifdef dsdebug}    
+    writeln ('Post: Internalpost succeeded');
+{$endif}
     FreeFieldBuffers;
+{$ifdef dsdebug}    
+    writeln ('Post: Freeing field buffers');
+{$endif}
     SetState(dsBrowse);
+{$ifdef dsdebug}    
+    writeln ('Post: Browse mode set');
+{$endif}
     Resync([]);
     DoAfterPost;
     end;
@@ -1359,12 +1371,19 @@ Var Retry : TDataAction;
 begin
   {$ifdef dsdebug}
   Writeln ('Trying to do');
+  If P=Nil then writeln ('Procedure to call is nil !!!');
   {$endif dsdebug}
   Result:=True;
   Retry:=daRetry;
   while Retry=daRetry do
     Try 
+  {$ifdef dsdebug}
+  Writeln ('Trying : updatecursorpos');
+  {$endif dsdebug}
       UpdateCursorPos;
+  {$ifdef dsdebug}
+  Writeln ('Trying to do it');
+  {$endif dsdebug}
       P;
       exit;
     except
@@ -1456,7 +1475,10 @@ end;
 
 {
   $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
 
   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
   RecPos, InsPos: Integer;
 begin
+ {$ifdef dsdebug}
+  Writeln ('Starting internal post.');
+ {$endif}
   if FRecordPos = -1 then
     RecPos := 0
   else begin

+ 58 - 15
fcl/db/tested.pp

@@ -75,6 +75,19 @@ begin
     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 
   Data : TDDGdataset;
   I,Count : longint;
@@ -144,21 +157,21 @@ begin
     FieldByName('DateTimeField').AsDateTime:=Now;
     FieldByName('DateField').AsDateTime:=Date;
     FieldByName('TimeField').AsDateTime:=Time;
+    Writeln ('End of append, going to post');
     Post;
+    DumpFields(Data);
     Writeln ('Doing Last');
     Writeln ('----------');
     Last;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Prior');
     Writeln ('----------');
     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 ('--------------------------');
     first;
-    for I:=1 to 4 do 
+    for I:=1 to 7 do 
       Next;
     Insert;
     FieldByName('Name').AsString:='Insertname';
@@ -173,30 +186,60 @@ begin
     Post;
     Writeln ('Doing field dump');
     writeln ('----------------');
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Prior');
     Writeln ('-----------');
     Prior;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Next');
     Writeln ('----------');
     Next;
-    For I:=0 to FieldCount-1 do
-      DumpFieldData(Fields[i]);
+    DumpFields(Data);
     Writeln ('Doing Next');
     Writeln ('----------');
     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.');   
     Close;
     end;
 end.
 {
   $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
 
   Revision 1.1  1999/11/14 19:26:17  michael