mtest.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. {$mode objfpc}
  13. {$H+}
  14. program mtest;
  15. uses db,sysutils,mysqldb;
  16. Procedure Log(Const Msg : String);
  17. begin
  18. Writeln(Msg);
  19. end;
  20. Procedure DumpFieldDef(F : TfieldDef);
  21. begin
  22. With F do
  23. begin
  24. Writeln ('Name : ',Name);
  25. Writeln ('FieldNo : ',FieldNo);
  26. Writeln ('Size : ',Size);
  27. Writeln ('FieldClass : ',FieldClass.ClassName);
  28. Writeln ('Required : ',required);
  29. Writeln ('Precision : ',Precision);
  30. Writeln ('DataType : ',FieldTypeNames[DataType]);
  31. Writeln ('InternalCalcField : ',Internalcalcfield);
  32. end;
  33. end;
  34. Procedure DumpField(F : Tfield);
  35. begin
  36. With F do
  37. begin
  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. Dbase : TMySQLDatabase;
  67. Data : TMysqldataset;
  68. I,Count : longint;
  69. Bookie : TBookMarkStr;
  70. Procedure ScrollForward;
  71. begin
  72. Writeln ('Browsing Forward:');
  73. Writeln ('------------------');
  74. With Data do
  75. While NOT EOF do
  76. begin
  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<>4 then
  96. begin
  97. Writeln ('Usage : mtest db user pwd sql');
  98. Halt(1);
  99. end;
  100. Log ('Creating Database');
  101. DBase:=TMySQLDatabase.Create(Nil);
  102. Try
  103. With DBase do
  104. begin
  105. Log('Setting database');
  106. DatabaseName:=Paramstr(1);
  107. Log('Setting user');
  108. UserName:=Paramstr(2);
  109. Log('Setting password');
  110. PassWord := Paramstr(3);
  111. Log('Connecting');
  112. Connected:=True;
  113. end;
  114. Log ('Creating Dataset');
  115. Data:=TMysqlDataset.Create(Nil);
  116. With Data do
  117. Try
  118. Log('Setting database property');
  119. Database:=DBase;
  120. Log('Setting SQL');
  121. SQL.text := Paramstr(4);
  122. Log('Opening Dataset');
  123. Open;
  124. Log('Dumping fielddefs : ');
  125. Writeln ('Fielddefs count : ',FieldDefs.Count);
  126. For I:=0 to FieldDefs.Count-1 do
  127. DumpFieldDef(FieldDefs.Items[i]);
  128. Writeln ('Fields count : ',FieldCount);
  129. For I:=0 to FieldCount-1 do
  130. DumpField(Fields[i]);
  131. ScrollForward;
  132. ScrollBackWard;
  133. Writeln ('Going to last :');
  134. writeln ('---------------');
  135. Last;
  136. ScrollBackWard;
  137. ScrollForward;
  138. Writeln ('Going to first:');
  139. First;
  140. Count:=0;
  141. Writeln ('Browsing Forward:');
  142. Writeln ('------------------');
  143. With Data do
  144. While NOT EOF do
  145. begin
  146. Inc(Count);
  147. If Count=recordCount div 2 then
  148. begin
  149. Writeln ('Setting bookmark on record');
  150. Bookie:=Bookmark;
  151. Writeln ('Got data : "',Bookie,'"');
  152. end;
  153. For I:=0 to FieldCount-1 do
  154. DumpFieldData(Fields[I]);
  155. Next;
  156. end;
  157. Writeln ('Jumping to bookmark',Bookie);
  158. BookMark:=Bookie;
  159. Writeln ('Dumping Record : ');
  160. For I:=0 to FieldCount-1 do
  161. DumpFieldData(Fields[I]);
  162. Next;
  163. Writeln ('Dumping Next Record : ');
  164. For I:=0 to FieldCount-1 do
  165. DumpFieldData(Fields[I]);
  166. Prior;
  167. Prior;
  168. Writeln ('Dumping Previous Record : ');
  169. For I:=0 to FieldCount-1 do
  170. DumpFieldData(Fields[I]);
  171. Log('Closing Dataset');
  172. Close;
  173. Log('End.');
  174. Finally
  175. Free;
  176. end;
  177. Finally
  178. Writeln('Freeing database');
  179. DBase.free;
  180. end;
  181. end.
  182. {
  183. $Log$
  184. Revision 1.3 2003-08-16 16:42:21 michael
  185. + Fixes in TDBDataset etc. Changed MySQLDb to use database as well
  186. Revision 1.2 2002/09/07 15:15:23 peter
  187. * old logs removed and tabs fixed
  188. }