PostgreSQL Source Code  git master
libpq-fe.h
Go to the documentation of this file.
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-2021, 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
19 extern "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  * These symbols may be used in compile-time #ifdef tests for the availability
33  * of newer libpq features.
34  */
35 /* Indicates presence of PQenterPipelineMode and friends */
36 #define LIBPQ_HAS_PIPELINING 1
37 /* Indicates presence of PQsetTraceFlags; also new PQtrace output format */
38 #define LIBPQ_HAS_TRACE_FLAGS 1
39 
40 /*
41  * Option flags for PQcopyResult
42  */
43 #define PG_COPYRES_ATTRS 0x01
44 #define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */
45 #define PG_COPYRES_EVENTS 0x04
46 #define PG_COPYRES_NOTICEHOOKS 0x08
47 
48 /* Application-visible enum types */
49 
50 /*
51  * Although it is okay to add to these lists, values which become unused
52  * should never be removed, nor should constants be redefined - that would
53  * break compatibility with existing code.
54  */
55 
56 typedef enum
57 {
60  /* Non-blocking mode only below here */
61 
62  /*
63  * The existence of these should never be relied upon - they should only
64  * be used for user feedback or similar purposes.
65  */
66  CONNECTION_STARTED, /* Waiting for connection to be made. */
67  CONNECTION_MADE, /* Connection OK; waiting to send. */
68  CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the
69  * postmaster. */
70  CONNECTION_AUTH_OK, /* Received authentication; waiting for
71  * backend startup. */
72  CONNECTION_SETENV, /* This state is no longer used. */
73  CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
74  CONNECTION_NEEDED, /* Internal state: connect() needed */
75  CONNECTION_CHECK_WRITABLE, /* Checking if session is read-write. */
76  CONNECTION_CONSUME, /* Consuming any extra messages. */
77  CONNECTION_GSS_STARTUP, /* Negotiating GSSAPI. */
78  CONNECTION_CHECK_TARGET, /* Checking target server properties. */
79  CONNECTION_CHECK_STANDBY /* Checking if server is in standby mode. */
81 
82 typedef enum
83 {
85  PGRES_POLLING_READING, /* These two indicate that one may */
86  PGRES_POLLING_WRITING, /* use select before polling again. */
88  PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards
89  * compatibility */
91 
92 typedef enum
93 {
94  PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
95  PGRES_COMMAND_OK, /* a query command that doesn't return
96  * anything was executed properly by the
97  * backend */
98  PGRES_TUPLES_OK, /* a query command that returns tuples was
99  * executed properly by the backend, PGresult
100  * contains the result tuples */
101  PGRES_COPY_OUT, /* Copy Out data transfer in progress */
102  PGRES_COPY_IN, /* Copy In data transfer in progress */
103  PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
104  * backend */
105  PGRES_NONFATAL_ERROR, /* notice or warning message */
106  PGRES_FATAL_ERROR, /* query failed */
107  PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
108  PGRES_SINGLE_TUPLE, /* single tuple from larger resultset */
109  PGRES_PIPELINE_SYNC, /* pipeline synchronization point */
110  PGRES_PIPELINE_ABORTED /* Command didn't run because of an abort
111  * earlier in a pipeline */
113 
114 typedef enum
115 {
116  PQTRANS_IDLE, /* connection idle */
117  PQTRANS_ACTIVE, /* command in progress */
118  PQTRANS_INTRANS, /* idle, within transaction block */
119  PQTRANS_INERROR, /* idle, within failed transaction */
120  PQTRANS_UNKNOWN /* cannot determine status */
122 
123 typedef enum
124 {
125  PQERRORS_TERSE, /* single-line error messages */
126  PQERRORS_DEFAULT, /* recommended style */
127  PQERRORS_VERBOSE, /* all the facts, ma'am */
128  PQERRORS_SQLSTATE /* only error severity and SQLSTATE code */
129 } PGVerbosity;
130 
131 typedef enum
132 {
133  PQSHOW_CONTEXT_NEVER, /* never show CONTEXT field */
134  PQSHOW_CONTEXT_ERRORS, /* show CONTEXT for errors only (default) */
135  PQSHOW_CONTEXT_ALWAYS /* always show CONTEXT field */
137 
138 /*
139  * PGPing - The ordering of this enum should not be altered because the
140  * values are exposed externally via pg_isready.
141  */
142 
143 typedef enum
144 {
145  PQPING_OK, /* server is accepting connections */
146  PQPING_REJECT, /* server is alive but rejecting connections */
147  PQPING_NO_RESPONSE, /* could not establish connection */
148  PQPING_NO_ATTEMPT /* connection not attempted (bad params) */
149 } PGPing;
150 
151 /*
152  * PGpipelineStatus - Current status of pipeline mode
153  */
154 typedef enum
155 {
160 
161 /* PGconn encapsulates a connection to the backend.
162  * The contents of this struct are not supposed to be known to applications.
163  */
164 typedef struct pg_conn PGconn;
165 
166 /* PGresult encapsulates the result of a query (or more precisely, of a single
167  * SQL command --- a query string given to PQsendQuery can contain multiple
168  * commands and thus return multiple PGresult objects).
169  * The contents of this struct are not supposed to be known to applications.
170  */
171 typedef struct pg_result PGresult;
172 
173 /* PGcancel encapsulates the information needed to cancel a running
174  * query on an existing connection.
175  * The contents of this struct are not supposed to be known to applications.
176  */
177 typedef struct pg_cancel PGcancel;
178 
179 /* PGnotify represents the occurrence of a NOTIFY message.
180  * Ideally this would be an opaque typedef, but it's so simple that it's
181  * unlikely to change.
182  * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
183  * whereas in earlier versions it was always your own backend's PID.
184  */
185 typedef struct pgNotify
186 {
187  char *relname; /* notification condition name */
188  int be_pid; /* process ID of notifying server process */
189  char *extra; /* notification parameter */
190  /* Fields below here are private to libpq; apps should not use 'em */
191  struct pgNotify *next; /* list link */
192 } PGnotify;
193 
194 /* Function types for notice-handling callbacks */
195 typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
196 typedef void (*PQnoticeProcessor) (void *arg, const char *message);
197 
198 /* Print options for PQprint() */
199 typedef char pqbool;
200 
201 typedef struct _PQprintOpt
202 {
203  pqbool header; /* print output field headings and row count */
204  pqbool align; /* fill align the fields */
205  pqbool standard; /* old brain dead format */
206  pqbool html3; /* output html tables */
207  pqbool expanded; /* expand tables */
208  pqbool pager; /* use pager for output if needed */
209  char *fieldSep; /* field separator */
210  char *tableOpt; /* insert to HTML <table ...> */
211  char *caption; /* HTML <caption> */
212  char **fieldName; /* null terminated array of replacement field
213  * names */
214 } PQprintOpt;
215 
216 /* ----------------
217  * Structure for the conninfo parameter definitions returned by PQconndefaults
218  * or PQconninfoParse.
219  *
220  * All fields except "val" point at static strings which must not be altered.
221  * "val" is either NULL or a malloc'd current-value string. PQconninfoFree()
222  * will release both the val strings and the PQconninfoOption array itself.
223  * ----------------
224  */
225 typedef struct _PQconninfoOption
226 {
227  char *keyword; /* The keyword of the option */
228  char *envvar; /* Fallback environment variable name */
229  char *compiled; /* Fallback compiled in default value */
230  char *val; /* Option's current value, or NULL */
231  char *label; /* Label for field in connect dialog */
232  char *dispchar; /* Indicates how to display this field in a
233  * connect dialog. Values are: "" Display
234  * entered value as is "*" Password field -
235  * hide value "D" Debug option - don't show
236  * by default */
237  int dispsize; /* Field size in characters for dialog */
239 
240 /* ----------------
241  * PQArgBlock -- structure for PQfn() arguments
242  * ----------------
243  */
244 typedef struct
245 {
246  int len;
247  int isint;
248  union
249  {
250  int *ptr; /* can't use void (dec compiler barfs) */
251  int integer;
252  } u;
253 } PQArgBlock;
254 
255 /* ----------------
256  * PGresAttDesc -- Data about a single attribute (column) of a query result
257  * ----------------
258  */
259 typedef struct pgresAttDesc
260 {
261  char *name; /* column name */
262  Oid tableid; /* source table, if known */
263  int columnid; /* source column, if known */
264  int format; /* format code for value (text/binary) */
265  Oid typid; /* type id */
266  int typlen; /* type size */
267  int atttypmod; /* type-specific modifier info */
268 } PGresAttDesc;
269 
270 /* ----------------
271  * Exported functions of libpq
272  * ----------------
273  */
274 
275 /* === in fe-connect.c === */
276 
277 /* make a new client connection to the backend */
278 /* Asynchronous (non-blocking) */
279 extern PGconn *PQconnectStart(const char *conninfo);
280 extern PGconn *PQconnectStartParams(const char *const *keywords,
281  const char *const *values, int expand_dbname);
282 extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
283 
284 /* Synchronous (blocking) */
285 extern PGconn *PQconnectdb(const char *conninfo);
286 extern PGconn *PQconnectdbParams(const char *const *keywords,
287  const char *const *values, int expand_dbname);
288 extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
289  const char *pgoptions, const char *pgtty,
290  const char *dbName,
291  const char *login, const char *pwd);
292 
293 #define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
294  PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
295 
296 /* close the current connection and free the PGconn data structure */
297 extern void PQfinish(PGconn *conn);
298 
299 /* get info about connection options known to PQconnectdb */
300 extern PQconninfoOption *PQconndefaults(void);
301 
302 /* parse connection options in same way as PQconnectdb */
303 extern PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
304 
305 /* return the connection options used by a live connection */
307 
308 /* free the data structure returned by PQconndefaults() or PQconninfoParse() */
309 extern void PQconninfoFree(PQconninfoOption *connOptions);
310 
311 /*
312  * close the current connection and reestablish a new one with the same
313  * parameters
314  */
315 /* Asynchronous (non-blocking) */
316 extern int PQresetStart(PGconn *conn);
317 extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
318 
319 /* Synchronous (blocking) */
320 extern void PQreset(PGconn *conn);
321 
322 /* request a cancel structure */
323 extern PGcancel *PQgetCancel(PGconn *conn);
324 
325 /* free a cancel structure */
326 extern void PQfreeCancel(PGcancel *cancel);
327 
328 /* issue a cancel request */
329 extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
330 
331 /* backwards compatible version of PQcancel; not thread-safe */
332 extern int PQrequestCancel(PGconn *conn);
333 
334 /* Accessor functions for PGconn objects */
335 extern char *PQdb(const PGconn *conn);
336 extern char *PQuser(const PGconn *conn);
337 extern char *PQpass(const PGconn *conn);
338 extern char *PQhost(const PGconn *conn);
339 extern char *PQhostaddr(const PGconn *conn);
340 extern char *PQport(const PGconn *conn);
341 extern char *PQtty(const PGconn *conn);
342 extern char *PQoptions(const PGconn *conn);
343 extern ConnStatusType PQstatus(const PGconn *conn);
344 extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
345 extern const char *PQparameterStatus(const PGconn *conn,
346  const char *paramName);
347 extern int PQprotocolVersion(const PGconn *conn);
348 extern int PQserverVersion(const PGconn *conn);
349 extern char *PQerrorMessage(const PGconn *conn);
350 extern int PQsocket(const PGconn *conn);
351 extern int PQbackendPID(const PGconn *conn);
352 extern PGpipelineStatus PQpipelineStatus(const PGconn *conn);
353 extern int PQconnectionNeedsPassword(const PGconn *conn);
354 extern int PQconnectionUsedPassword(const PGconn *conn);
355 extern int PQclientEncoding(const PGconn *conn);
356 extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
357 
358 /* SSL information functions */
359 extern int PQsslInUse(PGconn *conn);
360 extern void *PQsslStruct(PGconn *conn, const char *struct_name);
361 extern const char *PQsslAttribute(PGconn *conn, const char *attribute_name);
362 extern const char *const *PQsslAttributeNames(PGconn *conn);
363 
364 /* Get the OpenSSL structure associated with a connection. Returns NULL for
365  * unencrypted connections or if any other TLS library is in use. */
366 extern void *PQgetssl(PGconn *conn);
367 
368 /* Tell libpq whether it needs to initialize OpenSSL */
369 extern void PQinitSSL(int do_init);
370 
371 /* More detailed way to tell libpq whether it needs to initialize OpenSSL */
372 extern void PQinitOpenSSL(int do_ssl, int do_crypto);
373 
374 /* Return true if GSSAPI encryption is in use */
375 extern int PQgssEncInUse(PGconn *conn);
376 
377 /* Returns GSSAPI context if GSSAPI is in use */
378 extern void *PQgetgssctx(PGconn *conn);
379 
380 /* Set verbosity for PQerrorMessage and PQresultErrorMessage */
381 extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
382 
383 /* Set CONTEXT visibility for PQerrorMessage and PQresultErrorMessage */
384 extern PGContextVisibility PQsetErrorContextVisibility(PGconn *conn,
385  PGContextVisibility show_context);
386 
387 /* Override default notice handling routines */
389  PQnoticeReceiver proc,
390  void *arg);
392  PQnoticeProcessor proc,
393  void *arg);
394 
395 /*
396  * Used to set callback that prevents concurrent access to
397  * non-thread safe functions that libpq needs.
398  * The default implementation uses a libpq internal mutex.
399  * Only required for multithreaded apps that use kerberos
400  * both within their app and for postgresql connections.
401  */
402 typedef void (*pgthreadlock_t) (int acquire);
403 
405 
406 /* === in fe-trace.c === */
407 extern void PQtrace(PGconn *conn, FILE *debug_port);
408 extern void PQuntrace(PGconn *conn);
409 
410 /* flags controlling trace output: */
411 /* omit timestamps from each line */
412 #define PQTRACE_SUPPRESS_TIMESTAMPS (1<<0)
413 /* redact portions of some messages, for testing frameworks */
414 #define PQTRACE_REGRESS_MODE (1<<1)
415 extern void PQsetTraceFlags(PGconn *conn, int flags);
416 
417 /* === in fe-exec.c === */
418 
419 /* Simple synchronous query */
420 extern PGresult *PQexec(PGconn *conn, const char *query);
422  const char *command,
423  int nParams,
424  const Oid *paramTypes,
425  const char *const *paramValues,
426  const int *paramLengths,
427  const int *paramFormats,
428  int resultFormat);
429 extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
430  const char *query, int nParams,
431  const Oid *paramTypes);
433  const char *stmtName,
434  int nParams,
435  const char *const *paramValues,
436  const int *paramLengths,
437  const int *paramFormats,
438  int resultFormat);
439 
440 /* Interface for multiple-result or asynchronous queries */
441 #define PQ_QUERY_PARAM_MAX_LIMIT 65535
442 
443 extern int PQsendQuery(PGconn *conn, const char *query);
444 extern int PQsendQueryParams(PGconn *conn,
445  const char *command,
446  int nParams,
447  const Oid *paramTypes,
448  const char *const *paramValues,
449  const int *paramLengths,
450  const int *paramFormats,
451  int resultFormat);
452 extern int PQsendPrepare(PGconn *conn, const char *stmtName,
453  const char *query, int nParams,
454  const Oid *paramTypes);
455 extern int PQsendQueryPrepared(PGconn *conn,
456  const char *stmtName,
457  int nParams,
458  const char *const *paramValues,
459  const int *paramLengths,
460  const int *paramFormats,
461  int resultFormat);
462 extern int PQsetSingleRowMode(PGconn *conn);
463 extern PGresult *PQgetResult(PGconn *conn);
464 
465 /* Routines for managing an asynchronous query */
466 extern int PQisBusy(PGconn *conn);
467 extern int PQconsumeInput(PGconn *conn);
468 
469 /* Routines for pipeline mode management */
470 extern int PQenterPipelineMode(PGconn *conn);
471 extern int PQexitPipelineMode(PGconn *conn);
472 extern int PQpipelineSync(PGconn *conn);
473 extern int PQsendFlushRequest(PGconn *conn);
474 
475 /* LISTEN/NOTIFY support */
476 extern PGnotify *PQnotifies(PGconn *conn);
477 
478 /* Routines for copy in/out */
479 extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
480 extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
481 extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
482 
483 /* Deprecated routines for copy in/out */
484 extern int PQgetline(PGconn *conn, char *string, int length);
485 extern int PQputline(PGconn *conn, const char *string);
486 extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
487 extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
488 extern int PQendcopy(PGconn *conn);
489 
490 /* Set blocking/nonblocking connection to the backend */
491 extern int PQsetnonblocking(PGconn *conn, int arg);
492 extern int PQisnonblocking(const PGconn *conn);
493 extern int PQisthreadsafe(void);
494 extern PGPing PQping(const char *conninfo);
495 extern PGPing PQpingParams(const char *const *keywords,
496  const char *const *values, int expand_dbname);
497 
498 /* Force the write buffer to be written (or at least try) */
499 extern int PQflush(PGconn *conn);
500 
501 /*
502  * "Fast path" interface --- not really recommended for application
503  * use
504  */
505 extern PGresult *PQfn(PGconn *conn,
506  int fnid,
507  int *result_buf,
508  int *result_len,
509  int result_is_int,
510  const PQArgBlock *args,
511  int nargs);
512 
513 /* Accessor functions for PGresult objects */
514 extern ExecStatusType PQresultStatus(const PGresult *res);
515 extern char *PQresStatus(ExecStatusType status);
516 extern char *PQresultErrorMessage(const PGresult *res);
517 extern char *PQresultVerboseErrorMessage(const PGresult *res,
518  PGVerbosity verbosity,
519  PGContextVisibility show_context);
520 extern char *PQresultErrorField(const PGresult *res, int fieldcode);
521 extern int PQntuples(const PGresult *res);
522 extern int PQnfields(const PGresult *res);
523 extern int PQbinaryTuples(const PGresult *res);
524 extern char *PQfname(const PGresult *res, int field_num);
525 extern int PQfnumber(const PGresult *res, const char *field_name);
526 extern Oid PQftable(const PGresult *res, int field_num);
527 extern int PQftablecol(const PGresult *res, int field_num);
528 extern int PQfformat(const PGresult *res, int field_num);
529 extern Oid PQftype(const PGresult *res, int field_num);
530 extern int PQfsize(const PGresult *res, int field_num);
531 extern int PQfmod(const PGresult *res, int field_num);
532 extern char *PQcmdStatus(PGresult *res);
533 extern char *PQoidStatus(const PGresult *res); /* old and ugly */
534 extern Oid PQoidValue(const PGresult *res); /* new and improved */
535 extern char *PQcmdTuples(PGresult *res);
536 extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
537 extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
538 extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
539 extern int PQnparams(const PGresult *res);
540 extern Oid PQparamtype(const PGresult *res, int param_num);
541 
542 /* Describe prepared statements and portals */
543 extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
544 extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
545 extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
546 extern int PQsendDescribePortal(PGconn *conn, const char *portal);
547 
548 /* Delete a PGresult */
549 extern void PQclear(PGresult *res);
550 
551 /* For freeing other alloc'd results, such as PGnotify structs */
552 extern void PQfreemem(void *ptr);
553 
554 /* Exists for backward compatibility. bjm 2003-03-24 */
555 #define PQfreeNotify(ptr) PQfreemem(ptr)
556 
557 /* Error when no password was given. */
558 /* Note: depending on this is deprecated; use PQconnectionNeedsPassword(). */
559 #define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
560 
561 /* Create and manipulate PGresults */
562 extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
563 extern PGresult *PQcopyResult(const PGresult *src, int flags);
564 extern int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs);
565 extern void *PQresultAlloc(PGresult *res, size_t nBytes);
566 extern size_t PQresultMemorySize(const PGresult *res);
567 extern int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len);
568 
569 /* Quoting strings before inclusion in queries. */
570 extern size_t PQescapeStringConn(PGconn *conn,
571  char *to, const char *from, size_t length,
572  int *error);
573 extern char *PQescapeLiteral(PGconn *conn, const char *str, size_t len);
574 extern char *PQescapeIdentifier(PGconn *conn, const char *str, size_t len);
575 extern unsigned char *PQescapeByteaConn(PGconn *conn,
576  const unsigned char *from, size_t from_length,
577  size_t *to_length);
578 extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
579  size_t *retbuflen);
580 
581 /* These forms are deprecated! */
582 extern size_t PQescapeString(char *to, const char *from, size_t length);
583 extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
584  size_t *to_length);
585 
586 
587 
588 /* === in fe-print.c === */
589 
590 extern void PQprint(FILE *fout, /* output stream */
591  const PGresult *res,
592  const PQprintOpt *ps); /* option structure */
593 
594 /*
595  * really old printing routines
596  */
597 extern void PQdisplayTuples(const PGresult *res,
598  FILE *fp, /* where to send the output */
599  int fillAlign, /* pad the fields with spaces */
600  const char *fieldSep, /* field separator */
601  int printHeader, /* display headers? */
602  int quiet);
603 
604 extern void PQprintTuples(const PGresult *res,
605  FILE *fout, /* output stream */
606  int PrintAttNames, /* print attribute names */
607  int TerseOutput, /* delimiter bars */
608  int colWidth); /* width of column, if 0, use
609  * variable width */
610 
611 
612 /* === in fe-lobj.c === */
613 
614 /* Large-object access routines */
615 extern int lo_open(PGconn *conn, Oid lobjId, int mode);
616 extern int lo_close(PGconn *conn, int fd);
617 extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
618 extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
619 extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
620 extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
621 extern Oid lo_creat(PGconn *conn, int mode);
622 extern Oid lo_create(PGconn *conn, Oid lobjId);
623 extern int lo_tell(PGconn *conn, int fd);
624 extern pg_int64 lo_tell64(PGconn *conn, int fd);
625 extern int lo_truncate(PGconn *conn, int fd, size_t len);
626 extern int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
627 extern int lo_unlink(PGconn *conn, Oid lobjId);
628 extern Oid lo_import(PGconn *conn, const char *filename);
629 extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
630 extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
631 
632 /* === in fe-misc.c === */
633 
634 /* Get the version of the libpq library in use */
635 extern int PQlibVersion(void);
636 
637 /* Determine length of multibyte encoded char at *s */
638 extern int PQmblen(const char *s, int encoding);
639 
640 /* Same, but not more than the distance to the end of string s */
641 extern int PQmblenBounded(const char *s, int encoding);
642 
643 /* Determine display length of multibyte encoded char at *s */
644 extern int PQdsplen(const char *s, int encoding);
645 
646 /* Get encoding id from environment variable PGCLIENTENCODING */
647 extern int PQenv2encoding(void);
648 
649 /* === in fe-auth.c === */
650 
651 extern char *PQencryptPassword(const char *passwd, const char *user);
652 extern char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm);
653 
654 /* === in encnames.c === */
655 
656 extern int pg_char_to_encoding(const char *name);
657 extern const char *pg_encoding_to_char(int encoding);
658 extern int pg_valid_server_encoding_id(int encoding);
659 
660 /* === in fe-secure-openssl.c === */
661 
662 /* Support for overriding sslpassword handling with a callback */
663 typedef int (*PQsslKeyPassHook_OpenSSL_type) (char *buf, int size, PGconn *conn);
666 extern int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn);
667 
668 #ifdef __cplusplus
669 }
670 #endif
671 
672 #endif /* LIBPQ_FE_H */
int PQclientEncoding(const PGconn *conn)
Definition: fe-connect.c:6821
PGresult * PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:2207
void PQtrace(PGconn *conn, FILE *debug_port)
Definition: fe-trace.c:35
int PQsocket(const PGconn *conn)
Definition: fe-connect.c:6770
void PQinitSSL(int do_init)
Definition: fe-secure.c:139
Oid PQftable(const PGresult *res, int field_num)
Definition: fe-exec.c:3453
char * PQport(const PGconn *conn)
Definition: fe-connect.c:6659
char * extra
Definition: libpq-fe.h:189
void * PQgetssl(PGconn *conn)
ConnStatusType
Definition: libpq-fe.h:56
static PgChecksumMode mode
Definition: pg_checksums.c:65
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3256
int PQsendQueryParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:1438
size_t PQescapeString(char *to, const char *from, size_t length)
Definition: fe-exec.c:3931
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
Definition: fe-connect.c:5337
void(* PQnoticeReceiver)(void *arg, const PGresult *res)
Definition: libpq-fe.h:195
void PQsetTraceFlags(PGconn *conn, int flags)
Definition: fe-trace.c:64
int lo_tell(PGconn *conn, int fd)
Definition: fe-lobj.c:522
void * PQsslStruct(PGconn *conn, const char *struct_name)
int lo_export(PGconn *conn, Oid lobjId, const char *filename)
Definition: fe-lobj.c:757
PGPing PQping(const char *conninfo)
Definition: fe-connect.c:729
void PQuntrace(PGconn *conn)
Definition: fe-trace.c:49
int PQgetCopyData(PGconn *conn, char **buffer, int async)
Definition: fe-exec.c:2668
static void error(void)
Definition: sql-dyntest.c:147
int PQfmod(const PGresult *res, int field_num)
Definition: fe-exec.c:3508
int PQisnonblocking(const PGconn *conn)
Definition: fe-exec.c:3747
int PQmblen(const char *s, int encoding)
Definition: fe-misc.c:1192
char * PQpass(const PGconn *conn)
Definition: fe-connect.c:6606
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
Definition: fe-exec.c:4075
PGresult * PQcopyResult(const PGresult *src, int flags)
Definition: fe-exec.c:299
int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)
Definition: fe-exec.c:2754
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:6598
int pg_valid_server_encoding_id(int encoding)
Definition: encnames.c:514
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
Definition: fe-exec.c:2544
void PQreset(PGconn *conn)
Definition: fe-connect.c:4245
int PQresetStart(PGconn *conn)
Definition: fe-connect.c:4286
pg_int64 lo_tell64(PGconn *conn, int fd)
Definition: fe-lobj.c:555
int PQbinaryTuples(const PGresult *res)
Definition: fe-exec.c:3264
PGconn * PQconnectStartParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:760
int lo_read(PGconn *conn, int fd, char *buf, size_t len)
Definition: fe-lobj.c:248
void PQfreeCancel(PGcancel *cancel)
Definition: fe-connect.c:4375
void(* PQnoticeProcessor)(void *arg, const char *message)
Definition: libpq-fe.h:196
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6590
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
int PQisthreadsafe(void)
Definition: fe-exec.c:3754
PGcancel * PQgetCancel(PGconn *conn)
Definition: fe-connect.c:4352
unsigned char * PQescapeByteaConn(PGconn *conn, const unsigned char *from, size_t from_length, size_t *to_length)
Definition: fe-exec.c:4219
int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len)
Definition: fe-exec.c:436
int PQfformat(const PGresult *res, int field_num)
Definition: fe-exec.c:3475
const char * pghost
Definition: pgbench.c:280
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void * PQgetgssctx(PGconn *conn)
PGresult * PQfn(PGconn *conn, int fnid, int *result_buf, int *result_len, int result_is_int, const PQArgBlock *args, int nargs)
Definition: fe-exec.c:2833
char * PQcmdTuples(PGresult *res)
Definition: fe-exec.c:3589
int PQconnectionUsedPassword(const PGconn *conn)
Definition: fe-connect.c:6810
ExecStatusType
Definition: libpq-fe.h:92
PGresult * PQexecPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:2254
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3178
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
Definition: fe-connect.c:6912
pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler)
Definition: fe-connect.c:7311
void PQinitOpenSSL(int do_ssl, int do_crypto)
Definition: fe-secure.c:151
char * PQtty(const PGconn *conn)
Definition: fe-connect.c:6675
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4231
unsigned int Oid
Definition: postgres_ext.h:31
int PQlibVersion(void)
Definition: fe-misc.c:66
pqbool standard
Definition: libpq-fe.h:205
const char *const * PQsslAttributeNames(PGconn *conn)
static int fd(const char *x, int i)
Definition: preproc-init.c:105
int columnid
Definition: libpq-fe.h:263
char * fieldSep
Definition: libpq-fe.h:209
const char * dbName
Definition: pgbench.c:283
PG_INT64_TYPE pg_int64
Definition: postgres_ext.h:47
Oid lo_create(PGconn *conn, Oid lobjId)
Definition: fe-lobj.c:480
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6699
Oid lo_creat(PGconn *conn, int mode)
Definition: fe-lobj.c:444
PQconninfoOption * PQconndefaults(void)
Definition: fe-connect.c:1472
char * PQoptions(const PGconn *conn)
Definition: fe-connect.c:6683
PGconn * PQconnectStart(const char *conninfo)
Definition: fe-connect.c:841
void PQconninfoFree(PQconninfoOption *connOptions)
Definition: fe-connect.c:6572
int PQpipelineSync(PGconn *conn)
Definition: fe-exec.c:3077
int PQsetnonblocking(PGconn *conn, int arg)
Definition: fe-exec.c:3710
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:588
int PQnparams(const PGresult *res)
Definition: fe-exec.c:3681
int PQgetline(PGconn *conn, char *string, int length)
Definition: fe-exec.c:2707
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:96
int PQprotocolVersion(const PGconn *conn)
Definition: fe-connect.c:6724
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:657
int lo_lseek(PGconn *conn, int fd, int offset, int whence)
Definition: fe-lobj.c:349
void(* pgthreadlock_t)(int acquire)
Definition: libpq-fe.h:402
int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
int PQputCopyEnd(PGconn *conn, const char *errormsg)
Definition: fe-exec.c:2600
int PQsslInUse(PGconn *conn)
Definition: fe-secure.c:127
PGconn * conn
Definition: streamutil.c:54
int be_pid
Definition: libpq-fe.h:188
void PQprint(FILE *fout, const PGresult *res, const PQprintOpt *ps)
Definition: fe-print.c:68
int PQsendDescribePortal(PGconn *conn, const char *portal)
Definition: fe-exec.c:2435
int PQftablecol(const PGresult *res, int field_num)
Definition: fe-exec.c:3464
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition: fe-lobj.c:57
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:3233
char * PQresultVerboseErrorMessage(const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
Definition: fe-exec.c:3202
static char * buf
Definition: pg_test_fsync.c:68
char * PQencryptPassword(const char *passwd, const char *user)
Definition: fe-auth.c:1175
PGpipelineStatus PQpipelineStatus(const PGconn *conn)
Definition: fe-connect.c:6786
int PQputline(PGconn *conn, const char *string)
Definition: fe-exec.c:2771
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
Definition: fe-connect.c:6871
pqbool align
Definition: libpq-fe.h:204
size_t PQresultMemorySize(const PGresult *res)
Definition: fe-exec.c:639
char * relname
Definition: libpq-fe.h:187
PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook_OpenSSL(void)
int PQmblenBounded(const char *s, int encoding)
Definition: fe-misc.c:1202
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2193
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3653
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
Definition: fe-exec.c:4069
int PQsendDescribePrepared(PGconn *conn, const char *stmt)
Definition: fe-exec.c:2422
int PQrequestCancel(PGconn *conn)
Definition: fe-connect.c:4532
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:6709
int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
Definition: fe-exec.c:1484
void PQprintTuples(const PGresult *res, FILE *fout, int PrintAttNames, int TerseOutput, int colWidth)
Definition: fe-print.c:689
int PQenterPipelineMode(PGconn *conn)
Definition: fe-exec.c:2894
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
Definition: fe-connect.c:6895
int PQsendFlushRequest(PGconn *conn)
Definition: fe-exec.c:3144
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:6623
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3356
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6744
char * PQcmdStatus(PGresult *res)
Definition: fe-exec.c:3519
void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook)
char * PQhostaddr(const PGconn *conn)
Definition: fe-connect.c:6646
int PQsetSingleRowMode(PGconn *conn)
Definition: fe-exec.c:1876
char * caption
Definition: libpq-fe.h:211
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:676
char * PQresStatus(ExecStatusType status)
Definition: fe-exec.c:3186
pqbool pager
Definition: libpq-fe.h:208
Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId)
Definition: fe-lobj.c:649
int PQconsumeInput(PGconn *conn)
Definition: fe-exec.c:1904
char * PQresultErrorMessage(const PGresult *res)
Definition: fe-exec.c:3194
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3486
PGContextVisibility
Definition: libpq-fe.h:131
int PQconnectionNeedsPassword(const PGconn *conn)
Definition: fe-connect.c:6795
struct pgNotify * next
Definition: libpq-fe.h:191
void * PQresultAlloc(PGresult *res, size_t nBytes)
Definition: fe-exec.c:523
PGVerbosity
Definition: libpq-fe.h:123
PostgresPollingStatusType PQresetPoll(PGconn *conn)
Definition: fe-connect.c:4305
int atttypmod
Definition: libpq-fe.h:267
PGpipelineStatus
Definition: libpq-fe.h:154
static struct @143 value
unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
Definition: fe-exec.c:4259
const char * PQsslAttribute(PGconn *conn, const char *attribute_name)
struct pgresAttDesc PGresAttDesc
PGTransactionStatusType
Definition: libpq-fe.h:114
int PQgssEncInUse(PGconn *conn)
int PQexitPipelineMode(PGconn *conn)
Definition: fe-exec.c:2926
unsigned char * PQescapeBytea(const unsigned char *from, size_t from_length, size_t *to_length)
Definition: fe-exec.c:4234
PostgresPollingStatusType PQconnectPoll(PGconn *conn)
Definition: fe-connect.c:2246
Oid lo_import(PGconn *conn, const char *filename)
Definition: fe-lobj.c:634
struct _PQconninfoOption PQconninfoOption
int PQisBusy(PGconn *conn)
Definition: fe-exec.c:1951
int PQendcopy(PGconn *conn)
Definition: fe-exec.c:2802
char ** fieldName
Definition: libpq-fe.h:212
pqbool expanded
Definition: libpq-fe.h:207
PGconn * PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd)
Definition: fe-connect.c:1510
int lo_unlink(PGconn *conn, Oid lobjId)
Definition: fe-lobj.c:597
int lo_truncate(PGconn *conn, int fd, size_t len)
Definition: fe-lobj.c:131
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3667
int lo_write(PGconn *conn, int fd, const char *buf, size_t len)
Definition: fe-lobj.c:299
static void do_init(void)
Definition: pg_ctl.c:829
int32 encoding
Definition: pg_database.h:41
PGresult * PQprepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
Definition: fe-exec.c:2237
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:1978
int PQsetClientEncoding(PGconn *conn, const char *encoding)
Definition: fe-connect.c:6829
PGconn * PQconnectdb(const char *conninfo)
Definition: fe-connect.c:713
void PQfreemem(void *ptr)
Definition: fe-exec.c:3796
const char * name
Definition: encode.c:561
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6691
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition: fe-connect.c:4507
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3497
pqbool html3
Definition: libpq-fe.h:206
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3334
char * tableOpt
Definition: libpq-fe.h:210
static Datum values[MAXATTR]
Definition: bootstrap.c:156
PostgresPollingStatusType
Definition: libpq-fe.h:82
void PQclear(PGresult *res)
Definition: fe-exec.c:694
static char * filename
Definition: pg_dumpall.c:92
char * PQoidStatus(const PGresult *res)
Definition: fe-exec.c:3532
static char * user
Definition: pg_regress.c:95
Oid PQoidValue(const PGresult *res)
Definition: fe-exec.c:3560
int errmsg(const char *fmt,...)
Definition: elog.c:909
PQconninfoOption * PQconninfo(PGconn *conn)
Definition: fe-connect.c:6528
pqbool header
Definition: libpq-fe.h:203
int lo_truncate64(PGconn *conn, int fd, pg_int64 len)
Definition: fe-lobj.c:197
int PQdsplen(const char *s, int encoding)
Definition: fe-misc.c:1212
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
Definition: fe-connect.c:6883
char * name
Definition: libpq-fe.h:261
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
Definition: fe-exec.c:146
void * arg
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
Definition: fe-auth.c:1217
int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:1584
int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs)
Definition: fe-exec.c:234
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
Definition: fe-exec.c:3910
PGPing
Definition: libpq-fe.h:143
int PQputnbytes(PGconn *conn, const char *buffer, int nbytes)
Definition: fe-exec.c:2781
int isint
Definition: libpq-fe.h:247
void PQdisplayTuples(const PGresult *res, FILE *fp, int fillAlign, const char *fieldSep, int printHeader, int quiet)
Definition: fe-print.c:591
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6734
int PQenv2encoding(void)
Definition: fe-misc.c:1221
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227
int(* PQsslKeyPassHook_OpenSSL_type)(char *buf, int size, PGconn *conn)
Definition: libpq-fe.h:663
int PQbackendPID(const PGconn *conn)
Definition: fe-connect.c:6778
int PQflush(PGconn *conn)
Definition: fe-exec.c:3766
struct pgNotify PGnotify
char pqbool
Definition: libpq-fe.h:199
struct _PQprintOpt PQprintOpt
Oid PQparamtype(const PGresult *res, int param_num)
Definition: fe-exec.c:3692
PGresult * PQdescribePortal(PGconn *conn, const char *portal)
Definition: fe-exec.c:2405
int pg_char_to_encoding(const char *name)
Definition: encnames.c:550
int * ptr
Definition: libpq-fe.h:250
const char * pgport
Definition: pgbench.c:281
int integer
Definition: libpq-fe.h:251
pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence)
Definition: fe-lobj.c:390
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1326
PGnotify * PQnotifies(PGconn *conn)
Definition: fe-exec.c:2516
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
Definition: fe-exec.c:2386