summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-db/src/sqldb/examples/alisttables.pp
blob: 63930750c79bc2ec5199ed122abdb4f07f10386e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(******************************************************************************
 *                                                                            *
 *  (c) 2005 CNOC v.o.f.                                                      *
 *                                                                            *
 *  File:        aListTables.pp                                               *
 *  Author:      Joost van der Sluis (joost@cnoc.nl)                          *
 *  Description: SQLDB example and test program                               *
 *  License:     GPL                                                          *
 *                                                                            *
 ******************************************************************************)

program aListTables;

{$mode objfpc}{$H+}

uses
  Classes,
  sqldb, pqconnection, mysql40conn, mysql41conn, mysql50conn, IBConnection, ODBCConn,
  SqldbExampleUnit;

var Tables : TStringList;
    i      : integer;

begin
  ReadIniFile;

// create FConnection
  if dbtype = 'mysql40' then Fconnection := tMySQL40Connection.Create(nil);
  if dbtype = 'mysql41' then Fconnection := tMySQL41Connection.Create(nil);
  if dbtype = 'mysql50' then Fconnection := tMySQL50Connection.Create(nil);
  if dbtype = 'postgresql' then Fconnection := tpqConnection.Create(nil);
  if dbtype = 'interbase' then Fconnection := tIBConnection.Create(nil);
  if dbtype = 'odbc' then Fconnection := tODBCConnection.Create(nil);

  if not assigned(Fconnection) then ExitWithError('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');

  with Fconnection do
    begin
      if dbhost<>'' then
        hostname:=dbhost;
      DatabaseName := dbname;
      UserName := dbuser;
      Password := dbpassword;
      open;
    end;

// create FTransaction
  Ftransaction := tsqltransaction.create(nil);
  with Ftransaction do
    begin
    database := Fconnection;
    StartTransaction;
    end;

  Fconnection.Transaction := Ftransaction;

  Tables := TStringList.Create;
  Fconnection.GetTableNames(Tables);
  for i := 0 to Tables.Count -1 do writeln(Tables[i]);

  Tables.Free;
  Ftransaction.Free;
  Fconnection.Free;
end.