mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 12:19:18 +02:00
- Changed for dyn.linking
- Made the query read-only
This commit is contained in:
parent
10b6189ecf
commit
fa3ce88bbd
@ -2,10 +2,6 @@ program testsqldb;
|
|||||||
|
|
||||||
{ A very simple example for sqldb, written by Joost van der Sluis (2004)
|
{ A very simple example for sqldb, written by Joost van der Sluis (2004)
|
||||||
|
|
||||||
Usage:
|
|
||||||
remove the defines for the databases whose clients aren't installed, or
|
|
||||||
the linking will fail.
|
|
||||||
|
|
||||||
The following parameters are used, in given order:
|
The following parameters are used, in given order:
|
||||||
|
|
||||||
parameter1 = databasetype (mysql,interbase,postgresql - case sensitive)
|
parameter1 = databasetype (mysql,interbase,postgresql - case sensitive)
|
||||||
@ -23,15 +19,11 @@ program testsqldb;
|
|||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
{$define pqconnection}
|
|
||||||
{$define MySQLConnection}
|
|
||||||
{$define IBConnection}
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes,
|
Classes,
|
||||||
{$ifdef pqconnection} pqconnection, {$endif}
|
pqconnection,
|
||||||
{$ifdef MySQLConnection} mysql4conn, {$endif}
|
mysql4conn,
|
||||||
{$ifdef IBConnection} IBConnection, {$endif}
|
IBConnection,
|
||||||
sqldb;
|
sqldb;
|
||||||
|
|
||||||
var connection : tSQLConnection;
|
var connection : tSQLConnection;
|
||||||
@ -42,15 +34,10 @@ var connection : tSQLConnection;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
dbtype := paramstr(1);
|
dbtype := paramstr(1);
|
||||||
{$ifdef MySQLConnection}
|
|
||||||
if dbtype = 'mysql' then connection := tMySQLConnection.Create(nil);
|
if dbtype = 'mysql' then connection := tMySQLConnection.Create(nil);
|
||||||
{$endif}
|
|
||||||
{$ifdef pqconnection}
|
|
||||||
if dbtype = 'postgresql' then connection := tpqConnection.Create(nil);
|
if dbtype = 'postgresql' then connection := tpqConnection.Create(nil);
|
||||||
{$endif}
|
|
||||||
{$ifdef IBConnection}
|
|
||||||
if dbtype = 'interbase' then connection := tIBConnection.Create(nil);
|
if dbtype = 'interbase' then connection := tIBConnection.Create(nil);
|
||||||
{$endif}
|
|
||||||
if not assigned(connection) then exit; // probably an invalid database type given
|
if not assigned(connection) then exit; // probably an invalid database type given
|
||||||
|
|
||||||
connection.DatabaseName := paramstr(2);
|
connection.DatabaseName := paramstr(2);
|
||||||
@ -68,6 +55,8 @@ begin
|
|||||||
begin
|
begin
|
||||||
SQL.clear;
|
SQL.clear;
|
||||||
sql.add('select * from ' + paramstr(3));
|
sql.add('select * from ' + paramstr(3));
|
||||||
|
ReadOnly := True; // If the query is writeable, a transaction must be assigned
|
||||||
|
// to the database.
|
||||||
open;
|
open;
|
||||||
|
|
||||||
while not eof do
|
while not eof do
|
||||||
|
Loading…
Reference in New Issue
Block a user