mtest.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. <What does this file>
  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 mtest;
  13. uses db,sysutils,mysqldb;
  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 ('FieldName : ',FieldName);
  37. Writeln ('FieldNo : ',FieldNo);
  38. Writeln ('Index : ',Index);
  39. Writeln ('DataSize : ',DataSize);
  40. Writeln ('Size : ',Size);
  41. Writeln ('DataType : ',FieldTypeNames[DataType]);
  42. Writeln ('Class : ',ClassName);
  43. Writeln ('Required : ',required);
  44. Writeln ('ReadOnly : ',ReadOnly);
  45. Writeln ('Visible : ',Visible);
  46. end;
  47. end;
  48. Procedure DumpFieldData (F : TField);
  49. begin
  50. With F Do
  51. begin
  52. Writeln ('Field : ',FieldName);
  53. Writeln ('Data type : ',FieldTypeNames[DataType]);
  54. Writeln ('As String : ',Asstring);
  55. Case Datatype of
  56. ftSmallint, ftInteger, ftWord : Writeln ('As longint : ',AsLongint);
  57. ftBoolean : Writeln ('As Boolean : ',AsBoolean);
  58. ftFloat : Writeln ('As Float : ',AsFloat);
  59. ftDate, ftTime, ftDateTime : Writeln ('As DateTime : ',DateTimeToStr(AsDateTime));
  60. end;
  61. end;
  62. end;
  63. Var
  64. Data : TMysqldataset;
  65. I,Count : longint;
  66. Bookie : TBookMarkStr;
  67. Procedure ScrollForward;
  68. begin
  69. Writeln ('Browsing Forward:');
  70. Writeln ('------------------');
  71. With Data do
  72. While NOT EOF do
  73. begin
  74. For I:=0 to FieldCount-1 do
  75. DumpFieldData(Fields[I]);
  76. Next;
  77. end;
  78. end;
  79. Procedure ScrollBackWard;
  80. begin
  81. Writeln ('Browsing Backward:');
  82. Writeln ('-------------------');
  83. With Data do
  84. While NOT BOF do
  85. begin
  86. For I:=0 to FieldCount-1 do
  87. DumpFieldData(Fields[I]);
  88. Prior;
  89. end;
  90. end;
  91. begin
  92. if paramcount<>4 then
  93. begin
  94. Writeln ('Usage : mtest db user pwd sql');
  95. Halt(1);
  96. end;
  97. Log ('Creating Dataset');
  98. Data:=TMysqlDataset.Create(Nil);
  99. With Data do
  100. begin
  101. Log('Setting database');
  102. Database:=Paramstr(1);
  103. Log('Setting user');
  104. User:=Paramstr(2);
  105. Log('Setting password');
  106. PassWord := Paramstr(3);
  107. Log('Setting SQL');
  108. SQL.text := Paramstr(4);
  109. Log('Opening Dataset');
  110. Open;
  111. Log('Dumping fielddefs : ');
  112. Writeln ('Fielddefs count : ',FieldDefs.Count);
  113. For I:=0 to FieldDefs.Count-1 do
  114. DumpFieldDef(FieldDefs.Items[i]);
  115. Writeln ('Fields count : ',FieldCount);
  116. For I:=0 to FieldCount-1 do
  117. DumpField(Fields[i]);
  118. ScrollForward;
  119. ScrollBackWard;
  120. Writeln ('Going to last :');
  121. writeln ('---------------');
  122. Last;
  123. ScrollBackWard;
  124. ScrollForward;
  125. Writeln ('Going to first:');
  126. First;
  127. Count:=0;
  128. Writeln ('Browsing Forward:');
  129. Writeln ('------------------');
  130. With Data do
  131. While NOT EOF do
  132. begin
  133. Inc(Count);
  134. If Count=recordCount div 2 then
  135. begin
  136. Writeln ('Setting bookmark on record');
  137. Bookie:=Bookmark;
  138. Writeln ('Got data : "',Bookie,'"');
  139. end;
  140. For I:=0 to FieldCount-1 do
  141. DumpFieldData(Fields[I]);
  142. Next;
  143. end;
  144. Writeln ('Jumping to bookmark',Bookie);
  145. BookMark:=Bookie;
  146. Writeln ('Dumping Record : ');
  147. For I:=0 to FieldCount-1 do
  148. DumpFieldData(Fields[I]);
  149. Next;
  150. Writeln ('Dumping Next Record : ');
  151. For I:=0 to FieldCount-1 do
  152. DumpFieldData(Fields[I]);
  153. Prior;
  154. Prior;
  155. Writeln ('Dumping Previous Record : ');
  156. For I:=0 to FieldCount-1 do
  157. DumpFieldData(Fields[I]);
  158. Log('Closing Dataset');
  159. Close;
  160. Log('End.');
  161. Free;
  162. end;
  163. end.
  164. {
  165. $Log$
  166. Revision 1.2 2002-09-07 15:15:23 peter
  167. * old logs removed and tabs fixed
  168. }