/packages/fcl-db/src/sqldb/examples/alisttables.pp
Puppet | 64 lines | 52 code | 12 blank | 0 comment | 9 complexity | 15542ec793113ec51e2bf0bcb6bbac78 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
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 12program aListTables; 13 14{$mode objfpc}{$H+} 15 16uses 17 Classes, 18 sqldb, pqconnection, mysql40conn, mysql41conn, mysql50conn, IBConnection, ODBCConn, 19 SqldbExampleUnit; 20 21var Tables : TStringList; 22 i : integer; 23 24begin 25 ReadIniFile; 26 27// create FConnection 28 if dbtype = 'mysql40' then Fconnection := tMySQL40Connection.Create(nil); 29 if dbtype = 'mysql41' then Fconnection := tMySQL41Connection.Create(nil); 30 if dbtype = 'mysql50' then Fconnection := tMySQL50Connection.Create(nil); 31 if dbtype = 'postgresql' then Fconnection := tpqConnection.Create(nil); 32 if dbtype = 'interbase' then Fconnection := tIBConnection.Create(nil); 33 if dbtype = 'odbc' then Fconnection := tODBCConnection.Create(nil); 34 35 if not assigned(Fconnection) then ExitWithError('Invalid database-type, check if a valid database-type was provided in the file ''database.ini'''); 36 37 with Fconnection do 38 begin 39 if dbhost<>'' then 40 hostname:=dbhost; 41 DatabaseName := dbname; 42 UserName := dbuser; 43 Password := dbpassword; 44 open; 45 end; 46 47// create FTransaction 48 Ftransaction := tsqltransaction.create(nil); 49 with Ftransaction do 50 begin 51 database := Fconnection; 52 StartTransaction; 53 end; 54 55 Fconnection.Transaction := Ftransaction; 56 57 Tables := TStringList.Create; 58 Fconnection.GetTableNames(Tables); 59 for i := 0 to Tables.Count -1 do writeln(Tables[i]); 60 61 Tables.Free; 62 Ftransaction.Free; 63 Fconnection.Free; 64end.