testds.pp 4.4 KB

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