testds.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt, member of the
  5. Free Pascal development team
  6. Tests the TDDGDataset component.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. program testds;
  14. uses db,ddg_ds,sysutils;
  15. Procedure Log(Const Msg : String);
  16. begin
  17. Writeln(Msg);
  18. end;
  19. Procedure DumpFieldDef(F : TfieldDef);
  20. begin
  21. With F do
  22. begin
  23. Writeln ('Name : ',Name);
  24. Writeln ('FieldNo : ',FieldNo);
  25. Writeln ('Size : ',Size);
  26. Writeln ('FieldClass : ',FieldClass.ClassName);
  27. Writeln ('Required : ',required);
  28. Writeln ('Precision : ',Precision);
  29. Writeln ('DataType : ',FieldTypeNames[DataType]);
  30. Writeln ('InternalCalcField : ',Internalcalcfield);
  31. end;
  32. end;
  33. Procedure DumpField(F : Tfield);
  34. begin
  35. With F do
  36. begin
  37. writeln ('-------------------------------------');
  38. Writeln ('FieldName : ',FieldName);
  39. Writeln ('FieldNo : ',FieldNo);
  40. Writeln ('Index : ',Index);
  41. Writeln ('DataSize : ',DataSize);
  42. Writeln ('Size : ',Size);
  43. Writeln ('DataType : ',FieldTypeNames[DataType]);
  44. Writeln ('Class : ',ClassName);
  45. Writeln ('Required : ',required);
  46. Writeln ('ReadOnly : ',ReadOnly);
  47. Writeln ('Visible : ',Visible);
  48. end;
  49. end;
  50. Procedure DumpFieldData (F : TField);
  51. begin
  52. With F Do
  53. begin
  54. Writeln ('Field : ',FieldName);
  55. Writeln ('Data type : ',FieldTypeNames[DataType]);
  56. Writeln ('As String : ',Asstring);
  57. Case Datatype of
  58. ftSmallint, ftInteger, ftWord : Writeln ('As longint : ',AsLongint);
  59. ftBoolean : Writeln ('As Boolean : ',AsBoolean);
  60. ftFloat : Writeln ('As Float : ',AsFloat);
  61. ftDate, ftTime, ftDateTime : Writeln ('As DateTime : ',DateTimeToStr(AsDateTime));
  62. end;
  63. end;
  64. end;
  65. Var
  66. Data : TDDGdataset;
  67. I,Count : longint;
  68. Bookie : TBookMarkStr;
  69. Procedure ScrollForward;
  70. begin
  71. Writeln ('Browsing Forward:');
  72. Writeln ('------------------');
  73. With Data do
  74. While NOT EOF do
  75. begin
  76. Writeln ('================================================');
  77. For I:=0 to FieldCount-1 do
  78. DumpFieldData(Fields[I]);
  79. Next;
  80. end;
  81. end;
  82. Procedure ScrollBackWard;
  83. begin
  84. Writeln ('Browsing Backward:');
  85. Writeln ('-------------------');
  86. With Data do
  87. While NOT BOF do
  88. begin
  89. For I:=0 to FieldCount-1 do
  90. DumpFieldData(Fields[I]);
  91. Prior;
  92. end;
  93. end;
  94. begin
  95. if paramcount<>1 then
  96. begin
  97. Writeln ('Usage : testds tablename');
  98. Halt(1);
  99. end;
  100. Log ('Creating Dataset');
  101. Data:=TDDGDataset.Create(Nil);
  102. With Data do
  103. begin
  104. Log('Setting Tablename');
  105. TableName:=Paramstr(1);
  106. Log('Opening Dataset');
  107. Open;
  108. Log('Dumping fielddefs : ');
  109. Writeln ('Fielddefs count : ',FieldDefs.Count);
  110. For I:=0 to FieldDefs.Count-1 do
  111. DumpFieldDef(FieldDefs.Items[i]);
  112. Writeln ('Fields count : ',FieldCount);
  113. For I:=0 to FieldCount-1 do
  114. DumpField(Fields[i]);
  115. ScrollForward;
  116. ScrollBackWard;
  117. Writeln ('Going to last :');
  118. writeln ('---------------');
  119. Last;
  120. ScrollBackWard;
  121. ScrollForward;
  122. Writeln ('Going to first:');
  123. First;
  124. Count:=0;
  125. Writeln ('Browsing Forward:');
  126. Writeln ('------------------');
  127. With Data do
  128. While NOT EOF do
  129. begin
  130. Inc(Count);
  131. If Count=50 then
  132. begin
  133. Writeln ('Setting bookmark on record');
  134. Bookie:=Bookmark;
  135. Writeln ('Got data : "',Bookie,'"');
  136. end;
  137. For I:=0 to FieldCount-1 do
  138. DumpFieldData(Fields[I]);
  139. Next;
  140. end;
  141. Writeln ('Jumping to bookmark',Bookie);
  142. BookMark:=Bookie;
  143. Writeln ('Dumping Record : ');
  144. For I:=0 to FieldCount-1 do
  145. DumpFieldData(Fields[I]);
  146. Next;
  147. Writeln ('Dumping Next Record : ');
  148. For I:=0 to FieldCount-1 do
  149. DumpFieldData(Fields[I]);
  150. Prior;
  151. Prior;
  152. Writeln ('Dumping Previous Record : ');
  153. For I:=0 to FieldCount-1 do
  154. DumpFieldData(Fields[I]);
  155. Log('Closing Dataset');
  156. Close;
  157. Log('End.');
  158. Free;
  159. end;
  160. end.
  161. {
  162. $Log$
  163. Revision 1.1 2000-09-01 22:02:10 peter
  164. * build also db
  165. Revision 1.1 2000/07/13 06:31:28 michael
  166. + Initial import
  167. Revision 1.6 2000/01/07 01:24:32 peter
  168. * updated copyright to 2000
  169. Revision 1.5 2000/01/06 01:20:32 peter
  170. * moved out of packages/ back to topdir
  171. Revision 1.1 2000/01/03 19:33:06 peter
  172. * moved to packages dir
  173. Revision 1.3 1999/11/11 17:31:09 michael
  174. + Added Checks for all simple field types.
  175. + Initial implementation of Insert/Append
  176. Revision 1.2 1999/10/24 17:07:54 michael
  177. + Added copyright header
  178. }