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