testib.pp 2.0 KB

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