This package offers an “FFI”-based interface to PostgreSQL.
The package “SQL”
(nicknamed “POSTGRES”
and “POSTGRESQL”) is :CASE-SENSITIVE
,
so you would write (sql:PQconnectdb ...)
when you need to call PQconnectdb
.
When this module is present, *FEATURES*
contains the symbol :POSTGRESQL
.
See modules/postgresql/test.tst
for sample usage.
Additionally, some higher level functionality is available (defined
in modules/postgresql/sql.lisp
):
(sql:pq-finish
connection
)
PQfinish
the connection
and mark it as invalid(sql:pq-clear
result
)
PQclear
the result
and mark it as invalid(sql:sql-error connection
result
format-string
&REST
arguments
)
connection
and result
and SIGNAL
an
appropriate ERROR
(sql:sql-connect
&KEY
host port options tty name login password)
PQsetdbLogin
and
return the connection
(sql:with-sql-connection
(variable
&REST
option
s &KEY
log
&ALLOW-OTHER-KEYS
)
&BODY
body
)
bind *sql-log*
to the log
argument
call sql:sql-connect
on
option
s and bind variable
to the result
execute body
call sql:pq-finish
on
variable
(sql:sql-transaction connection
command
status
&OPTIONAL
(clear-p T
))
command
via connection
;
if the status does not match status
, ERROR
is SIGNAL
ed;
if clear-p
is
non-NIL
sql:pq-clear
the result
;
otherwise return it(sql:with-sql-transaction (result
connection
command
status) &BODY
body
)
body
on the result
of command
,
then sql:pq-clear
the result
sql:*sql-login*
login
argument to sql:sql-connect
(initially set to "postgres"
)
sql:*sql-password*
password
argument to sql:sql-connect
(initially set to "postgres"
)
sql:*sql-log*
NIL
, should be a STREAM
;
sql:sql-connect
and sql:sql-transaction
will write to it (initially set to NIL
)
Since PQfinish
and PQclear
cannot be called on the same pointer twice, one needs to track their
validity (sql:sql-connect
and sql:sql-transaction
take care of that).
See Example 32.11, “Controlling validity of resources”.
For PQtrace
, see
Section 33.1.13, “Standard file input and output”.
These notes document CLISP version 2.49 | Last modified: 2010-07-07 |