]> gitweb.factorcode.org Git - factor.git/blob - libs/sql/postgresql/libpq.factor
more sql changes
[factor.git] / libs / sql / postgresql / libpq.factor
1 ! See http://factor.sf.net/license.txt for BSD license.
2
3 ! adapted from libpq-fe.h version 7.4.7
4 ! tested on debian linux with postgresql 7.4.7
5 ! Updated to 8.1
6
7 IN: postgresql
8 USING: alien ;
9
10
11 ! ConnSatusType
12 : CONNECTION_OK                                         HEX: 0 ; inline
13 : CONNECTION_BAD                                        HEX: 1 ; inline
14 : CONNECTION_STARTED                            HEX: 2 ; inline
15 : CONNECTION_MADE                                       HEX: 3 ; inline
16 : CONNECTION_AWAITING_RESPONSE          HEX: 4 ; inline
17 : CONNECTION_AUTH_OK                            HEX: 5 ; inline
18 : CONNECTION_SETENV                                     HEX: 6 ; inline
19 : CONNECTION_SSL_STARTUP                        HEX: 7 ; inline
20 : CONNECTION_NEEDED                                     HEX: 8 ; inline
21
22 ! PostgresPollingStatusType
23 : PGRES_POLLING_FAILED                          HEX: 0 ; inline
24 : PGRES_POLLING_READING                         HEX: 1 ; inline
25 : PGRES_POLLING_WRITING                         HEX: 2 ; inline
26 : PGRES_POLLING_OK                                      HEX: 3 ; inline
27 : PGRES_POLLING_ACTIVE                          HEX: 4 ; inline
28
29 ! ExecStatusType;
30 : PGRES_EMPTY_QUERY                             HEX: 0 ; inline
31 : PGRES_COMMAND_OK                                      HEX: 1 ; inline
32 : PGRES_TUPLES_OK                                       HEX: 2 ; inline
33 : PGRES_COPY_OUT                                        HEX: 3 ; inline
34 : PGRES_COPY_IN                                         HEX: 4 ; inline
35 : PGRES_BAD_RESPONSE                            HEX: 5 ; inline
36 : PGRES_NONFATAL_ERROR                          HEX: 6 ; inline
37 : PGRES_FATAL_ERROR                                     HEX: 7 ; inline
38
39 ! PGTransactionStatusType;
40 : PQTRANS_IDLE                                          HEX: 0 ; inline
41 : PQTRANS_ACTIVE                                        HEX: 1 ; inline
42 : PQTRANS_INTRANS                                       HEX: 2 ; inline
43 : PQTRANS_INERROR                                       HEX: 3 ; inline
44 : PQTRANS_UNKNOWN                                       HEX: 4 ; inline
45
46 ! PGVerbosity;
47 : PQERRORS_TERSE                                        HEX: 0 ; inline
48 : PQERRORS_DEFAULT                                      HEX: 1 ; inline
49 : PQERRORS_VERBOSE                                      HEX: 2 ; inline
50
51
52 TYPEDEF: int size_t
53 TYPEDEF: int ConnStatusType
54 TYPEDEF: int ExecStatusType 
55 TYPEDEF: int PostgresPollingStatusType
56 TYPEDEF: int PGTransactionStatusType 
57 TYPEDEF: int PGVerbosity 
58
59 TYPEDEF: void* PGconn*
60 TYPEDEF: void* PGresult*
61 TYPEDEF: void* PGcancel*
62 TYPEDEF: uint Oid
63 TYPEDEF: uint* Oid*
64 TYPEDEF: char pqbool
65 TYPEDEF: void* PQconninfoOption*
66 TYPEDEF: void* PGnotify*
67 TYPEDEF: void* PQArgBlock*
68 TYPEDEF: void* PQprintOpt*
69 TYPEDEF: void* FILE*
70 TYPEDEF: void* SSL*
71
72 LIBRARY: postgresql
73
74
75 ! Exported functions of libpq
76 ! ===   in fe-connect.c ===
77
78 ! make a new client connection to the backend
79 ! Asynchronous (non-blocking)
80 FUNCTION: PGconn* PQconnectStart ( char* conninfo ) ;
81 FUNCTION: PostgresPollingStatusType PQconnectPoll ( PGconn* conn ) ;
82
83 ! Synchronous (blocking)
84 FUNCTION: PGconn* PQconnectdb ( char* conninfo ) ;
85 FUNCTION: PGconn* PQsetdbLogin ( char* pghost, char* pgport,
86                          char* pgoptions, char* pgtty,
87                          char* dbName,
88                          char* login, char* pwd ) ;
89
90 : PQsetdb ( M_PGHOST M_PGPORT M_PGOPT M_PGTTY M_DBNAME -- PGconn* )
91         f f PQsetdbLogin ;
92
93 ! close the current connection and free the PGconn data structure
94 FUNCTION: void PQfinish ( PGconn* conn ) ;
95
96 ! get info about connection options known to PQconnectdb
97 FUNCTION: PQconninfoOption* PQconndefaults ( ) ;
98
99 ! free the data structure returned by PQconndefaults()
100 FUNCTION: void PQconninfoFree ( PQconninfoOption* connOptions ) ;
101
102
103 ! close the current connection and restablish a new one with the same
104 ! parameters
105 !
106 ! Asynchronous (non-blocking)
107 FUNCTION: int   PQresetStart ( PGconn* conn ) ;
108 FUNCTION: PostgresPollingStatusType PQresetPoll ( PGconn* conn ) ;
109
110 ! Synchronous (blocking)
111 FUNCTION: void PQreset ( PGconn* conn ) ;
112
113 ! request a cancel structure
114 FUNCTION: PGcancel* PQgetCancel ( PGconn* conn ) ;
115
116 ! free a cancel structure
117 FUNCTION: void PQfreeCancel ( PGcancel* cancel ) ;
118
119 ! issue a cancel request
120 FUNCTION: int   PQrequestCancel ( PGconn* conn ) ;
121
122 ! Accessor functions for PGconn objects
123 FUNCTION: char* PQdb ( PGconn* conn ) ;
124 FUNCTION: char* PQuser ( PGconn* conn ) ;
125 FUNCTION: char* PQpass ( PGconn* conn ) ;
126 FUNCTION: char* PQhost ( PGconn* conn ) ;
127 FUNCTION: char* PQport ( PGconn* conn ) ;
128 FUNCTION: char* PQtty ( PGconn* conn ) ;
129 FUNCTION: char* PQoptions ( PGconn* conn ) ;
130 FUNCTION: ConnStatusType PQstatus ( PGconn* conn ) ;
131 FUNCTION: PGTransactionStatusType PQtransactionStatus ( PGconn* conn ) ;
132 FUNCTION: char* PQparameterStatus ( PGconn* conn,
133                                   char* paramName ) ;
134 FUNCTION: int   PQprotocolVersion ( PGconn* conn ) ;
135 FUNCTION: int   PQServerVersion ( PGconn* conn ) ;
136 FUNCTION: char* PQerrorMessage ( PGconn* conn ) ;
137 FUNCTION: int   PQsocket ( PGconn* conn ) ;
138 FUNCTION: int   PQbackendPID ( PGconn* conn ) ;
139 FUNCTION: int   PQclientEncoding ( PGconn* conn ) ;
140 FUNCTION: int   PQsetClientEncoding ( PGconn* conn, char* encoding ) ;
141
142 ! May not be compiled into libpq
143 ! Get the SSL structure associated with a connection
144 FUNCTION: SSL* PQgetssl ( PGconn* conn ) ;
145
146 ! Tell libpq whether it needs to initialize OpenSSL
147 FUNCTION: void PQinitSSL ( int do_init ) ;
148
149 ! Set verbosity for PQerrorMessage and PQresultErrorMessage
150 FUNCTION: PGVerbosity PQsetErrorVerbosity ( PGconn* conn,
151         PGVerbosity verbosity ) ;
152
153 ! Enable/disable tracing
154 FUNCTION: void PQtrace ( PGconn* conn, FILE* debug_port ) ;
155 FUNCTION: void PQuntrace ( PGconn* conn ) ;
156
157 ! BROKEN
158 ! Function types for notice-handling callbacks
159 ! typedef void (*PQnoticeReceiver) (void *arg, PGresult *res);
160 ! typedef void (*PQnoticeProcessor) (void *arg, char* message);
161 ! ALIAS: void* PQnoticeReceiver
162 ! ALIAS: void* PQnoticeProcessor
163
164 ! Override default notice handling routines
165 ! FUNCTION: PQnoticeReceiver PQsetNoticeReceiver ( PGconn* conn,
166                                         ! PQnoticeReceiver proc,
167                                         ! void* arg ) ;
168 ! FUNCTION: PQnoticeProcessor PQsetNoticeProcessor ( PGconn* conn,
169                                         ! PQnoticeProcessor proc,
170                                         ! void* arg ) ;
171 ! END BROKEN
172
173 ! === in fe-exec.c ===
174
175 ! Simple synchronous query
176 FUNCTION: PGresult* PQexec ( PGconn* conn, char* query ) ;
177 FUNCTION: PGresult* PQexecParams ( PGconn* conn,
178                          char* command,
179                          int nParams,
180                          Oid* paramTypes,
181                          char** paramValues,
182                          int* paramLengths,
183                          int* paramFormats,
184                          int resultFormat ) ;
185 FUNCTION: PGresult* PQprepare ( PGconn* conn, char* stmtName,
186         char* query, int nParams,
187         Oid* paramTypes ) ;
188 FUNCTION: PGresult* PQexecPrepared ( PGconn* conn,
189                          char* stmtName,
190                          int nParams,
191                          char** paramValues,
192                          int* paramLengths,
193                          int* paramFormats,
194                          int resultFormat ) ;
195
196 ! Interface for multiple-result or asynchronous queries
197 FUNCTION: int PQsendQuery ( PGconn* conn, char* query ) ;
198 FUNCTION: int PQsendQueryParams ( PGconn* conn,
199                                   char* command,
200                                   int nParams,
201                                   Oid* paramTypes,
202                                   char** paramValues,
203                                   int* paramLengths,
204                                   int* paramFormats,
205                                   int resultFormat ) ;
206 FUNCTION: PGresult* PQsendPrepare ( PGconn* conn, char* stmtName,
207             char* query, int nParams,
208             Oid* paramTypes ) ;
209 FUNCTION: int PQsendQueryPrepared ( PGconn* conn,
210                                   char* stmtName,
211                                   int nParams,
212                                   char** paramValues,
213                                   int *paramLengths,
214                                   int *paramFormats,
215                                   int resultFormat ) ;
216 FUNCTION: PGresult* PQgetResult ( PGconn* conn ) ;
217
218 ! Routines for managing an asynchronous query
219 FUNCTION: int   PQisBusy ( PGconn* conn ) ;
220 FUNCTION: int   PQconsumeInput ( PGconn* conn ) ;
221
222 ! LISTEN/NOTIFY support
223 FUNCTION: PGnotify* PQnotifies ( PGconn* conn ) ;
224
225 ! Routines for copy in/out
226 FUNCTION: int   PQputCopyData ( PGconn* conn, char* buffer, int nbytes ) ;
227 FUNCTION: int   PQputCopyEnd ( PGconn* conn, char* errormsg ) ;
228 FUNCTION: int   PQgetCopyData ( PGconn* conn, char** buffer, int async ) ;
229
230 ! Deprecated routines for copy in/out
231 FUNCTION: int   PQgetline ( PGconn* conn, char* string, int length ) ;
232 FUNCTION: int   PQputline ( PGconn* conn, char* string ) ;
233 FUNCTION: int   PQgetlineAsync ( PGconn* conn, char* buffer, int bufsize ) ;
234 FUNCTION: int   PQputnbytes ( PGconn* conn, char* buffer, int nbytes ) ;
235 FUNCTION: int   PQendcopy ( PGconn* conn ) ;
236
237 ! Set blocking/nonblocking connection to the backend
238 FUNCTION: int   PQsetnonblocking ( PGconn* conn, int arg ) ;
239 FUNCTION: int   PQisnonblocking ( PGconn* conn ) ;
240
241 ! Force the write buffer to be written (or at least try)
242 FUNCTION: int   PQflush ( PGconn* conn ) ;
243
244
245 ! * "Fast path" interface --- not really recommended for application
246 ! * use
247 !
248 FUNCTION: PGresult* PQfn ( PGconn* conn,
249          int fnid,
250          int* result_buf,
251          int* result_len,
252          int result_is_int,
253          PQArgBlock* args,
254          int nargs ) ;
255
256 ! Accessor functions for PGresult objects
257 FUNCTION: ExecStatusType PQresultStatus ( PGresult* res ) ;
258 FUNCTION: char* PQresStatus ( ExecStatusType status ) ;
259 FUNCTION: char* PQresultErrorMessage ( PGresult* res ) ;
260 FUNCTION: char* PQresultErrorField ( PGresult* res, int fieldcode ) ;
261 FUNCTION: int   PQntuples ( PGresult* res ) ;
262 FUNCTION: int   PQnfields ( PGresult* res ) ;
263 FUNCTION: int   PQbinaryTuples ( PGresult* res ) ;
264 FUNCTION: char* PQfname ( PGresult* res, int field_num ) ;
265 FUNCTION: int   PQfnumber ( PGresult* res, char* field_name ) ;
266 FUNCTION: Oid   PQftable ( PGresult* res, int field_num ) ;
267 FUNCTION: int   PQftablecol ( PGresult* res, int field_num ) ;
268 FUNCTION: int   PQfformat ( PGresult* res, int field_num ) ;
269 FUNCTION: Oid   PQftype ( PGresult* res, int field_num ) ;
270 FUNCTION: int   PQfsize ( PGresult* res, int field_num ) ;
271 FUNCTION: int   PQfmod ( PGresult* res, int field_num ) ;
272 FUNCTION: char* PQcmdStatus ( PGresult* res ) ;
273 FUNCTION: char* PQoidStatus ( PGresult* res ) ;
274 FUNCTION: Oid   PQoidValue ( PGresult* res ) ;
275 FUNCTION: char* PQcmdTuples ( PGresult* res ) ;
276 FUNCTION: char* PQgetvalue ( PGresult* res, int tup_num, int field_num ) ;
277 FUNCTION: int   PQgetlength ( PGresult* res, int tup_num, int field_num ) ;
278 FUNCTION: int   PQgetisnull ( PGresult* res, int tup_num, int field_num ) ;
279
280 ! Delete a PGresult
281 FUNCTION: void PQclear ( PGresult* res ) ;
282
283 ! For freeing other alloc'd results, such as PGnotify structs
284 FUNCTION: void PQfreemem ( void* ptr ) ;
285
286 ! Exists for backward compatibility.
287 : PQfreeNotify PQfreemem ;
288
289 !
290 ! Make an empty PGresult with given status (some apps find this
291 ! useful). If conn is not NULL and status indicates an error, the
292 ! conn's errorMessage is copied.
293 !
294 FUNCTION: PGresult* PQmakeEmptyPGresult ( PGconn* conn, ExecStatusType status ) ;
295
296 ! Quoting strings before inclusion in queries.
297 FUNCTION: size_t PQescapeStringConn ( PGconn* conn,
298                                     char* to, char* from, size_t length,
299                                     int* error ) ;
300 FUNCTION: uchar* PQescapeByteaConn ( PGconn* conn,
301                                     char* from, size_t length,
302                                     size_t* to_length ) ;
303 FUNCTION: uchar* PQunescapeBytea ( uchar* strtext,
304                 size_t* retbuflen ) ;
305 ! These forms are deprecated!
306 FUNCTION: size_t PQescapeString ( void* to, char* from, size_t length ) ;
307 FUNCTION: uchar* PQescapeBytea ( uchar* bintext, size_t binlen,
308                           size_t* bytealen ) ;
309
310 ! === in fe-print.c ===
311
312 FUNCTION: void PQprint ( FILE* fout, PGresult* res, PQprintOpt* ps ) ;
313
314 ! really old printing routines
315 FUNCTION: void PQdisplayTuples ( PGresult* res,
316                                 FILE* fp,               
317                                 int fillAlign,
318                                 char* fieldSep,
319                                 int printHeader,
320                                 int quiet ) ;
321
322 FUNCTION: void PQprintTuples ( PGresult* res,
323                           FILE* fout,           
324                           int printAttName,
325                           int terseOutput,      
326                           int width ) ; 
327                                                 
328 ! === in fe-lobj.c ===
329
330 ! Large-object access routines
331 FUNCTION: int   lo_open ( PGconn* conn, Oid lobjId, int mode ) ;
332 FUNCTION: int   lo_close ( PGconn* conn, int fd ) ;
333 FUNCTION: int   lo_read ( PGconn* conn, int fd, char* buf, size_t len ) ;
334 FUNCTION: int   lo_write ( PGconn* conn, int fd, char* buf, size_t len ) ;
335 FUNCTION: int   lo_lseek ( PGconn* conn, int fd, int offset, int whence ) ;
336 FUNCTION: Oid   lo_creat ( PGconn* conn, int mode ) ;
337 FUNCTION: Oid   lo_creat ( PGconn* conn, Oid lobjId ) ;
338 FUNCTION: int   lo_tell ( PGconn* conn, int fd ) ;
339 FUNCTION: int   lo_unlink ( PGconn* conn, Oid lobjId ) ;
340 FUNCTION: Oid   lo_import ( PGconn* conn, char* filename ) ;
341 FUNCTION: int   lo_export ( PGconn* conn, Oid lobjId, char* filename ) ;
342
343 ! === in fe-misc.c ===
344
345 ! Determine length of multibyte encoded char at *s
346 FUNCTION: int   PQmblen ( uchar* s, int encoding ) ;
347
348 ! Determine display length of multibyte encoded char at *s
349 FUNCTION: int   PQdsplen ( uchar* s, int encoding ) ;
350
351 ! Get encoding id from environment variable PGCLIENTENCODING
352 FUNCTION: int   PQenv2encoding ( ) ;
353