tested.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. procedure DumpFields (DS : TDataset);
  66. Var I : longint;
  67. begin
  68. With DS do
  69. begin
  70. Writeln('Dumping fields');
  71. For I:=0 to FieldCount-1 do
  72. DumpFieldData(Fields[i]);
  73. end;
  74. end;
  75. Var
  76. Data : TDDGdataset;
  77. I,Count : longint;
  78. Bookie : TBookMarkStr;
  79. Procedure ScrollForward;
  80. begin
  81. Writeln ('Browsing Forward:');
  82. Writeln ('------------------');
  83. With Data do
  84. While NOT EOF do
  85. begin
  86. Writeln ('================================================');
  87. For I:=0 to FieldCount-1 do
  88. DumpFieldData(Fields[I]);
  89. Next;
  90. end;
  91. end;
  92. Procedure ScrollBackWard;
  93. begin
  94. Writeln ('Browsing Backward:');
  95. Writeln ('-------------------');
  96. With Data do
  97. While NOT BOF do
  98. begin
  99. For I:=0 to FieldCount-1 do
  100. DumpFieldData(Fields[I]);
  101. Prior;
  102. end;
  103. end;
  104. begin
  105. if paramcount<>1 then
  106. begin
  107. Writeln ('Usage : testds tablename');
  108. Halt(1);
  109. end;
  110. Log ('Creating Dataset');
  111. Data:=TDDGDataset.Create(Nil);
  112. With Data do
  113. begin
  114. Log('Setting Tablename');
  115. TableName:=Paramstr(1);
  116. Log('Opening Dataset');
  117. Open;
  118. Log('Dumping fielddefs : ');
  119. Writeln ('Fielddefs count : ',FieldDefs.Count);
  120. For I:=0 to FieldDefs.Count-1 do
  121. DumpFieldDef(FieldDefs.Items[i]);
  122. Writeln ('Fields count : ',FieldCount);
  123. For I:=0 to FieldCount-1 do
  124. DumpField(Fields[i]);
  125. ScrollForward;
  126. ScrollBackWard;
  127. Writeln ('Doing append');
  128. writeln ('------------');
  129. Append;
  130. FieldByName('Name').AsString:='AppendName';
  131. FieldByName('Height').AsFloat:=9.99E9;
  132. FieldByName('LongField').AsLongInt:=999;
  133. FieldByName('ShoeSize').AsLongInt:=999;
  134. FieldByName('WordField').AsLongInt:=999;
  135. FieldByName('BooleanField').AsBoolean:=False;
  136. FieldByName('DateTimeField').AsDateTime:=Now;
  137. FieldByName('DateField').AsDateTime:=Date;
  138. FieldByName('TimeField').AsDateTime:=Time;
  139. Writeln ('End of append, going to post');
  140. Post;
  141. DumpFields(Data);
  142. Writeln ('Doing Last');
  143. Writeln ('----------');
  144. Last;
  145. DumpFields(Data);
  146. Writeln ('Doing Prior');
  147. Writeln ('----------');
  148. Prior;
  149. DumpFields(Data);
  150. Writeln ('Doing Insert at position 8');
  151. writeln ('--------------------------');
  152. first;
  153. for I:=1 to 7 do
  154. Next;
  155. Insert;
  156. FieldByName('Name').AsString:='Insertname';
  157. FieldByName('Height').AsFloat:=8.99E8;
  158. FieldByName('LongField').AsLongInt:=888;
  159. FieldByName('ShoeSize').AsLongInt:=888;
  160. FieldByName('WordField').AsLongInt:=888;
  161. FieldByName('BooleanField').AsBoolean:=True;
  162. FieldByName('DateTimeField').AsDateTime:=Now;
  163. FieldByName('DateField').AsDateTime:=Date;
  164. FieldByName('TimeField').AsDateTime:=Time;
  165. Post;
  166. Writeln ('Doing field dump');
  167. writeln ('----------------');
  168. DumpFields(Data);
  169. Writeln ('Doing Prior');
  170. Writeln ('-----------');
  171. Prior;
  172. DumpFields(Data);
  173. Writeln ('Doing Next');
  174. Writeln ('----------');
  175. Next;
  176. DumpFields(Data);
  177. Writeln ('Doing Next');
  178. Writeln ('----------');
  179. Next;
  180. DumpFields(Data);
  181. Writeln ('Doing Edit at position 5');
  182. writeln ('-------------------------');
  183. first;
  184. for I:=1 to 4 do
  185. Next;
  186. Edit;
  187. FieldByName('Name').AsString:='Editname';
  188. FieldByName('Height').AsFloat:=3.33E3;
  189. FieldByName('LongField').AsLongInt:=333;
  190. FieldByName('ShoeSize').AsLongInt:=333;
  191. FieldByName('WordField').AsLongInt:=333;
  192. FieldByName('BooleanField').AsBoolean:=False;
  193. FieldByName('DateTimeField').AsDateTime:=Now;
  194. FieldByName('DateField').AsDateTime:=Date;
  195. FieldByName('TimeField').AsDateTime:=Time;
  196. Post;
  197. Writeln ('Doing field dump');
  198. writeln ('----------------');
  199. DumpFields(Data);
  200. Writeln ('Doing Prior');
  201. Writeln ('-----------');
  202. Prior;
  203. DumpFields(Data);
  204. Writeln ('Doing Next');
  205. Writeln ('----------');
  206. Next;
  207. DumpFields(Data);
  208. Writeln ('Doing Next');
  209. Writeln ('----------');
  210. Next;
  211. DumpFields(Data);
  212. Writeln ('Closing.');
  213. Close;
  214. end;
  215. end.
  216. {
  217. $Log$
  218. Revision 1.2 2002-09-07 15:15:24 peter
  219. * old logs removed and tabs fixed
  220. }