alisttables.pp 2.0 KB

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