Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / include / postgre / libpq-fe.h
blobf51c6b38acdcdd2da4fe17f14cc601dc918bbc77
1 /*-------------------------------------------------------------------------
3 * libpq-fe.h
4 * This file contains definitions for structures and
5 * externs for functions used by frontend postgres applications.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.141 2008/01/01 19:46:00 momjian Exp $
12 *-------------------------------------------------------------------------
15 #ifndef LIBPQ_FE_H
16 #define LIBPQ_FE_H
18 #ifdef __cplusplus
19 extern "C"
21 #endif
23 #include <stdio.h>
26 * postgres_ext.h defines the backend's externally visible types,
27 * such as Oid.
29 #include "postgres_ext.h"
31 /* Application-visible enum types */
33 typedef enum
36 * Although it is okay to add to this list, values which become unused
37 * should never be removed, nor should constants be redefined - that would
38 * break compatibility with existing code.
40 CONNECTION_OK,
41 CONNECTION_BAD,
42 /* Non-blocking mode only below here */
45 * The existence of these should never be relied upon - they should only
46 * be used for user feedback or similar purposes.
48 CONNECTION_STARTED, /* Waiting for connection to be made. */
49 CONNECTION_MADE, /* Connection OK; waiting to send. */
50 CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the
51 * postmaster. */
52 CONNECTION_AUTH_OK, /* Received authentication; waiting for
53 * backend startup. */
54 CONNECTION_SETENV, /* Negotiating environment. */
55 CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
56 CONNECTION_NEEDED /* Internal state: connect() needed */
57 } ConnStatusType;
59 typedef enum
61 PGRES_POLLING_FAILED = 0,
62 PGRES_POLLING_READING, /* These two indicate that one may */
63 PGRES_POLLING_WRITING, /* use select before polling again. */
64 PGRES_POLLING_OK,
65 PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards
66 * compatibility */
67 } PostgresPollingStatusType;
69 typedef enum
71 PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
72 PGRES_COMMAND_OK, /* a query command that doesn't return
73 * anything was executed properly by the
74 * backend */
75 PGRES_TUPLES_OK, /* a query command that returns tuples was
76 * executed properly by the backend, PGresult
77 * contains the result tuples */
78 PGRES_COPY_OUT, /* Copy Out data transfer in progress */
79 PGRES_COPY_IN, /* Copy In data transfer in progress */
80 PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
81 * backend */
82 PGRES_NONFATAL_ERROR, /* notice or warning message */
83 PGRES_FATAL_ERROR /* query failed */
84 } ExecStatusType;
86 typedef enum
88 PQTRANS_IDLE, /* connection idle */
89 PQTRANS_ACTIVE, /* command in progress */
90 PQTRANS_INTRANS, /* idle, within transaction block */
91 PQTRANS_INERROR, /* idle, within failed transaction */
92 PQTRANS_UNKNOWN /* cannot determine status */
93 } PGTransactionStatusType;
95 typedef enum
97 PQERRORS_TERSE, /* single-line error messages */
98 PQERRORS_DEFAULT, /* recommended style */
99 PQERRORS_VERBOSE /* all the facts, ma'am */
100 } PGVerbosity;
102 /* PGconn encapsulates a connection to the backend.
103 * The contents of this struct are not supposed to be known to applications.
105 typedef struct pg_conn PGconn;
107 /* PGresult encapsulates the result of a query (or more precisely, of a single
108 * SQL command --- a query string given to PQsendQuery can contain multiple
109 * commands and thus return multiple PGresult objects).
110 * The contents of this struct are not supposed to be known to applications.
112 typedef struct pg_result PGresult;
114 /* PGcancel encapsulates the information needed to cancel a running
115 * query on an existing connection.
116 * The contents of this struct are not supposed to be known to applications.
118 typedef struct pg_cancel PGcancel;
120 /* PGnotify represents the occurrence of a NOTIFY message.
121 * Ideally this would be an opaque typedef, but it's so simple that it's
122 * unlikely to change.
123 * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
124 * whereas in earlier versions it was always your own backend's PID.
126 typedef struct pgNotify
128 char *relname; /* notification condition name */
129 int be_pid; /* process ID of notifying server process */
130 char *extra; /* notification parameter */
131 /* Fields below here are private to libpq; apps should not use 'em */
132 struct pgNotify *next; /* list link */
133 } PGnotify;
135 /* Function types for notice-handling callbacks */
136 typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
137 typedef void (*PQnoticeProcessor) (void *arg, const char *message);
139 /* Print options for PQprint() */
140 typedef char pqbool;
142 typedef struct _PQprintOpt
144 pqbool header; /* print output field headings and row count */
145 pqbool align; /* fill align the fields */
146 pqbool standard; /* old brain dead format */
147 pqbool html3; /* output html tables */
148 pqbool expanded; /* expand tables */
149 pqbool pager; /* use pager for output if needed */
150 char *fieldSep; /* field separator */
151 char *tableOpt; /* insert to HTML <table ...> */
152 char *caption; /* HTML <caption> */
153 char **fieldName; /* null terminated array of replacement field
154 * names */
155 } PQprintOpt;
157 /* ----------------
158 * Structure for the conninfo parameter definitions returned by PQconndefaults
160 * All fields except "val" point at static strings which must not be altered.
161 * "val" is either NULL or a malloc'd current-value string. PQconninfoFree()
162 * will release both the val strings and the PQconninfoOption array itself.
163 * ----------------
165 typedef struct _PQconninfoOption
167 char *keyword; /* The keyword of the option */
168 char *envvar; /* Fallback environment variable name */
169 char *compiled; /* Fallback compiled in default value */
170 char *val; /* Option's current value, or NULL */
171 char *label; /* Label for field in connect dialog */
172 char *dispchar; /* Character to display for this field in a
173 * connect dialog. Values are: "" Display
174 * entered value as is "*" Password field -
175 * hide value "D" Debug option - don't show
176 * by default */
177 int dispsize; /* Field size in characters for dialog */
178 } PQconninfoOption;
180 /* ----------------
181 * PQArgBlock -- structure for PQfn() arguments
182 * ----------------
184 typedef struct
186 int len;
187 int isint;
188 union
190 int *ptr; /* can't use void (dec compiler barfs) */
191 int integer;
192 } u;
193 } PQArgBlock;
195 /* ----------------
196 * Exported functions of libpq
197 * ----------------
200 /* === in fe-connect.c === */
202 /* make a new client connection to the backend */
203 /* Asynchronous (non-blocking) */
204 extern PGconn *PQconnectStart(const char *conninfo);
205 extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
207 /* Synchronous (blocking) */
208 extern PGconn *PQconnectdb(const char *conninfo);
209 extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
210 const char *pgoptions, const char *pgtty,
211 const char *dbName,
212 const char *login, const char *pwd);
214 #define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
215 PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
217 /* close the current connection and free the PGconn data structure */
218 extern void PQfinish(PGconn *conn);
220 /* get info about connection options known to PQconnectdb */
221 extern PQconninfoOption *PQconndefaults(void);
223 /* free the data structure returned by PQconndefaults() */
224 extern void PQconninfoFree(PQconninfoOption *connOptions);
227 * close the current connection and restablish a new one with the same
228 * parameters
230 /* Asynchronous (non-blocking) */
231 extern int PQresetStart(PGconn *conn);
232 extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
234 /* Synchronous (blocking) */
235 extern void PQreset(PGconn *conn);
237 /* request a cancel structure */
238 extern PGcancel *PQgetCancel(PGconn *conn);
240 /* free a cancel structure */
241 extern void PQfreeCancel(PGcancel *cancel);
243 /* issue a cancel request */
244 extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
246 /* backwards compatible version of PQcancel; not thread-safe */
247 extern int PQrequestCancel(PGconn *conn);
249 /* Accessor functions for PGconn objects */
250 extern char *PQdb(const PGconn *conn);
251 extern char *PQuser(const PGconn *conn);
252 extern char *PQpass(const PGconn *conn);
253 extern char *PQhost(const PGconn *conn);
254 extern char *PQport(const PGconn *conn);
255 extern char *PQtty(const PGconn *conn);
256 extern char *PQoptions(const PGconn *conn);
257 extern ConnStatusType PQstatus(const PGconn *conn);
258 extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
259 extern const char *PQparameterStatus(const PGconn *conn,
260 const char *paramName);
261 extern int PQprotocolVersion(const PGconn *conn);
262 extern int PQserverVersion(const PGconn *conn);
263 extern char *PQerrorMessage(const PGconn *conn);
264 extern int PQsocket(const PGconn *conn);
265 extern int PQbackendPID(const PGconn *conn);
266 extern int PQconnectionNeedsPassword(const PGconn *conn);
267 extern int PQconnectionUsedPassword(const PGconn *conn);
268 extern int PQclientEncoding(const PGconn *conn);
269 extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
271 /* Get the OpenSSL structure associated with a connection. Returns NULL for
272 * unencrypted connections or if any other TLS library is in use. */
273 extern void *PQgetssl(PGconn *conn);
275 /* Tell libpq whether it needs to initialize OpenSSL */
276 extern void PQinitSSL(int do_init);
278 /* Set verbosity for PQerrorMessage and PQresultErrorMessage */
279 extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
281 /* Enable/disable tracing */
282 extern void PQtrace(PGconn *conn, FILE *debug_port);
283 extern void PQuntrace(PGconn *conn);
285 /* Override default notice handling routines */
286 extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
287 PQnoticeReceiver proc,
288 void *arg);
289 extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
290 PQnoticeProcessor proc,
291 void *arg);
294 * Used to set callback that prevents concurrent access to
295 * non-thread safe functions that libpq needs.
296 * The default implementation uses a libpq internal mutex.
297 * Only required for multithreaded apps that use kerberos
298 * both within their app and for postgresql connections.
300 typedef void (*pgthreadlock_t) (int acquire);
302 extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
304 /* === in fe-exec.c === */
306 /* Simple synchronous query */
307 extern PGresult *PQexec(PGconn *conn, const char *query);
308 extern PGresult *PQexecParams(PGconn *conn,
309 const char *command,
310 int nParams,
311 const Oid *paramTypes,
312 const char *const * paramValues,
313 const int *paramLengths,
314 const int *paramFormats,
315 int resultFormat);
316 extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
317 const char *query, int nParams,
318 const Oid *paramTypes);
319 extern PGresult *PQexecPrepared(PGconn *conn,
320 const char *stmtName,
321 int nParams,
322 const char *const * paramValues,
323 const int *paramLengths,
324 const int *paramFormats,
325 int resultFormat);
327 /* Interface for multiple-result or asynchronous queries */
328 extern int PQsendQuery(PGconn *conn, const char *query);
329 extern int PQsendQueryParams(PGconn *conn,
330 const char *command,
331 int nParams,
332 const Oid *paramTypes,
333 const char *const * paramValues,
334 const int *paramLengths,
335 const int *paramFormats,
336 int resultFormat);
337 extern int PQsendPrepare(PGconn *conn, const char *stmtName,
338 const char *query, int nParams,
339 const Oid *paramTypes);
340 extern int PQsendQueryPrepared(PGconn *conn,
341 const char *stmtName,
342 int nParams,
343 const char *const * paramValues,
344 const int *paramLengths,
345 const int *paramFormats,
346 int resultFormat);
347 extern PGresult *PQgetResult(PGconn *conn);
349 /* Routines for managing an asynchronous query */
350 extern int PQisBusy(PGconn *conn);
351 extern int PQconsumeInput(PGconn *conn);
353 /* LISTEN/NOTIFY support */
354 extern PGnotify *PQnotifies(PGconn *conn);
356 /* Routines for copy in/out */
357 extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
358 extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
359 extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
361 /* Deprecated routines for copy in/out */
362 extern int PQgetline(PGconn *conn, char *string, int length);
363 extern int PQputline(PGconn *conn, const char *string);
364 extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
365 extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
366 extern int PQendcopy(PGconn *conn);
368 /* Set blocking/nonblocking connection to the backend */
369 extern int PQsetnonblocking(PGconn *conn, int arg);
370 extern int PQisnonblocking(const PGconn *conn);
371 extern int PQisthreadsafe(void);
373 /* Force the write buffer to be written (or at least try) */
374 extern int PQflush(PGconn *conn);
377 * "Fast path" interface --- not really recommended for application
378 * use
380 extern PGresult *PQfn(PGconn *conn,
381 int fnid,
382 int *result_buf,
383 int *result_len,
384 int result_is_int,
385 const PQArgBlock *args,
386 int nargs);
388 /* Accessor functions for PGresult objects */
389 extern ExecStatusType PQresultStatus(const PGresult *res);
390 extern char *PQresStatus(ExecStatusType status);
391 extern char *PQresultErrorMessage(const PGresult *res);
392 extern char *PQresultErrorField(const PGresult *res, int fieldcode);
393 extern int PQntuples(const PGresult *res);
394 extern int PQnfields(const PGresult *res);
395 extern int PQbinaryTuples(const PGresult *res);
396 extern char *PQfname(const PGresult *res, int field_num);
397 extern int PQfnumber(const PGresult *res, const char *field_name);
398 extern Oid PQftable(const PGresult *res, int field_num);
399 extern int PQftablecol(const PGresult *res, int field_num);
400 extern int PQfformat(const PGresult *res, int field_num);
401 extern Oid PQftype(const PGresult *res, int field_num);
402 extern int PQfsize(const PGresult *res, int field_num);
403 extern int PQfmod(const PGresult *res, int field_num);
404 extern char *PQcmdStatus(PGresult *res);
405 extern char *PQoidStatus(const PGresult *res); /* old and ugly */
406 extern Oid PQoidValue(const PGresult *res); /* new and improved */
407 extern char *PQcmdTuples(PGresult *res);
408 extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
409 extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
410 extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
411 extern int PQnparams(const PGresult *res);
412 extern Oid PQparamtype(const PGresult *res, int param_num);
414 /* Describe prepared statements and portals */
415 extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
416 extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
417 extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
418 extern int PQsendDescribePortal(PGconn *conn, const char *portal);
420 /* Delete a PGresult */
421 extern void PQclear(PGresult *res);
423 /* For freeing other alloc'd results, such as PGnotify structs */
424 extern void PQfreemem(void *ptr);
426 /* Exists for backward compatibility. bjm 2003-03-24 */
427 #define PQfreeNotify(ptr) PQfreemem(ptr)
429 /* Error when no password was given. */
430 /* Note: depending on this is deprecated; use PQconnectionNeedsPassword(). */
431 #define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
434 * Make an empty PGresult with given status (some apps find this
435 * useful). If conn is not NULL and status indicates an error, the
436 * conn's errorMessage is copied.
438 extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
441 /* Quoting strings before inclusion in queries. */
442 extern size_t PQescapeStringConn(PGconn *conn,
443 char *to, const char *from, size_t length,
444 int *error);
445 extern unsigned char *PQescapeByteaConn(PGconn *conn,
446 const unsigned char *from, size_t from_length,
447 size_t *to_length);
448 extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
449 size_t *retbuflen);
451 /* These forms are deprecated! */
452 extern size_t PQescapeString(char *to, const char *from, size_t length);
453 extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
454 size_t *to_length);
458 /* === in fe-print.c === */
460 extern void
461 PQprint(FILE *fout, /* output stream */
462 const PGresult *res,
463 const PQprintOpt *ps); /* option structure */
466 * really old printing routines
468 extern void
469 PQdisplayTuples(const PGresult *res,
470 FILE *fp, /* where to send the output */
471 int fillAlign, /* pad the fields with spaces */
472 const char *fieldSep, /* field separator */
473 int printHeader, /* display headers? */
474 int quiet);
476 extern void
477 PQprintTuples(const PGresult *res,
478 FILE *fout, /* output stream */
479 int printAttName, /* print attribute names */
480 int terseOutput, /* delimiter bars */
481 int width); /* width of column, if 0, use variable width */
484 /* === in fe-lobj.c === */
486 /* Large-object access routines */
487 extern int lo_open(PGconn *conn, Oid lobjId, int mode);
488 extern int lo_close(PGconn *conn, int fd);
489 extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
490 extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
491 extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
492 extern Oid lo_creat(PGconn *conn, int mode);
493 extern Oid lo_create(PGconn *conn, Oid lobjId);
494 extern int lo_tell(PGconn *conn, int fd);
495 extern int lo_truncate(PGconn *conn, int fd, size_t len);
496 extern int lo_unlink(PGconn *conn, Oid lobjId);
497 extern Oid lo_import(PGconn *conn, const char *filename);
498 extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
500 /* === in fe-misc.c === */
502 /* Determine length of multibyte encoded char at *s */
503 extern int PQmblen(const char *s, int encoding);
505 /* Determine display length of multibyte encoded char at *s */
506 extern int PQdsplen(const char *s, int encoding);
508 /* Get encoding id from environment variable PGCLIENTENCODING */
509 extern int PQenv2encoding(void);
511 /* === in fe-auth.c === */
513 extern char *PQencryptPassword(const char *passwd, const char *user);
515 /* === in encnames.c === */
517 extern int pg_char_to_encoding(const char *name);
518 extern const char *pg_encoding_to_char(int encoding);
519 extern int pg_valid_server_encoding_id(int encoding);
521 #ifdef __cplusplus
523 #endif
525 #endif /* LIBPQ_FE_H */