1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: postgresql.cl
6 ;;;; Purpose: Low-level PostgreSQL interface using UFFI
7 ;;;; Programmers: Kevin M. Rosenberg based on
8 ;;;; Original code by Pierre R. Mai
9 ;;;; Date Started: Feb 2002
11 ;;;; $Id: postgresql-api.cl,v 1.3 2002/03/25 14:13:41 kevin Exp $
13 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
16 ;;;; CLSQL users are granted the rights to distribute and use this software
17 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
18 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
19 ;;;; *************************************************************************
21 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
22 (in-package :postgresql)
25 ;;;; This file implements as little of the FFI bindings to the
26 ;;;; PostgreSQL client libraries as we could get away with.
27 ;;;; Especially all the PostgreSQL-specific goodies aren't there, and
28 ;;;; we just use void pointers where we can get away with it, which
29 ;;;; thanks to the design of the PostgreSQL client libraries is pretty
30 ;;;; much everywhere, in contrast to the MySQL client libraries for
37 (uffi:def-foreign-type pgsql-oid :unsigned-int)
39 (uffi:def-enum pgsql-conn-status-type
43 (uffi:def-enum pgsql-exec-status-type
53 (uffi:def-foreign-type pgsql-conn :pointer-void)
54 (uffi:def-foreign-type pgsql-result :pointer-void)
56 (uffi:def-enum pgsql-ftype
64 ;;(declaim (inline PQsetdbLogin)) ;; causes compile error in LW 4.2.0
65 (uffi:def-function ("PQsetdbLogin" PQsetdbLogin)
73 :returning pgsql-conn)
75 (declaim (inline PQfinish))
76 (uffi:def-function ("PQfinish" PQfinish)
81 (declaim (inline PQstatus))
82 (uffi:def-function ("PQstatus" PQstatus)
85 :returning pgsql-conn-status-type)
87 (declaim (inline PQerrorMessage))
88 (uffi:def-function ("PQerrorMessage" PQerrorMessage)
93 (declaim (inline PQexec))
94 (uffi:def-function ("PQexec" PQexec)
98 :returning pgsql-result)
100 (declaim (inline PQresultStatus))
101 (uffi:def-function ("PQresultStatus" PQresultStatus)
104 :returning pgsql-exec-status-type)
106 (declaim (inline PQresultErrorMessage))
107 (uffi:def-function ("PQresultErrorMessage" PQresultErrorMessage)
112 (declaim (inline PQntuples))
113 (uffi:def-function ("PQntuples" PQntuples)
118 (declaim (inline PQnfields))
119 (uffi:def-function ("PQnfields" PQnfields)
124 (declaim (inline PQfname))
125 (uffi:def-function ("PQfname" PQfname)
131 (declaim (inline PQfnumber))
132 (uffi:def-function ("PQfnumber" PQfnumber)
134 (field-name :cstring))
138 (declaim (inline PQftype))
139 (uffi:def-function ("PQftype" PQftype)
143 :returning pgsql-oid)
145 (declaim (inline PQfsize))
146 (uffi:def-function ("PQfsize" PQfsize)
152 (declaim (inline PQcmdStatus))
153 (uffi:def-function ("PQcmdStatus" PQcmdStatus)
158 (declaim (inline PQoidStatus))
159 (uffi:def-function ("PQoidStatus" PQoidStatus)
164 (declaim (inline PQcmdTuples))
165 (uffi:def-function ("PQcmdTuples" PQcmdTuples)
170 (declaim (inline PQgetvalue))
171 (uffi:def-function ("PQgetvalue" PQgetvalue)
176 :returning (* :unsigned-char))
178 (declaim (inline PQgetlength))
179 (uffi:def-function ("PQgetlength" PQgetlength)
186 (declaim (inline PQgetisnull))
187 (uffi:def-function ("PQgetisnull" PQgetisnull)
194 (declaim (inline PQclear))
195 (uffi:def-function ("PQclear" PQclear)