r1639: Initial revision
[clsql.git] / interfaces / postgresql / postgresql-uffi.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
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
10 ;;;;
11 ;;;; $Id: postgresql-uffi.cl,v 1.1 2002/03/23 14:04:53 kevin Exp $
12 ;;;;
13 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
15 ;;;;
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 ;;;; *************************************************************************
20
21 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
22 (in-package :postgresql)
23
24
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
31 ;;;; example.
32
33 ;;;; Type definitions
34
35 ;;; Basic Types
36
37 (uffi:def-foreign-type pgsql-oid :unsigned-int)
38
39 (uffi:def-enum pgsql-conn-status-type 
40     (:connection-ok
41      :connection-bad))
42
43 (uffi:def-enum pgsql-exec-status-type
44     (:empty-query
45      :command-ok
46      :tuples-ok
47      :copy-out
48      :copy-in
49      :bad-response
50      :nonfatal-error
51      :fatal-error))
52
53 (uffi:def-foreign-type pgsql-conn :pointer-void)
54 (uffi:def-foreign-type pgsql-result :pointer-void)
55
56 ;;(declaim (inline PQsetdbLogin)) ;; causes compile error in LW 4.2.0
57 (uffi:def-function ("PQsetdbLogin" PQsetdbLogin)
58   ((pghost :cstring)
59    (pgport :cstring)
60    (pgoptions :cstring)
61    (pgtty :cstring)
62    (dbName :cstring)
63    (login :cstring)
64    (pwd :cstring))
65   :returning pgsql-conn)
66
67 (declaim (inline PQfinish))
68 (uffi:def-function ("PQfinish" PQfinish)
69   ((conn pgsql-conn))
70   :module "postgresql"
71   :returning :void)
72
73 (declaim (inline PQstatus))
74 (uffi:def-function ("PQstatus" PQstatus)
75   ((conn pgsql-conn))
76   :module "postgresql"
77   :returning pgsql-conn-status-type)
78
79 (declaim (inline PQerrorMessage))
80 (uffi:def-function ("PQerrorMessage" PQerrorMessage)
81   ((conn pgsql-conn))
82   :module "postgresql"
83   :returning :cstring)
84
85 (declaim (inline PQexec))
86 (uffi:def-function ("PQexec" PQexec)
87   ((conn pgsql-conn)
88    (query :cstring))
89   :module "postgresql"
90   :returning pgsql-result)
91
92 (declaim (inline PQresultStatus))
93 (uffi:def-function ("PQresultStatus" PQresultStatus)
94   ((res pgsql-result))
95   :module "postgresql"
96   :returning pgsql-exec-status-type)
97
98 (declaim (inline PQresultErrorMessage))
99 (uffi:def-function ("PQresultErrorMessage" PQresultErrorMessage)
100   ((res pgsql-result))
101   :module "postgresql"
102   :returning :cstring)
103
104 (declaim (inline PQntuples))
105 (uffi:def-function ("PQntuples" PQntuples) 
106   ((res pgsql-result))
107   :module "postgresql"
108   :returning :int)
109
110 (declaim (inline PQnfields))
111 (uffi:def-function ("PQnfields" PQnfields)
112   ((res pgsql-result))
113   :module "postgresql"
114   :returning :int)
115
116 (declaim (inline PQfname))
117 (uffi:def-function ("PQfname" PQfname)
118   ((res pgsql-result)
119    (field-num :int))
120   :module "postgresql"
121   :returning :cstring)
122
123 (declaim (inline PQfnumber))
124 (uffi:def-function ("PQfnumber" PQfnumber)
125   ((res pgsql-result)
126   (field-name :cstring))
127   :module "postgresql"
128   :returning :int)
129
130 (declaim (inline PQftype))
131 (uffi:def-function ("PQftype" PQftype)
132   ((res pgsql-result)
133    (field-num :int))
134   :module "postgresql"
135   :returning pgsql-oid)
136
137 (declaim (inline PQfsize))
138 (uffi:def-function ("PQfsize" PQfsize)
139   ((res pgsql-result)
140    (field-num :int))
141   :module "postgresql"
142   :returning :short)
143
144 (declaim (inline PQcmdStatus))
145 (uffi:def-function ("PQcmdStatus" PQcmdStatus)
146   ((res pgsql-result))
147   :module "postgresql"
148   :returning :cstring)
149
150 (declaim (inline PQoidStatus))
151 (uffi:def-function ("PQoidStatus" PQoidStatus)
152   ((res pgsql-result))
153   :module "postgresql"
154   :returning :cstring)
155
156 (declaim (inline PQcmdTuples))
157 (uffi:def-function ("PQcmdTuples" PQcmdTuples)
158   ((res pgsql-result))
159   :module "postgresql"
160   :returning :cstring)
161
162 (declaim (inline PQgetvalue))
163 (uffi:def-function ("PQgetvalue" PQgetvalue)
164   ((res pgsql-result)
165    (tup-num :int)
166    (field-num :int))
167   :module "postgresql"
168   :returning :cstring)
169
170 (declaim (inline PQgetlength))
171 (uffi:def-function ("PQgetlength" PQgetlength)
172   ((res pgsql-result)
173    (tup-num :int)
174    (field-num :int))
175   :module "postgresql"
176   :returning :int)
177
178 (declaim (inline PQgetisnull))
179 (uffi:def-function ("PQgetisnull" PQgetisnull)
180   ((res pgsql-result)
181    (tup-num :int)
182    (field-num :int))
183   :module "postgresql"
184   :returning :int)
185
186 (declaim (inline PQclear))
187 (uffi:def-function ("PQclear" PQclear)
188   ((res pgsql-result))
189   :module "postgresql"
190   :returning :void)