testib.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. { $Id$
  2. Copyright (c) 2000 by Pavel Stingl
  3. Interbase testing program
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. program TestIB;
  11. {$ifdef unix}
  12. {$ifndef BSD} // BSD has libdl built in libc
  13. {$linklib dl}
  14. {$endif}
  15. {$linklib crypt}
  16. {$endif}
  17. uses Interbase, SysUtils;
  18. var
  19. Database : TIBDatabase;
  20. Trans : TIBTransaction;
  21. Query : TIBQuery;
  22. x : integer;
  23. begin
  24. Database := TIBDatabase.Create(nil);
  25. Trans := TIBTransaction.Create(nil);
  26. Query := TIBQuery.Create(nil);
  27. Database.DatabaseName := 'test.gdb';
  28. Database.UserName := 'sysdba';
  29. Database.Password := 'masterkey';
  30. Database.Transaction := Trans;
  31. Trans.Action := caRollback;
  32. Trans.Active := True;
  33. Write('Opening database... Database.Connected = ');
  34. Database.Open;
  35. WriteLn(Database.Connected);
  36. // Assigning database to dataset
  37. Query.Database := Database;
  38. Query.SQL.Add('select * from fpdev');
  39. Query.Open;
  40. WriteLn;
  41. while not Query.EOF do
  42. begin
  43. for x := 0 to Query.FieldCount - 2 do
  44. Write(Query.Fields[x].AsString,',');
  45. WriteLn(Query.Fields[Query.FieldCount - 1].AsString);
  46. Query.Next;
  47. end;
  48. WriteLn;
  49. try
  50. WriteLn('Trying to insert new record to table fpdev');
  51. Query.Close;
  52. Query.SQL.Clear;
  53. Query.SQL.Add('insert into fpdev values (''9'',''John Doe'',''[email protected]'')');
  54. Query.ExecSQL;
  55. Trans.CommitRetaining;
  56. WriteLn('Insert succeeded.');
  57. except
  58. on E:Exception do
  59. begin
  60. WriteLn(E.Message);
  61. WriteLn('Error when inserting record. Transaction rollback.');
  62. Trans.RollbackRetaining;
  63. end;
  64. end;
  65. WriteLn;
  66. Trans.Commit;
  67. Write('Closing database... Database.Connected = ');
  68. Database.Close;
  69. WriteLn(Database.Connected);
  70. end.
  71. {
  72. $Log$
  73. Revision 1.7 2005-02-14 17:13:12 peter
  74. * truncate log
  75. }