libpq-fe.h 24 KB

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