Annotation of win32/sql/pgsql/include/libpq-fe.h, revision 1.3
1.1 parser 1: /*-------------------------------------------------------------------------
2: *
3: * libpq-fe.h
4: * This file contains definitions for structures and
5: * externs for functions used by frontend postgres applications.
6: *
1.3 ! misha 7: * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1.1 parser 8: * Portions Copyright (c) 1994, Regents of the University of California
9: *
1.3 ! misha 10: * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.134 2006/10/04 00:30:13 momjian Exp $
1.1 parser 11: *
12: *-------------------------------------------------------------------------
13: */
14:
15: #ifndef LIBPQ_FE_H
16: #define LIBPQ_FE_H
17:
18: #ifdef __cplusplus
19: extern "C"
20: {
21: #endif
22:
23: #include <stdio.h>
1.2 misha 24:
25: /*
26: * postgres_ext.h defines the backend's externally visible types,
1.1 parser 27: * such as Oid.
28: */
29: #include "postgres_ext.h"
1.2 misha 30:
1.1 parser 31: /* Application-visible enum types */
32:
1.2 misha 33: typedef enum
34: {
35: /*
36: * Although it is okay to add to this list, values which become unused
1.3 ! misha 37: * should never be removed, nor should constants be redefined - that would
! 38: * break compatibility with existing code.
1.2 misha 39: */
40: CONNECTION_OK,
41: CONNECTION_BAD,
42: /* Non-blocking mode only below here */
1.1 parser 43:
1.2 misha 44: /*
1.3 ! misha 45: * The existence of these should never be relied upon - they should only
! 46: * be used for user feedback or similar purposes.
1.2 misha 47: */
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
1.1 parser 51: * postmaster. */
1.2 misha 52: CONNECTION_AUTH_OK, /* Received authentication; waiting for
1.1 parser 53: * backend startup. */
1.2 misha 54: CONNECTION_SETENV, /* Negotiating environment. */
55: CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
56: CONNECTION_NEEDED /* Internal state: connect() needed */
57: } ConnStatusType;
1.1 parser 58:
1.2 misha 59: typedef enum
60: {
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;
1.1 parser 68:
1.2 misha 69: typedef enum
70: {
71: PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
72: PGRES_COMMAND_OK, /* a query command that doesn't return
1.1 parser 73: * anything was executed properly by the
74: * backend */
1.2 misha 75: PGRES_TUPLES_OK, /* a query command that returns tuples was
1.3 ! misha 76: * executed properly by the backend, PGresult
! 77: * contains the result tuples */
1.2 misha 78: PGRES_COPY_OUT, /* Copy Out data transfer in progress */
79: PGRES_COPY_IN, /* Copy In data transfer in progress */
1.3 ! misha 80: PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
! 81: * backend */
1.2 misha 82: PGRES_NONFATAL_ERROR, /* notice or warning message */
83: PGRES_FATAL_ERROR /* query failed */
84: } ExecStatusType;
85:
86: typedef enum
87: {
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;
94:
95: typedef enum
96: {
97: PQERRORS_TERSE, /* single-line error messages */
98: PQERRORS_DEFAULT, /* recommended style */
99: PQERRORS_VERBOSE /* all the facts, ma'am */
100: } PGVerbosity;
1.1 parser 101:
102: /* PGconn encapsulates a connection to the backend.
103: * The contents of this struct are not supposed to be known to applications.
104: */
1.2 misha 105: typedef struct pg_conn PGconn;
1.1 parser 106:
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.
111: */
1.2 misha 112: typedef struct pg_result PGresult;
113:
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.
117: */
118: typedef struct pg_cancel PGcancel;
1.1 parser 119:
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.
125: */
1.2 misha 126: typedef struct pgNotify
127: {
128: char *relname; /* notification condition name */
1.3 ! misha 129: int be_pid; /* process ID of notifying server process */
1.2 misha 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;
134:
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);
1.1 parser 138:
139: /* Print options for PQprint() */
1.2 misha 140: typedef char pqbool;
1.1 parser 141:
1.2 misha 142: typedef struct _PQprintOpt
143: {
1.3 ! misha 144: pqbool header; /* print output field headings and row count */
1.2 misha 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> */
1.3 ! misha 153: char **fieldName; /* null terminated array of replacement field
! 154: * names */
1.2 misha 155: } PQprintOpt;
1.1 parser 156:
157: /* ----------------
158: * Structure for the conninfo parameter definitions returned by PQconndefaults
159: *
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: * ----------------
164: */
1.2 misha 165: typedef struct _PQconninfoOption
166: {
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 */
1.3 ! misha 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 */
1.2 misha 177: int dispsize; /* Field size in characters for dialog */
178: } PQconninfoOption;
1.1 parser 179:
180: /* ----------------
181: * PQArgBlock -- structure for PQfn() arguments
182: * ----------------
183: */
1.2 misha 184: typedef struct
185: {
186: int len;
187: int isint;
188: union
1.1 parser 189: {
1.2 misha 190: int *ptr; /* can't use void (dec compiler barfs) */
191: int integer;
192: } u;
193: } PQArgBlock;
1.1 parser 194:
195: /* ----------------
196: * Exported functions of libpq
197: * ----------------
198: */
199:
200: /* === in fe-connect.c === */
201:
1.2 misha 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);
206:
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);
213:
1.1 parser 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)
216:
1.2 misha 217: /* close the current connection and free the PGconn data structure */
218: extern void PQfinish(PGconn *conn);
1.1 parser 219:
1.2 misha 220: /* get info about connection options known to PQconnectdb */
221: extern PQconninfoOption *PQconndefaults(void);
1.1 parser 222:
1.2 misha 223: /* free the data structure returned by PQconndefaults() */
224: extern void PQconninfoFree(PQconninfoOption *connOptions);
225:
226: /*
227: * close the current connection and restablish a new one with the same
228: * parameters
229: */
230: /* Asynchronous (non-blocking) */
231: extern int PQresetStart(PGconn *conn);
232: extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
233:
234: /* Synchronous (blocking) */
235: extern void PQreset(PGconn *conn);
236:
237: /* request a cancel structure */
238: extern PGcancel *PQgetCancel(PGconn *conn);
239:
240: /* free a cancel structure */
241: extern void PQfreeCancel(PGcancel *cancel);
242:
243: /* issue a cancel request */
244: extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
245:
246: /* backwards compatible version of PQcancel; not thread-safe */
247: extern int PQrequestCancel(PGconn *conn);
248:
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 PQclientEncoding(const PGconn *conn);
267: extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
1.1 parser 268:
1.3 ! misha 269: /* Get the OpenSSL structure associated with a connection. Returns NULL for
! 270: * unencrypted connections or if any other TLS library is in use. */
1.2 misha 271: extern void *PQgetssl(PGconn *conn);
1.1 parser 272:
1.2 misha 273: /* Tell libpq whether it needs to initialize OpenSSL */
274: extern void PQinitSSL(int do_init);
275:
276: /* Set verbosity for PQerrorMessage and PQresultErrorMessage */
277: extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
1.1 parser 278:
1.2 misha 279: /* Enable/disable tracing */
280: extern void PQtrace(PGconn *conn, FILE *debug_port);
281: extern void PQuntrace(PGconn *conn);
282:
283: /* Override default notice handling routines */
284: extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
285: PQnoticeReceiver proc,
286: void *arg);
287: extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
288: PQnoticeProcessor proc,
289: void *arg);
290:
291: /*
292: * Used to set callback that prevents concurrent access to
293: * non-thread safe functions that libpq needs.
294: * The default implementation uses a libpq internal mutex.
295: * Only required for multithreaded apps that use kerberos
296: * both within their app and for postgresql connections.
297: */
298: typedef void (*pgthreadlock_t) (int acquire);
1.1 parser 299:
1.2 misha 300: extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
1.1 parser 301:
302: /* === in fe-exec.c === */
303:
1.2 misha 304: /* Simple synchronous query */
305: extern PGresult *PQexec(PGconn *conn, const char *query);
306: extern PGresult *PQexecParams(PGconn *conn,
307: const char *command,
308: int nParams,
309: const Oid *paramTypes,
310: const char *const * paramValues,
311: const int *paramLengths,
312: const int *paramFormats,
313: int resultFormat);
314: extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
1.3 ! misha 315: const char *query, int nParams,
! 316: const Oid *paramTypes);
1.2 misha 317: extern PGresult *PQexecPrepared(PGconn *conn,
318: const char *stmtName,
319: int nParams,
320: const char *const * paramValues,
321: const int *paramLengths,
322: const int *paramFormats,
323: int resultFormat);
324:
325: /* Interface for multiple-result or asynchronous queries */
326: extern int PQsendQuery(PGconn *conn, const char *query);
327: extern int PQsendQueryParams(PGconn *conn,
328: const char *command,
329: int nParams,
330: const Oid *paramTypes,
331: const char *const * paramValues,
332: const int *paramLengths,
333: const int *paramFormats,
334: int resultFormat);
335: extern int PQsendPrepare(PGconn *conn, const char *stmtName,
1.3 ! misha 336: const char *query, int nParams,
! 337: const Oid *paramTypes);
1.2 misha 338: extern int PQsendQueryPrepared(PGconn *conn,
339: const char *stmtName,
340: int nParams,
341: const char *const * paramValues,
342: const int *paramLengths,
343: const int *paramFormats,
344: int resultFormat);
345: extern PGresult *PQgetResult(PGconn *conn);
346:
347: /* Routines for managing an asynchronous query */
348: extern int PQisBusy(PGconn *conn);
349: extern int PQconsumeInput(PGconn *conn);
350:
351: /* LISTEN/NOTIFY support */
352: extern PGnotify *PQnotifies(PGconn *conn);
353:
354: /* Routines for copy in/out */
355: extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
356: extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
357: extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
358:
359: /* Deprecated routines for copy in/out */
360: extern int PQgetline(PGconn *conn, char *string, int length);
361: extern int PQputline(PGconn *conn, const char *string);
362: extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
363: extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
364: extern int PQendcopy(PGconn *conn);
365:
366: /* Set blocking/nonblocking connection to the backend */
367: extern int PQsetnonblocking(PGconn *conn, int arg);
368: extern int PQisnonblocking(const PGconn *conn);
1.3 ! misha 369: extern int PQisthreadsafe(void);
1.2 misha 370:
371: /* Force the write buffer to be written (or at least try) */
372: extern int PQflush(PGconn *conn);
373:
374: /*
375: * "Fast path" interface --- not really recommended for application
376: * use
377: */
378: extern PGresult *PQfn(PGconn *conn,
379: int fnid,
380: int *result_buf,
381: int *result_len,
382: int result_is_int,
383: const PQArgBlock *args,
384: int nargs);
385:
386: /* Accessor functions for PGresult objects */
387: extern ExecStatusType PQresultStatus(const PGresult *res);
388: extern char *PQresStatus(ExecStatusType status);
389: extern char *PQresultErrorMessage(const PGresult *res);
390: extern char *PQresultErrorField(const PGresult *res, int fieldcode);
391: extern int PQntuples(const PGresult *res);
392: extern int PQnfields(const PGresult *res);
393: extern int PQbinaryTuples(const PGresult *res);
394: extern char *PQfname(const PGresult *res, int field_num);
395: extern int PQfnumber(const PGresult *res, const char *field_name);
396: extern Oid PQftable(const PGresult *res, int field_num);
397: extern int PQftablecol(const PGresult *res, int field_num);
398: extern int PQfformat(const PGresult *res, int field_num);
399: extern Oid PQftype(const PGresult *res, int field_num);
400: extern int PQfsize(const PGresult *res, int field_num);
401: extern int PQfmod(const PGresult *res, int field_num);
402: extern char *PQcmdStatus(PGresult *res);
403: extern char *PQoidStatus(const PGresult *res); /* old and ugly */
404: extern Oid PQoidValue(const PGresult *res); /* new and improved */
405: extern char *PQcmdTuples(PGresult *res);
406: extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
407: extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
408: extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
1.3 ! misha 409: extern int PQnparams(const PGresult *res);
! 410: extern Oid PQparamtype(const PGresult *res, int param_num);
! 411:
! 412: /* Describe prepared statements and portals */
! 413: extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
! 414: extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
! 415: extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
! 416: extern int PQsendDescribePortal(PGconn *conn, const char *portal);
1.2 misha 417:
418: /* Delete a PGresult */
419: extern void PQclear(PGresult *res);
420:
421: /* For freeing other alloc'd results, such as PGnotify structs */
422: extern void PQfreemem(void *ptr);
423:
424: /* Exists for backward compatibility. bjm 2003-03-24 */
425: #define PQfreeNotify(ptr) PQfreemem(ptr)
426:
427: /* Define the string so all uses are consistent. */
428: #define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
429:
430: /*
431: * Make an empty PGresult with given status (some apps find this
432: * useful). If conn is not NULL and status indicates an error, the
433: * conn's errorMessage is copied.
434: */
435: extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
1.1 parser 436:
437:
1.2 misha 438: /* Quoting strings before inclusion in queries. */
439: extern size_t PQescapeStringConn(PGconn *conn,
1.3 ! misha 440: char *to, const char *from, size_t length,
! 441: int *error);
1.2 misha 442: extern unsigned char *PQescapeByteaConn(PGconn *conn,
443: const unsigned char *from, size_t from_length,
444: size_t *to_length);
445: extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
446: size_t *retbuflen);
1.3 ! misha 447:
1.2 misha 448: /* These forms are deprecated! */
449: extern size_t PQescapeString(char *to, const char *from, size_t length);
450: extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
451: size_t *to_length);
1.1 parser 452:
453:
454:
455: /* === in fe-print.c === */
456:
1.2 misha 457: extern void
458: PQprint(FILE *fout, /* output stream */
459: const PGresult *res,
460: const PQprintOpt *ps); /* option structure */
1.1 parser 461:
1.2 misha 462: /*
463: * really old printing routines
464: */
465: extern void
466: PQdisplayTuples(const PGresult *res,
467: FILE *fp, /* where to send the output */
468: int fillAlign, /* pad the fields with spaces */
469: const char *fieldSep, /* field separator */
470: int printHeader, /* display headers? */
471: int quiet);
472:
473: extern void
474: PQprintTuples(const PGresult *res,
475: FILE *fout, /* output stream */
476: int printAttName, /* print attribute names */
477: int terseOutput, /* delimiter bars */
1.3 ! misha 478: int width); /* width of column, if 0, use variable width */
1.1 parser 479:
480:
481: /* === in fe-lobj.c === */
482:
1.2 misha 483: /* Large-object access routines */
484: extern int lo_open(PGconn *conn, Oid lobjId, int mode);
485: extern int lo_close(PGconn *conn, int fd);
486: extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
1.3 ! misha 487: extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
1.2 misha 488: extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
489: extern Oid lo_creat(PGconn *conn, int mode);
1.3 ! misha 490: extern Oid lo_create(PGconn *conn, Oid lobjId);
1.2 misha 491: extern int lo_tell(PGconn *conn, int fd);
492: extern int lo_unlink(PGconn *conn, Oid lobjId);
493: extern Oid lo_import(PGconn *conn, const char *filename);
494: extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
1.1 parser 495:
496: /* === in fe-misc.c === */
497:
1.2 misha 498: /* Determine length of multibyte encoded char at *s */
1.3 ! misha 499: extern int PQmblen(const char *s, int encoding);
1.1 parser 500:
1.2 misha 501: /* Determine display length of multibyte encoded char at *s */
1.3 ! misha 502: extern int PQdsplen(const char *s, int encoding);
1.2 misha 503:
504: /* Get encoding id from environment variable PGCLIENTENCODING */
505: extern int PQenv2encoding(void);
1.1 parser 506:
1.3 ! misha 507: /* === in fe-auth.c === */
! 508:
! 509: extern char *PQencryptPassword(const char *passwd, const char *user);
! 510:
1.1 parser 511: #ifdef __cplusplus
512: }
513: #endif
514:
1.2 misha 515: #endif /* LIBPQ_FE_H */
E-mail: