mtest.pp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. <What does this file>
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode objfpc}
  12. {$H+}
  13. program mtest;
  14. uses db,sysutils, mysqldb4; // change to mysqldb3 if you are using version 3.
  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 ('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. Dbase : TMySQLDatabase;
  66. Data : TMysqldataset;
  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. 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<>4 then
  95. begin
  96. Writeln ('Usage : mtest db user pwd sql');
  97. Halt(1);
  98. end;
  99. Log ('Creating Database');
  100. DBase:=TMySQLDatabase.Create(Nil);
  101. Try
  102. With DBase do
  103. begin
  104. Log('Setting database');
  105. DatabaseName:=Paramstr(1);
  106. Log('Setting user');
  107. UserName:=Paramstr(2);
  108. Log('Setting password');
  109. PassWord := Paramstr(3);
  110. Log('Connecting');
  111. Connected:=True;
  112. end;
  113. Log ('Creating Dataset');
  114. Data:=TMysqlDataset.Create(Nil);
  115. With Data do
  116. Try
  117. Log('Setting database property');
  118. Database:=DBase;
  119. Log('Setting SQL');
  120. SQL.text := Paramstr(4);
  121. Log('Opening Dataset');
  122. Open;
  123. Log('Dumping fielddefs : ');
  124. Writeln ('Fielddefs count : ',FieldDefs.Count);
  125. For I:=0 to FieldDefs.Count-1 do
  126. DumpFieldDef(FieldDefs.Items[i]);
  127. Writeln ('Fields count : ',FieldCount);
  128. For I:=0 to FieldCount-1 do
  129. DumpField(Fields[i]);
  130. ScrollForward;
  131. ScrollBackWard;
  132. Writeln ('Going to last :');
  133. writeln ('---------------');
  134. Last;
  135. ScrollBackWard;
  136. ScrollForward;
  137. Writeln ('Going to first:');
  138. First;
  139. Count:=0;
  140. Writeln ('Browsing Forward:');
  141. Writeln ('------------------');
  142. With Data do
  143. While NOT EOF do
  144. begin
  145. Inc(Count);
  146. If Count=recordCount div 2 then
  147. begin
  148. Writeln ('Setting bookmark on record');
  149. Bookie:=Bookmark;
  150. Writeln ('Got data : "',Bookie,'"');
  151. end;
  152. For I:=0 to FieldCount-1 do
  153. DumpFieldData(Fields[I]);
  154. Next;
  155. end;
  156. Writeln ('Jumping to bookmark',Bookie);
  157. BookMark:=Bookie;
  158. Writeln ('Dumping Record : ');
  159. For I:=0 to FieldCount-1 do
  160. DumpFieldData(Fields[I]);
  161. Next;
  162. Writeln ('Dumping Next Record : ');
  163. For I:=0 to FieldCount-1 do
  164. DumpFieldData(Fields[I]);
  165. Prior;
  166. Prior;
  167. Writeln ('Dumping Previous Record : ');
  168. For I:=0 to FieldCount-1 do
  169. DumpFieldData(Fields[I]);
  170. Log('Closing Dataset');
  171. Close;
  172. Log('End.');
  173. Finally
  174. Free;
  175. end;
  176. Finally
  177. Writeln('Freeing database');
  178. DBase.free;
  179. end;
  180. end.