Warning: That file was not part of the compilation database. It may have many parsing errors.

1/*-------------------------------------------------------------------------
2 *
3 * libpq-fe.h
4 * This file contains definitions for structures and
5 * externs for functions used by frontend postgres applications.
6 *
7 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/interfaces/libpq/libpq-fe.h
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#ifndef LIBPQ_FE_H
16#define LIBPQ_FE_H
17
18#ifdef __cplusplus
19extern "C"
20{
21#endif
22
23#include <stdio.h>
24
25/*
26 * postgres_ext.h defines the backend's externally visible types,
27 * such as Oid.
28 */
29#include "postgres_ext.h"
30
31/*
32 * Option flags for PQcopyResult
33 */
34#define PG_COPYRES_ATTRS 0x01
35#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */
36#define PG_COPYRES_EVENTS 0x04
37#define PG_COPYRES_NOTICEHOOKS 0x08
38
39/* Application-visible enum types */
40
41/*
42 * Although it is okay to add to these lists, values which become unused
43 * should never be removed, nor should constants be redefined - that would
44 * break compatibility with existing code.
45 */
46
47typedef enum
48{
49 CONNECTION_OK,
50 CONNECTION_BAD,
51 /* Non-blocking mode only below here */
52
53 /*
54 * The existence of these should never be relied upon - they should only
55 * be used for user feedback or similar purposes.
56 */
57 CONNECTION_STARTED, /* Waiting for connection to be made. */
58 CONNECTION_MADE, /* Connection OK; waiting to send. */
59 CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the
60 * postmaster. */
61 CONNECTION_AUTH_OK, /* Received authentication; waiting for
62 * backend startup. */
63 CONNECTION_SETENV, /* Negotiating environment. */
64 CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
65 CONNECTION_NEEDED /* Internal state: connect() needed */
66} ConnStatusType;
67
68typedef enum
69{
70 PGRES_POLLING_FAILED = 0,
71 PGRES_POLLING_READING, /* These two indicate that one may */
72 PGRES_POLLING_WRITING, /* use select before polling again. */
73 PGRES_POLLING_OK,
74 PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards
75 * compatibility */
76} PostgresPollingStatusType;
77
78typedef enum
79{
80 PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
81 PGRES_COMMAND_OK, /* a query command that doesn't return
82 * anything was executed properly by the
83 * backend */
84 PGRES_TUPLES_OK, /* a query command that returns tuples was
85 * executed properly by the backend, PGresult
86 * contains the result tuples */
87 PGRES_COPY_OUT, /* Copy Out data transfer in progress */
88 PGRES_COPY_IN, /* Copy In data transfer in progress */
89 PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
90 * backend */
91 PGRES_NONFATAL_ERROR, /* notice or warning message */
92 PGRES_FATAL_ERROR, /* query failed */
93 PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
94 PGRES_SINGLE_TUPLE /* single tuple from larger resultset */
95} ExecStatusType;
96
97typedef enum
98{
99 PQTRANS_IDLE, /* connection idle */
100 PQTRANS_ACTIVE, /* command in progress */
101 PQTRANS_INTRANS, /* idle, within transaction block */
102 PQTRANS_INERROR, /* idle, within failed transaction */
103 PQTRANS_UNKNOWN /* cannot determine status */
104} PGTransactionStatusType;
105
106typedef enum
107{
108 PQERRORS_TERSE, /* single-line error messages */
109 PQERRORS_DEFAULT, /* recommended style */
110 PQERRORS_VERBOSE /* all the facts, ma'am */
111} PGVerbosity;
112
113/*
114 * PGPing - The ordering of this enum should not be altered because the
115 * values are exposed externally via pg_isready.
116 */
117
118typedef enum
119{
120 PQPING_OK, /* server is accepting connections */
121 PQPING_REJECT, /* server is alive but rejecting connections */
122 PQPING_NO_RESPONSE, /* could not establish connection */
123 PQPING_NO_ATTEMPT /* connection not attempted (bad params) */
124} PGPing;
125
126/* PGconn encapsulates a connection to the backend.
127 * The contents of this struct are not supposed to be known to applications.
128 */
129typedef struct pg_conn PGconn;
130
131/* PGresult encapsulates the result of a query (or more precisely, of a single
132 * SQL command --- a query string given to PQsendQuery can contain multiple
133 * commands and thus return multiple PGresult objects).
134 * The contents of this struct are not supposed to be known to applications.
135 */
136typedef struct pg_result PGresult;
137
138/* PGcancel encapsulates the information needed to cancel a running
139 * query on an existing connection.
140 * The contents of this struct are not supposed to be known to applications.
141 */
142typedef struct pg_cancel PGcancel;
143
144/* PGnotify represents the occurrence of a NOTIFY message.
145 * Ideally this would be an opaque typedef, but it's so simple that it's
146 * unlikely to change.
147 * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
148 * whereas in earlier versions it was always your own backend's PID.
149 */
150typedef struct pgNotify
151{
152 char *relname; /* notification condition name */
153 int be_pid; /* process ID of notifying server process */
154 char *extra; /* notification parameter */
155 /* Fields below here are private to libpq; apps should not use 'em */
156 struct pgNotify *next; /* list link */
157} PGnotify;
158
159/* Function types for notice-handling callbacks */
160typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
161typedef void (*PQnoticeProcessor) (void *arg, const char *message);
162
163/* Print options for PQprint() */
164typedef char pqbool;
165
166typedef struct _PQprintOpt
167{
168 pqbool header; /* print output field headings and row count */
169 pqbool align; /* fill align the fields */
170 pqbool standard; /* old brain dead format */
171 pqbool html3; /* output html tables */
172 pqbool expanded; /* expand tables */
173 pqbool pager; /* use pager for output if needed */
174 char *fieldSep; /* field separator */
175 char *tableOpt; /* insert to HTML <table ...> */
176 char *caption; /* HTML <caption> */
177 char **fieldName; /* null terminated array of replacement field
178 * names */
179} PQprintOpt;
180
181/* ----------------
182 * Structure for the conninfo parameter definitions returned by PQconndefaults
183 * or PQconninfoParse.
184 *
185 * All fields except "val" point at static strings which must not be altered.
186 * "val" is either NULL or a malloc'd current-value string. PQconninfoFree()
187 * will release both the val strings and the PQconninfoOption array itself.
188 * ----------------
189 */
190typedef struct _PQconninfoOption
191{
192 char *keyword; /* The keyword of the option */
193 char *envvar; /* Fallback environment variable name */
194 char *compiled; /* Fallback compiled in default value */
195 char *val; /* Option's current value, or NULL */
196 char *label; /* Label for field in connect dialog */
197 char *dispchar; /* Indicates how to display this field in a
198 * connect dialog. Values are: "" Display
199 * entered value as is "*" Password field -
200 * hide value "D" Debug option - don't show
201 * by default */
202 int dispsize; /* Field size in characters for dialog */
203} PQconninfoOption;
204
205/* ----------------
206 * PQArgBlock -- structure for PQfn() arguments
207 * ----------------
208 */
209typedef struct
210{
211 int len;
212 int isint;
213 union
214 {
215 int *ptr; /* can't use void (dec compiler barfs) */
216 int integer;
217 } u;
218} PQArgBlock;
219
220/* ----------------
221 * PGresAttDesc -- Data about a single attribute (column) of a query result
222 * ----------------
223 */
224typedef struct pgresAttDesc
225{
226 char *name; /* column name */
227 Oid tableid; /* source table, if known */
228 int columnid; /* source column, if known */
229 int format; /* format code for value (text/binary) */
230 Oid typid; /* type id */
231 int typlen; /* type size */
232 int atttypmod; /* type-specific modifier info */
233} PGresAttDesc;
234
235/* ----------------
236 * Exported functions of libpq
237 * ----------------
238 */
239
240/* === in fe-connect.c === */
241
242/* make a new client connection to the backend */
243/* Asynchronous (non-blocking) */
244extern PGconn *PQconnectStart(const char *conninfo);
245extern PGconn *PQconnectStartParams(const char *const * keywords,
246 const char *const * values, int expand_dbname);
247extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
248
249/* Synchronous (blocking) */
250extern PGconn *PQconnectdb(const char *conninfo);
251extern PGconn *PQconnectdbParams(const char *const * keywords,
252 const char *const * values, int expand_dbname);
253extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
254 const char *pgoptions, const char *pgtty,
255 const char *dbName,
256 const char *login, const char *pwd);
257
258#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
259 PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
260
261/* close the current connection and free the PGconn data structure */
262extern void PQfinish(PGconn *conn);
263
264/* get info about connection options known to PQconnectdb */
265extern PQconninfoOption *PQconndefaults(void);
266
267/* parse connection options in same way as PQconnectdb */
268extern PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
269
270/* return the connection options used by a live connection */
271extern PQconninfoOption *PQconninfo(PGconn *conn);
272
273/* free the data structure returned by PQconndefaults() or PQconninfoParse() */
274extern void PQconninfoFree(PQconninfoOption *connOptions);
275
276/*
277 * close the current connection and restablish a new one with the same
278 * parameters
279 */
280/* Asynchronous (non-blocking) */
281extern int PQresetStart(PGconn *conn);
282extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
283
284/* Synchronous (blocking) */
285extern void PQreset(PGconn *conn);
286
287/* request a cancel structure */
288extern PGcancel *PQgetCancel(PGconn *conn);
289
290/* free a cancel structure */
291extern void PQfreeCancel(PGcancel *cancel);
292
293/* issue a cancel request */
294extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
295
296/* backwards compatible version of PQcancel; not thread-safe */
297extern int PQrequestCancel(PGconn *conn);
298
299/* Accessor functions for PGconn objects */
300extern char *PQdb(const PGconn *conn);
301extern char *PQuser(const PGconn *conn);
302extern char *PQpass(const PGconn *conn);
303extern char *PQhost(const PGconn *conn);
304extern char *PQport(const PGconn *conn);
305extern char *PQtty(const PGconn *conn);
306extern char *PQoptions(const PGconn *conn);
307extern ConnStatusType PQstatus(const PGconn *conn);
308extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
309extern const char *PQparameterStatus(const PGconn *conn,
310 const char *paramName);
311extern int PQprotocolVersion(const PGconn *conn);
312extern int PQserverVersion(const PGconn *conn);
313extern char *PQerrorMessage(const PGconn *conn);
314extern int PQsocket(const PGconn *conn);
315extern int PQbackendPID(const PGconn *conn);
316extern int PQconnectionNeedsPassword(const PGconn *conn);
317extern int PQconnectionUsedPassword(const PGconn *conn);
318extern int PQclientEncoding(const PGconn *conn);
319extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
320
321/* Get the OpenSSL structure associated with a connection. Returns NULL for
322 * unencrypted connections or if any other TLS library is in use. */
323extern void *PQgetssl(PGconn *conn);
324
325/* Tell libpq whether it needs to initialize OpenSSL */
326extern void PQinitSSL(int do_init);
327
328/* More detailed way to tell libpq whether it needs to initialize OpenSSL */
329extern void PQinitOpenSSL(int do_ssl, int do_crypto);
330
331/* Set verbosity for PQerrorMessage and PQresultErrorMessage */
332extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
333
334/* Enable/disable tracing */
335extern void PQtrace(PGconn *conn, FILE *debug_port);
336extern void PQuntrace(PGconn *conn);
337
338/* Override default notice handling routines */
339extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
340 PQnoticeReceiver proc,
341 void *arg);
342extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
343 PQnoticeProcessor proc,
344 void *arg);
345
346/*
347 * Used to set callback that prevents concurrent access to
348 * non-thread safe functions that libpq needs.
349 * The default implementation uses a libpq internal mutex.
350 * Only required for multithreaded apps that use kerberos
351 * both within their app and for postgresql connections.
352 */
353typedef void (*pgthreadlock_t) (int acquire);
354
355extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
356
357/* === in fe-exec.c === */
358
359/* Simple synchronous query */
360extern PGresult *PQexec(PGconn *conn, const char *query);
361extern PGresult *PQexecParams(PGconn *conn,
362 const char *command,
363 int nParams,
364 const Oid *paramTypes,
365 const char *const * paramValues,
366 const int *paramLengths,
367 const int *paramFormats,
368 int resultFormat);
369extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
370 const char *query, int nParams,
371 const Oid *paramTypes);
372extern PGresult *PQexecPrepared(PGconn *conn,
373 const char *stmtName,
374 int nParams,
375 const char *const * paramValues,
376 const int *paramLengths,
377 const int *paramFormats,
378 int resultFormat);
379
380/* Interface for multiple-result or asynchronous queries */
381extern int PQsendQuery(PGconn *conn, const char *query);
382extern int PQsendQueryParams(PGconn *conn,
383 const char *command,
384 int nParams,
385 const Oid *paramTypes,
386 const char *const * paramValues,
387 const int *paramLengths,
388 const int *paramFormats,
389 int resultFormat);
390extern int PQsendPrepare(PGconn *conn, const char *stmtName,
391 const char *query, int nParams,
392 const Oid *paramTypes);
393extern int PQsendQueryPrepared(PGconn *conn,
394 const char *stmtName,
395 int nParams,
396 const char *const * paramValues,
397 const int *paramLengths,
398 const int *paramFormats,
399 int resultFormat);
400extern int PQsetSingleRowMode(PGconn *conn);
401extern PGresult *PQgetResult(PGconn *conn);
402
403/* Routines for managing an asynchronous query */
404extern int PQisBusy(PGconn *conn);
405extern int PQconsumeInput(PGconn *conn);
406
407/* LISTEN/NOTIFY support */
408extern PGnotify *PQnotifies(PGconn *conn);
409
410/* Routines for copy in/out */
411extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
412extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
413extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
414
415/* Deprecated routines for copy in/out */
416extern int PQgetline(PGconn *conn, char *string, int length);
417extern int PQputline(PGconn *conn, const char *string);
418extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
419extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
420extern int PQendcopy(PGconn *conn);
421
422/* Set blocking/nonblocking connection to the backend */
423extern int PQsetnonblocking(PGconn *conn, int arg);
424extern int PQisnonblocking(const PGconn *conn);
425extern int PQisthreadsafe(void);
426extern PGPing PQping(const char *conninfo);
427extern PGPing PQpingParams(const char *const * keywords,
428 const char *const * values, int expand_dbname);
429
430/* Force the write buffer to be written (or at least try) */
431extern int PQflush(PGconn *conn);
432
433/*
434 * "Fast path" interface --- not really recommended for application
435 * use
436 */
437extern PGresult *PQfn(PGconn *conn,
438 int fnid,
439 int *result_buf,
440 int *result_len,
441 int result_is_int,
442 const PQArgBlock *args,
443 int nargs);
444
445/* Accessor functions for PGresult objects */
446extern ExecStatusType PQresultStatus(const PGresult *res);
447extern char *PQresStatus(ExecStatusType status);
448extern char *PQresultErrorMessage(const PGresult *res);
449extern char *PQresultErrorField(const PGresult *res, int fieldcode);
450extern int PQntuples(const PGresult *res);
451extern int PQnfields(const PGresult *res);
452extern int PQbinaryTuples(const PGresult *res);
453extern char *PQfname(const PGresult *res, int field_num);
454extern int PQfnumber(const PGresult *res, const char *field_name);
455extern Oid PQftable(const PGresult *res, int field_num);
456extern int PQftablecol(const PGresult *res, int field_num);
457extern int PQfformat(const PGresult *res, int field_num);
458extern Oid PQftype(const PGresult *res, int field_num);
459extern int PQfsize(const PGresult *res, int field_num);
460extern int PQfmod(const PGresult *res, int field_num);
461extern char *PQcmdStatus(PGresult *res);
462extern char *PQoidStatus(const PGresult *res); /* old and ugly */
463extern Oid PQoidValue(const PGresult *res); /* new and improved */
464extern char *PQcmdTuples(PGresult *res);
465extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
466extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
467extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
468extern int PQnparams(const PGresult *res);
469extern Oid PQparamtype(const PGresult *res, int param_num);
470
471/* Describe prepared statements and portals */
472extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
473extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
474extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
475extern int PQsendDescribePortal(PGconn *conn, const char *portal);
476
477/* Delete a PGresult */
478extern void PQclear(PGresult *res);
479
480/* For freeing other alloc'd results, such as PGnotify structs */
481extern void PQfreemem(void *ptr);
482
483/* Exists for backward compatibility. bjm 2003-03-24 */
484#define PQfreeNotify(ptr) PQfreemem(ptr)
485
486/* Error when no password was given. */
487/* Note: depending on this is deprecated; use PQconnectionNeedsPassword(). */
488#define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
489
490/* Create and manipulate PGresults */
491extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
492extern PGresult *PQcopyResult(const PGresult *src, int flags);
493extern int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs);
494extern void *PQresultAlloc(PGresult *res, size_t nBytes);
495extern int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len);
496
497/* Quoting strings before inclusion in queries. */
498extern size_t PQescapeStringConn(PGconn *conn,
499 char *to, const char *from, size_t length,
500 int *error);
501extern char *PQescapeLiteral(PGconn *conn, const char *str, size_t len);
502extern char *PQescapeIdentifier(PGconn *conn, const char *str, size_t len);
503extern unsigned char *PQescapeByteaConn(PGconn *conn,
504 const unsigned char *from, size_t from_length,
505 size_t *to_length);
506extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
507 size_t *retbuflen);
508
509/* These forms are deprecated! */
510extern size_t PQescapeString(char *to, const char *from, size_t length);
511extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
512 size_t *to_length);
513
514
515
516/* === in fe-print.c === */
517
518extern void PQprint(FILE *fout, /* output stream */
519 const PGresult *res,
520 const PQprintOpt *ps); /* option structure */
521
522/*
523 * really old printing routines
524 */
525extern void PQdisplayTuples(const PGresult *res,
526 FILE *fp, /* where to send the output */
527 int fillAlign, /* pad the fields with spaces */
528 const char *fieldSep, /* field separator */
529 int printHeader, /* display headers? */
530 int quiet);
531
532extern void PQprintTuples(const PGresult *res,
533 FILE *fout, /* output stream */
534 int printAttName, /* print attribute names */
535 int terseOutput, /* delimiter bars */
536 int width); /* width of column, if 0, use variable width */
537
538
539/* === in fe-lobj.c === */
540
541/* Large-object access routines */
542extern int lo_open(PGconn *conn, Oid lobjId, int mode);
543extern int lo_close(PGconn *conn, int fd);
544extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
545extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
546extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
547extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
548extern Oid lo_creat(PGconn *conn, int mode);
549extern Oid lo_create(PGconn *conn, Oid lobjId);
550extern int lo_tell(PGconn *conn, int fd);
551extern pg_int64 lo_tell64(PGconn *conn, int fd);
552extern int lo_truncate(PGconn *conn, int fd, size_t len);
553extern int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
554extern int lo_unlink(PGconn *conn, Oid lobjId);
555extern Oid lo_import(PGconn *conn, const char *filename);
556extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
557extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
558
559/* === in fe-misc.c === */
560
561/* Get the version of the libpq library in use */
562extern int PQlibVersion(void);
563
564/* Determine length of multibyte encoded char at *s */
565extern int PQmblen(const char *s, int encoding);
566
567/* Determine display length of multibyte encoded char at *s */
568extern int PQdsplen(const char *s, int encoding);
569
570/* Get encoding id from environment variable PGCLIENTENCODING */
571extern int PQenv2encoding(void);
572
573/* === in fe-auth.c === */
574
575extern char *PQencryptPassword(const char *passwd, const char *user);
576
577/* === in encnames.c === */
578
579extern int pg_char_to_encoding(const char *name);
580extern const char *pg_encoding_to_char(int encoding);
581extern int pg_valid_server_encoding_id(int encoding);
582
583#ifdef __cplusplus
584}
585#endif
586
587#endif /* LIBPQ_FE_H */
588

Warning: That file was not part of the compilation database. It may have many parsing errors.