postgres

From Free Pascal wiki
Revision as of 14:53, 16 February 2009 by Marcov (talk | contribs) (New page: == Overview - interface to PostGreSQL == You can use Free Pascal to access a PostGreSQL database server from Linux. (for more info on PostGreSQL, see their home page.) Interfacing is ve...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Overview - interface to PostGreSQL

You 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.

Requirements

You 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. Installation The 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:

  1. The directory where the libpq library resides, usually /usr/local/pgsql/lib

Typing

make

Should 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 test

This 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.

You will see a lot of messages on your screen, giving you feedback and results. If something went wrong, make will inform you of this. Future plans The 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.

Go to back Packages List