The postgres unit.
Free Pascal interface to PostGreSQL
OverviewYou can use Free Pascal to access a PostGreSQL database server from Linux. (for more info on PostGreSQL, see their home page.)
Interfacing is very easy, all you need to do is compile some units, and use these units in your program. You need to specify the place of the PostGreSQL client Library (libpq) when compiling, and that is it. the provided units take care of the rest.
The main unit is called postgres, normally this is the only unit you must include in your uses clause. (view interface)
RequirementsYou need at least version 0.99.5 of Free Pascal. The headers are translated from PostGreSQL version 6.3.1. Using an earlier version may not work.
InstallationThe prostgres unit comes with the Free Pascal packages, and is distributed together with the compiler. This contains a directory postgres with the units, a test program and a makefile. cd to the directory and edit the Makefile to set the variables for your system. You must provide only 1 thing:
- The directory where the libpq library resides, usually /usr/local/pgsql/lib
makeShould compile the units and the program. If compilation was succesfull, you can install with
make install(Remember to set the directory where the units should be installed.)
You can then test the program by running
make testThis will:
- Run the test program testpg. It is a straightforward pascal translation of the example program in the PostGreSQL programmers' guide.
- Run a script to create a table in a database, and fill it with some data. (the psql program should be in your PATH for this) . By default, the used database is testdb.
- Run the testprogram testemail
- Run a shell script again to remove the created table.
Future plansThe interface to PostGreSQL is a pure translation of the PostGreSQL C header files. This means that the used functions are rather un-pascalish. It would be great to have an OOP interface for it, A la Delphi. This interface is being worked on.
FinallyIf you have found a bug, or if you have made some functions to interface these units in a more pascal-like fashion, feel free to contact me at email@example.com
Back to packages page.