Interface to the PostgreSQL Database Server from GNU Prolog

Copyright (C) 1999-2003 by  Alexander Diemand

PREDICATES
==========

pl_pgsql_connect/6 (+host,+port,+user,+password,+dbname,-connection)
    connect to the server on host as user with password, returns the 
    connection id, which must be used in further request.

pl_pgsql_disconnect/1 (+connection)
    disconnect and **free** allocated memory

pl_pgsql_query/2 (+connection,+query)
    sends the query to the server. There is no result.
    Used for insert/update/delete.

pl_pgsql_query/3 (+connection,+query,-result)
    sends the query to the server. This predicate is backtrackable and succeeds
    for every row in the result set of the query.


EXAMPLES
========
1) something that works:

| ?- pl_pgsql_connect("localhost",5432,"john,"my_password","the_db",DBx),
     pl_pgsql_query(DBx,"select nr,name,city from addresses",Result),
     format("~d: ~s lives in ~s~n",Result),
     fail,  % to backtrack over next row in Result
     pl_pgsql_disconnect(DBx).  % we never get here  :-(

2) better: we should always succeed a query to disconnect from the db at the end

  run_query(DBx) :-
     pl_pgsql_query(DBx,"select nr,name,city from addresses",Result),
     format("~d: ~s lives in ~s~n",Result),
     fail,  % to backtrack over next row in Result

  run_query(_).  % always succeed
	

| ?- pl_pgsql_connect("localhost",5432,"john,"my_password","the_db",DBx),
     run_query(DBx),
     pl_pgsql_disconnect(DBx).




HOW TO COMPILE
==============

type "make". ( ... )



COMMENTS
========
Arguments that are strings are passed as character code lists. Same for strings in the result. Have a look at the code if you want to change this behaviour and have atoms returned for strings.

On the mips/IRIX there were quite a few problems with gprolog tagged integers. As I pass the pl_pgsql_?? routines the address of the connection structure in C and this address has the 29th bit set the value is a negative number after tagging (left shift of 3 bits). By Un_Tagging this number, the processor thinks it should still be a negative number after right shifting of 3 bits. Hence that does not work. I did something very bad: the address is divided by two (because it is aligned on some even byte boundery in any case) and then passed to gprolog. That helps but is not quite nice.


LICENSE
=======

Unde Lesser GNU General Public License (see file COPYING)

(also: http://www.gnu.org or http://www.fsf.org)


