[fpc-pascal] Proposed FPC database example code: request for testing
reinierolislagers at gmail.com
Fri May 25 10:17:01 CEST 2012
I've created a small SQL*Plus/isql/osql/sqlcmd clone, pasql.
It lets you connect to a database and run select queries as well as
queries that don't return a dataset.
It also shows how to use logging.
Perhaps it's a nice candidate for inclusion as an FPC example, but it's
only been tested/known to work on Firebird 2.5 server, MS SQL Server
2008 and Sybase ASE15.
I'd be interested in suggestions for improving the code (e.g. the ODBC
code probably needs work), bug reports with other databases (PostgreSQL,
>From the readme:
Pasql is a sample tool that lets you connect to an SQLDB supported
database and run SQL commands.
It logs your commands and can print them at the end of the session.
To run this, you need to have the relevant database client drivers/dlls
installed (e.g. in Windows, you can put them in the directory where
Run pasql -h for help.
This program demonstrates:
- handling command line parameters
- use of a general class (TSQLConnection) for one of several specialized
classes (TIBConnection, TMSSQLConnection,...) and use of the as keyword
to call specialized code.
- a trick to find out whether a TSQLQuery returns records or not
Support for more databases
Rewrite program so it is a bit more object oriented and variables are
limited/scoped (the program originated as a procedural program)
For embedded/file based databases: if hostname and database are both
empty (or database does not exist), create a database if user agrees
Better format of returned records; scrolling support
Pasql command mode next to the existing SQL mode: e.g. by typing ' at
the beginning of a line.
This could include setting up parametrized queries:
'PARAM SELECT NAME,SURNAME,SALARY FROM EMPLOYEES WHERE NAME=:FINDNAME;
'PARAM FINDNAME=Van Canneyt
==>Database returns e.g.: Michael Van Canneyt 58000
==>reads file name.txt into FINDNAME parameter
==>Database returns e.g.: Florian Klaempfl 60000
(single quote to exit command mode and forget parametrized query)
Command mode could also have output formatting commands like
'SET HEADER OFF
'SET HEADER ON
and metadata commands like:
'SHOW TABLE X =>can show e.g. columns, indexes, constraints
... look into e.g. SQLQuery.SetSchemaInfo for that
Some way to insert blobs - e.g. using command mode above with the @file
Intercept keypresses (e.g. Alt-1, Alt-2) and show help/enter command mode
Reinier Olislagers, April 2012
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 8981 bytes
Desc: not available
More information about the fpc-pascal