alisttables.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, ODBCConn,
  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 dbtype = 'odbc' then Fconnection := tODBCConnection.Create(nil);
  26. if not assigned(Fconnection) then ExitWithError('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');
  27. with Fconnection do
  28. begin
  29. DatabaseName := dbname;
  30. UserName := dbuser;
  31. Password := dbpassword;
  32. open;
  33. end;
  34. // create FTransaction
  35. Ftransaction := tsqltransaction.create(nil);
  36. with Ftransaction do
  37. begin
  38. database := Fconnection;
  39. StartTransaction;
  40. end;
  41. Fconnection.Transaction := Ftransaction;
  42. Tables := TStringList.Create;
  43. Fconnection.GetTableNames(Tables);
  44. for i := 0 to Tables.Count -1 do writeln(Tables[i]);
  45. Tables.Free;
  46. Ftransaction.Free;
  47. Fconnection.Free;
  48. end.