alisttables.pp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. (******************************************************************************
  2. * *
  3. * (c) 2005 CNOC v.o.f. *
  4. * *
  5. * File: aListTables.pp *
  6. * Author: Joost van der Sluis ([email protected]) *
  7. * Description: SQLDB example and test program *
  8. * License: GPL *
  9. * *
  10. ******************************************************************************)
  11. program aListTables;
  12. {$mode objfpc}{$H+}
  13. uses
  14. Classes,
  15. sqldb, pqconnection, mysql4conn, IBConnection,
  16. SqldbExampleUnit;
  17. var Tables : TStringList;
  18. i : integer;
  19. begin
  20. ReadIniFile;
  21. // create FConnection
  22. if dbtype = 'mysql' then Fconnection := tMySQLConnection.Create(nil);
  23. if dbtype = 'postgresql' then Fconnection := tpqConnection.Create(nil);
  24. if dbtype = 'interbase' then Fconnection := tIBConnection.Create(nil);
  25. if not assigned(Fconnection) then ExitWithError('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');
  26. with Fconnection do
  27. begin
  28. DatabaseName := dbname;
  29. UserName := dbuser;
  30. Password := dbpassword;
  31. open;
  32. end;
  33. // create FTransaction
  34. Ftransaction := tsqltransaction.create(nil);
  35. with Ftransaction do
  36. begin
  37. database := Fconnection;
  38. StartTransaction;
  39. end;
  40. Fconnection.Transaction := Ftransaction;
  41. Tables := TStringList.Create;
  42. Fconnection.GetTableNames(Tables);
  43. for i := 0 to Tables.Count -1 do writeln(Tables[i]);
  44. Tables.Free;
  45. Ftransaction.Free;
  46. Fconnection.Free;
  47. end.