testib.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. {$linklib dl}
  12. {$linklib crypt}
  13. uses Interbase, SysUtils;
  14. var
  15. Database : TIBDatabase;
  16. Trans : TIBTransaction;
  17. Query : TIBQuery;
  18. x : integer;
  19. begin
  20. Database := TIBDatabase.Create(nil);
  21. Trans := TIBTransaction.Create(nil);
  22. Query := TIBQuery.Create(nil);
  23. Database.DatabaseName := 'test.gdb';
  24. Database.UserName := 'sysdba';
  25. Database.Password := 'masterkey';
  26. Database.Transaction := Trans;
  27. Trans.Action := caRollback;
  28. Trans.Active := True;
  29. Write('Opening database... Database.Connected = ');
  30. Database.Open;
  31. WriteLn(Database.Connected);
  32. // Assigning database to dataset
  33. Query.Database := Database;
  34. Query.SQL.Add('select * from fpdev');
  35. Query.Open;
  36. WriteLn;
  37. while not Query.EOF do
  38. begin
  39. for x := 0 to Query.FieldCount - 2 do
  40. Write(Query.Fields[x].AsString,',');
  41. WriteLn(Query.Fields[Query.FieldCount - 1].AsString);
  42. Query.Next;
  43. end;
  44. WriteLn;
  45. try
  46. WriteLn('Trying to insert new record to table fpdev');
  47. Query.Close;
  48. Query.SQL.Clear;
  49. Query.SQL.Add('insert into fpdev values (''9'',''John Doe'',''[email protected]'')');
  50. Query.ExecSQL;
  51. Trans.CommitRetaining;
  52. WriteLn('Insert succeeded.');
  53. except
  54. on E:Exception do
  55. begin
  56. WriteLn(E.Message);
  57. WriteLn('Error when inserting record. Transaction rollback.');
  58. Trans.RollbackRetaining;
  59. end;
  60. end;
  61. WriteLn;
  62. Trans.Commit;
  63. Write('Closing database... Database.Connected = ');
  64. Database.Close;
  65. WriteLn(Database.Connected);
  66. end.
  67. {
  68. $Log$
  69. Revision 1.4 2002-09-07 15:15:23 peter
  70. * old logs removed and tabs fixed
  71. }