alisttables.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, 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. DatabaseName := dbname;
  32. UserName := dbuser;
  33. Password := dbpassword;
  34. open;
  35. end;
  36. // create FTransaction
  37. Ftransaction := tsqltransaction.create(nil);
  38. with Ftransaction do
  39. begin
  40. database := Fconnection;
  41. StartTransaction;
  42. end;
  43. Fconnection.Transaction := Ftransaction;
  44. Tables := TStringList.Create;
  45. Fconnection.GetTableNames(Tables);
  46. for i := 0 to Tables.Count -1 do writeln(Tables[i]);
  47. Tables.Free;
  48. Ftransaction.Free;
  49. Fconnection.Free;
  50. end.