/packages/fcl-db/src/sqldb/examples/alisttables.pp

https://github.com/slibre/freepascal · Puppet · 64 lines · 52 code · 12 blank · 0 comment · 9 complexity · 15542ec793113ec51e2bf0bcb6bbac78 MD5 · raw file

  1. (******************************************************************************
  2. * *
  3. * (c) 2005 CNOC v.o.f. *
  4. * *
  5. * File: aListTables.pp *
  6. * Author: Joost van der Sluis (joost@cnoc.nl) *
  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, mysql40conn, mysql41conn, mysql50conn, IBConnection, ODBCConn,
  16. SqldbExampleUnit;
  17. var Tables : TStringList;
  18. i : integer;
  19. begin
  20. ReadIniFile;
  21. // create FConnection
  22. if dbtype = 'mysql40' then Fconnection := tMySQL40Connection.Create(nil);
  23. if dbtype = 'mysql41' then Fconnection := tMySQL41Connection.Create(nil);
  24. if dbtype = 'mysql50' then Fconnection := tMySQL50Connection.Create(nil);
  25. if dbtype = 'postgresql' then Fconnection := tpqConnection.Create(nil);
  26. if dbtype = 'interbase' then Fconnection := tIBConnection.Create(nil);
  27. if dbtype = 'odbc' then Fconnection := tODBCConnection.Create(nil);
  28. if not assigned(Fconnection) then ExitWithError('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');
  29. with Fconnection do
  30. begin
  31. if dbhost<>'' then
  32. hostname:=dbhost;
  33. DatabaseName := dbname;
  34. UserName := dbuser;
  35. Password := dbpassword;
  36. open;
  37. end;
  38. // create FTransaction
  39. Ftransaction := tsqltransaction.create(nil);
  40. with Ftransaction do
  41. begin
  42. database := Fconnection;
  43. StartTransaction;
  44. end;
  45. Fconnection.Transaction := Ftransaction;
  46. Tables := TStringList.Create;
  47. Fconnection.GetTableNames(Tables);
  48. for i := 0 to Tables.Count -1 do writeln(Tables[i]);
  49. Tables.Free;
  50. Ftransaction.Free;
  51. Fconnection.Free;
  52. end.