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
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 (in-package #:postgresql)
24 ;;;; This file implements as little of the FFI bindings to the
25 ;;;; PostgreSQL client libraries as we could get away with.
26 ;;;; Especially all the PostgreSQL-specific goodies aren't there, and
27 ;;;; we just use void pointers where we can get away with it, which
28 ;;;; thanks to the design of the PostgreSQL client libraries is pretty
29 ;;;; much everywhere, in contrast to the MySQL client libraries for
36 (uffi:def-foreign-type pgsql-oid :unsigned-int)
38 (uffi:def-enum pgsql-conn-status-type
42 (uffi:def-enum pgsql-exec-status-type
52 (uffi:def-foreign-type pgsql-conn :pointer-void)
53 (uffi:def-foreign-type pgsql-result :pointer-void)
55 (uffi:def-type pgsql-conn-ptr :pointer-void)
57 (uffi:def-enum pgsql-ftype
65 ;;(declaim (inline PQsetdbLogin)) ;; causes compile error in LW 4.2.0
66 (uffi:def-function ("PQsetdbLogin" PQsetdbLogin)
74 :returning pgsql-conn)
76 (declaim (inline PQfinish))
77 (uffi:def-function ("PQfinish" PQfinish)
82 (declaim (inline PQstatus))
83 (uffi:def-function ("PQstatus" PQstatus)
86 :returning pgsql-conn-status-type)
88 (declaim (inline PQerrorMessage))
89 (uffi:def-function ("PQerrorMessage" PQerrorMessage)
94 (declaim (inline PQexec))
95 (uffi:def-function ("PQexec" PQexec)
99 :returning pgsql-result)
101 (declaim (inline PQresultStatus))
102 (uffi:def-function ("PQresultStatus" PQresultStatus)
105 :returning pgsql-exec-status-type)
107 (declaim (inline PQresultErrorMessage))
108 (uffi:def-function ("PQresultErrorMessage" PQresultErrorMessage)
113 (declaim (inline PQntuples))
114 (uffi:def-function ("PQntuples" PQntuples)
119 (declaim (inline PQnfields))
120 (uffi:def-function ("PQnfields" PQnfields)
125 (declaim (inline PQfname))
126 (uffi:def-function ("PQfname" PQfname)
132 (declaim (inline PQfnumber))
133 (uffi:def-function ("PQfnumber" PQfnumber)
135 (field-name :cstring))
139 (declaim (inline PQftype))
140 (uffi:def-function ("PQftype" PQftype)
144 :returning pgsql-oid)
146 (declaim (inline PQfsize))
147 (uffi:def-function ("PQfsize" PQfsize)
153 (declaim (inline PQcmdStatus))
154 (uffi:def-function ("PQcmdStatus" PQcmdStatus)
159 (declaim (inline PQoidStatus))
160 (uffi:def-function ("PQoidStatus" PQoidStatus)
165 (declaim (inline PQcmdTuples))
166 (uffi:def-function ("PQcmdTuples" PQcmdTuples)
171 (declaim (inline PQgetvalue))
172 (uffi:def-function ("PQgetvalue" PQgetvalue)
177 :returning (* :unsigned-char))
179 (declaim (inline PQgetlength))
180 (uffi:def-function ("PQgetlength" PQgetlength)
187 (declaim (inline PQgetisnull))
188 (uffi:def-function ("PQgetisnull" PQgetisnull)
195 (declaim (inline PQclear))
196 (uffi:def-function ("PQclear" PQclear)
201 (declaim (inline PQisBusy))
202 (uffi:def-function ("PQisBusy" PQisBusy)
208 ;;; Large objects support (MB)
210 (defconstant +INV_ARCHIVE+ 65536) ; fe-lobj.c
211 (defconstant +INV_WRITE+ 131072)
212 (defconstant +INV_READ+ 262144)
214 (declaim (inline lo-creat))
215 (uffi:def-function ("lo_creat" lo-create)
219 :returning pgsql-oid)
221 (declaim (inline lo-open))
222 (uffi:def-function ("lo_open" lo-open)
229 (declaim (inline lo-write))
230 (uffi:def-function ("lo_write" lo-write)
238 (declaim (inline lo-read))
239 (uffi:def-function ("lo_read" lo-read)
242 (data (* :unsigned-char))
247 (declaim (inline lo-lseek))
248 (uffi:def-function ("lo_lseek" lo-lseek)
256 (declaim (inline lo-close))
257 (uffi:def-function ("lo_close" lo-close)
263 (declaim (inline lo-unlink))
264 (uffi:def-function ("lo_unlink" lo-unlink)