testib.pp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // $Id$
  2. // Test program for interbase.pp unit
  3. program testib;
  4. uses Interbase,SysUtils,db;
  5. {$linklib dl}
  6. {$linklib crypt}
  7. const
  8. dbpath = 'testdb.gdb';
  9. var
  10. DBS : TIBDatabase;
  11. DS : TIBDataset;
  12. x : integer;
  13. S : TSystemTime;
  14. begin
  15. DBS := TIBDatabase.Create(nil);
  16. DS := TIBDataset.Create(nil);
  17. DS.Database := DBS;
  18. DBS.DatabaseName := dbpath;
  19. DBS.UserName := 'SYSDBA';
  20. DBS.Password := 'masterkey';
  21. WriteLn('Clearing ''John Doe'' entry from table');
  22. DS.SQL.Add('delete from fpdev where username = ''John Doe''');
  23. DS.Open;
  24. DS.Close;
  25. DS.sql.clear;
  26. WriteLn('Inserting ''John Doe'' developer to fpdev table');
  27. DS.SQL.Add('insert into fpdev values (9,''John Doe'',''[email protected]'')');
  28. DS.Open;
  29. DS.Close;
  30. DS.sql.clear;
  31. WriteLn('Making list from fpdev table');
  32. DS.SQL.Add('select * from fpdev');
  33. DS.Open;
  34. while not DS.EOF do
  35. begin
  36. for x := 0 to DS.FieldCount - 2 do
  37. Write(DS.Fields[x].AsString,',');
  38. WriteLn(DS.Fields[DS.FieldCount-1].AsString);
  39. DS.Next;
  40. end;
  41. DS.Close;
  42. DS.SQL.Clear;
  43. DS.Free;
  44. WriteLn;
  45. WriteLn('Trying to perform test of datatypes interpretation...');
  46. WriteLn('Some problems with TDateTimeField, see source');
  47. DS := TIBDataset.Create(nil);
  48. DS.Database := DBS;
  49. DS.SQL.Add('select * from test');
  50. DS.Open;
  51. while not DS.EOF do
  52. begin
  53. { Warning - TDateTimeField.AsDateTime returns wrong values,
  54. but conversions in TIBDataset are OK! }
  55. for x := 0 to DS.FieldCount - 1 do
  56. if (DS.Fields[x].DataType = ftDateTime) then
  57. WriteLn(DS.Fields[x].FieldName, ' : "',
  58. FormatDateTime('DD.MM.YYYY HH:MM:SS',DS.Fields[x].AsDateTime),'"')
  59. else WriteLn(DS.Fields[x].FieldName, ' : "',DS.Fields[x].AsString,'"');
  60. DS.Next;
  61. end;
  62. DS.Free;
  63. DBS.EndTransaction;
  64. DBS.Close;
  65. DBS.Free;
  66. end.
  67. {
  68. $Log$
  69. Revision 1.1 2000-07-13 06:31:28 michael
  70. + Initial import
  71. Revision 1.2 2000/06/04 08:24:38 michael
  72. + Correct example committed
  73. Revision 1.1.1.1 2000/06/02 06:56:37 stingp1
  74. Initial release
  75. }