00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef LIBPQ_FE_H
00016 #define LIBPQ_FE_H
00017
00018 #ifdef __cplusplus
00019 extern "C"
00020 {
00021 #endif
00022
00023 #include <stdio.h>
00024
00025
00026
00027
00028
00029 #include "postgres_ext.h"
00030
00031
00032
00033
00034 #define PG_COPYRES_ATTRS 0x01
00035 #define PG_COPYRES_TUPLES 0x02
00036 #define PG_COPYRES_EVENTS 0x04
00037 #define PG_COPYRES_NOTICEHOOKS 0x08
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 typedef enum
00048 {
00049 CONNECTION_OK,
00050 CONNECTION_BAD,
00051
00052
00053
00054
00055
00056
00057 CONNECTION_STARTED,
00058 CONNECTION_MADE,
00059 CONNECTION_AWAITING_RESPONSE,
00060
00061 CONNECTION_AUTH_OK,
00062
00063 CONNECTION_SETENV,
00064 CONNECTION_SSL_STARTUP,
00065 CONNECTION_NEEDED
00066 } ConnStatusType;
00067
00068 typedef enum
00069 {
00070 PGRES_POLLING_FAILED = 0,
00071 PGRES_POLLING_READING,
00072 PGRES_POLLING_WRITING,
00073 PGRES_POLLING_OK,
00074 PGRES_POLLING_ACTIVE
00075
00076 } PostgresPollingStatusType;
00077
00078 typedef enum
00079 {
00080 PGRES_EMPTY_QUERY = 0,
00081 PGRES_COMMAND_OK,
00082
00083
00084 PGRES_TUPLES_OK,
00085
00086
00087 PGRES_COPY_OUT,
00088 PGRES_COPY_IN,
00089 PGRES_BAD_RESPONSE,
00090
00091 PGRES_NONFATAL_ERROR,
00092 PGRES_FATAL_ERROR,
00093 PGRES_COPY_BOTH,
00094 PGRES_SINGLE_TUPLE
00095 } ExecStatusType;
00096
00097 typedef enum
00098 {
00099 PQTRANS_IDLE,
00100 PQTRANS_ACTIVE,
00101 PQTRANS_INTRANS,
00102 PQTRANS_INERROR,
00103 PQTRANS_UNKNOWN
00104 } PGTransactionStatusType;
00105
00106 typedef enum
00107 {
00108 PQERRORS_TERSE,
00109 PQERRORS_DEFAULT,
00110 PQERRORS_VERBOSE
00111 } PGVerbosity;
00112
00113
00114
00115
00116
00117
00118 typedef enum
00119 {
00120 PQPING_OK,
00121 PQPING_REJECT,
00122 PQPING_NO_RESPONSE,
00123 PQPING_NO_ATTEMPT
00124 } PGPing;
00125
00126
00127
00128
00129 typedef struct pg_conn PGconn;
00130
00131
00132
00133
00134
00135
00136 typedef struct pg_result PGresult;
00137
00138
00139
00140
00141
00142 typedef struct pg_cancel PGcancel;
00143
00144
00145
00146
00147
00148
00149
00150 typedef struct pgNotify
00151 {
00152 char *relname;
00153 int be_pid;
00154 char *extra;
00155
00156 struct pgNotify *next;
00157 } PGnotify;
00158
00159
00160 typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
00161 typedef void (*PQnoticeProcessor) (void *arg, const char *message);
00162
00163
00164 typedef char pqbool;
00165
00166 typedef struct _PQprintOpt
00167 {
00168 pqbool header;
00169 pqbool align;
00170 pqbool standard;
00171 pqbool html3;
00172 pqbool expanded;
00173 pqbool pager;
00174 char *fieldSep;
00175 char *tableOpt;
00176 char *caption;
00177 char **fieldName;
00178
00179 } PQprintOpt;
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 typedef struct _PQconninfoOption
00191 {
00192 char *keyword;
00193 char *envvar;
00194 char *compiled;
00195 char *val;
00196 char *label;
00197 char *dispchar;
00198
00199
00200
00201
00202 int dispsize;
00203 } PQconninfoOption;
00204
00205
00206
00207
00208
00209 typedef struct
00210 {
00211 int len;
00212 int isint;
00213 union
00214 {
00215 int *ptr;
00216 int integer;
00217 } u;
00218 } PQArgBlock;
00219
00220
00221
00222
00223
00224 typedef struct pgresAttDesc
00225 {
00226 char *name;
00227 Oid tableid;
00228 int columnid;
00229 int format;
00230 Oid typid;
00231 int typlen;
00232 int atttypmod;
00233 } PGresAttDesc;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 extern PGconn *PQconnectStart(const char *conninfo);
00245 extern PGconn *PQconnectStartParams(const char *const * keywords,
00246 const char *const * values, int expand_dbname);
00247 extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
00248
00249
00250 extern PGconn *PQconnectdb(const char *conninfo);
00251 extern PGconn *PQconnectdbParams(const char *const * keywords,
00252 const char *const * values, int expand_dbname);
00253 extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
00254 const char *pgoptions, const char *pgtty,
00255 const char *dbName,
00256 const char *login, const char *pwd);
00257
00258 #define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
00259 PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
00260
00261
00262 extern void PQfinish(PGconn *conn);
00263
00264
00265 extern PQconninfoOption *PQconndefaults(void);
00266
00267
00268 extern PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
00269
00270
00271 extern PQconninfoOption *PQconninfo(PGconn *conn);
00272
00273
00274 extern void PQconninfoFree(PQconninfoOption *connOptions);
00275
00276
00277
00278
00279
00280
00281 extern int PQresetStart(PGconn *conn);
00282 extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
00283
00284
00285 extern void PQreset(PGconn *conn);
00286
00287
00288 extern PGcancel *PQgetCancel(PGconn *conn);
00289
00290
00291 extern void PQfreeCancel(PGcancel *cancel);
00292
00293
00294 extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
00295
00296
00297 extern int PQrequestCancel(PGconn *conn);
00298
00299
00300 extern char *PQdb(const PGconn *conn);
00301 extern char *PQuser(const PGconn *conn);
00302 extern char *PQpass(const PGconn *conn);
00303 extern char *PQhost(const PGconn *conn);
00304 extern char *PQport(const PGconn *conn);
00305 extern char *PQtty(const PGconn *conn);
00306 extern char *PQoptions(const PGconn *conn);
00307 extern ConnStatusType PQstatus(const PGconn *conn);
00308 extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
00309 extern const char *PQparameterStatus(const PGconn *conn,
00310 const char *paramName);
00311 extern int PQprotocolVersion(const PGconn *conn);
00312 extern int PQserverVersion(const PGconn *conn);
00313 extern char *PQerrorMessage(const PGconn *conn);
00314 extern int PQsocket(const PGconn *conn);
00315 extern int PQbackendPID(const PGconn *conn);
00316 extern int PQconnectionNeedsPassword(const PGconn *conn);
00317 extern int PQconnectionUsedPassword(const PGconn *conn);
00318 extern int PQclientEncoding(const PGconn *conn);
00319 extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
00320
00321
00322
00323 extern void *PQgetssl(PGconn *conn);
00324
00325
00326 extern void PQinitSSL(int do_init);
00327
00328
00329 extern void PQinitOpenSSL(int do_ssl, int do_crypto);
00330
00331
00332 extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
00333
00334
00335 extern void PQtrace(PGconn *conn, FILE *debug_port);
00336 extern void PQuntrace(PGconn *conn);
00337
00338
00339 extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
00340 PQnoticeReceiver proc,
00341 void *arg);
00342 extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
00343 PQnoticeProcessor proc,
00344 void *arg);
00345
00346
00347
00348
00349
00350
00351
00352
00353 typedef void (*pgthreadlock_t) (int acquire);
00354
00355 extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
00356
00357
00358
00359
00360 extern PGresult *PQexec(PGconn *conn, const char *query);
00361 extern PGresult *PQexecParams(PGconn *conn,
00362 const char *command,
00363 int nParams,
00364 const Oid *paramTypes,
00365 const char *const * paramValues,
00366 const int *paramLengths,
00367 const int *paramFormats,
00368 int resultFormat);
00369 extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
00370 const char *query, int nParams,
00371 const Oid *paramTypes);
00372 extern PGresult *PQexecPrepared(PGconn *conn,
00373 const char *stmtName,
00374 int nParams,
00375 const char *const * paramValues,
00376 const int *paramLengths,
00377 const int *paramFormats,
00378 int resultFormat);
00379
00380
00381 extern int PQsendQuery(PGconn *conn, const char *query);
00382 extern int PQsendQueryParams(PGconn *conn,
00383 const char *command,
00384 int nParams,
00385 const Oid *paramTypes,
00386 const char *const * paramValues,
00387 const int *paramLengths,
00388 const int *paramFormats,
00389 int resultFormat);
00390 extern int PQsendPrepare(PGconn *conn, const char *stmtName,
00391 const char *query, int nParams,
00392 const Oid *paramTypes);
00393 extern int PQsendQueryPrepared(PGconn *conn,
00394 const char *stmtName,
00395 int nParams,
00396 const char *const * paramValues,
00397 const int *paramLengths,
00398 const int *paramFormats,
00399 int resultFormat);
00400 extern int PQsetSingleRowMode(PGconn *conn);
00401 extern PGresult *PQgetResult(PGconn *conn);
00402
00403
00404 extern int PQisBusy(PGconn *conn);
00405 extern int PQconsumeInput(PGconn *conn);
00406
00407
00408 extern PGnotify *PQnotifies(PGconn *conn);
00409
00410
00411 extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
00412 extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
00413 extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
00414
00415
00416 extern int PQgetline(PGconn *conn, char *string, int length);
00417 extern int PQputline(PGconn *conn, const char *string);
00418 extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
00419 extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
00420 extern int PQendcopy(PGconn *conn);
00421
00422
00423 extern int PQsetnonblocking(PGconn *conn, int arg);
00424 extern int PQisnonblocking(const PGconn *conn);
00425 extern int PQisthreadsafe(void);
00426 extern PGPing PQping(const char *conninfo);
00427 extern PGPing PQpingParams(const char *const * keywords,
00428 const char *const * values, int expand_dbname);
00429
00430
00431 extern int PQflush(PGconn *conn);
00432
00433
00434
00435
00436
00437 extern PGresult *PQfn(PGconn *conn,
00438 int fnid,
00439 int *result_buf,
00440 int *result_len,
00441 int result_is_int,
00442 const PQArgBlock *args,
00443 int nargs);
00444
00445
00446 extern ExecStatusType PQresultStatus(const PGresult *res);
00447 extern char *PQresStatus(ExecStatusType status);
00448 extern char *PQresultErrorMessage(const PGresult *res);
00449 extern char *PQresultErrorField(const PGresult *res, int fieldcode);
00450 extern int PQntuples(const PGresult *res);
00451 extern int PQnfields(const PGresult *res);
00452 extern int PQbinaryTuples(const PGresult *res);
00453 extern char *PQfname(const PGresult *res, int field_num);
00454 extern int PQfnumber(const PGresult *res, const char *field_name);
00455 extern Oid PQftable(const PGresult *res, int field_num);
00456 extern int PQftablecol(const PGresult *res, int field_num);
00457 extern int PQfformat(const PGresult *res, int field_num);
00458 extern Oid PQftype(const PGresult *res, int field_num);
00459 extern int PQfsize(const PGresult *res, int field_num);
00460 extern int PQfmod(const PGresult *res, int field_num);
00461 extern char *PQcmdStatus(PGresult *res);
00462 extern char *PQoidStatus(const PGresult *res);
00463 extern Oid PQoidValue(const PGresult *res);
00464 extern char *PQcmdTuples(PGresult *res);
00465 extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
00466 extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
00467 extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
00468 extern int PQnparams(const PGresult *res);
00469 extern Oid PQparamtype(const PGresult *res, int param_num);
00470
00471
00472 extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
00473 extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
00474 extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
00475 extern int PQsendDescribePortal(PGconn *conn, const char *portal);
00476
00477
00478 extern void PQclear(PGresult *res);
00479
00480
00481 extern void PQfreemem(void *ptr);
00482
00483
00484 #define PQfreeNotify(ptr) PQfreemem(ptr)
00485
00486
00487
00488 #define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
00489
00490
00491 extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
00492 extern PGresult *PQcopyResult(const PGresult *src, int flags);
00493 extern int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs);
00494 extern void *PQresultAlloc(PGresult *res, size_t nBytes);
00495 extern int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len);
00496
00497
00498 extern size_t PQescapeStringConn(PGconn *conn,
00499 char *to, const char *from, size_t length,
00500 int *error);
00501 extern char *PQescapeLiteral(PGconn *conn, const char *str, size_t len);
00502 extern char *PQescapeIdentifier(PGconn *conn, const char *str, size_t len);
00503 extern unsigned char *PQescapeByteaConn(PGconn *conn,
00504 const unsigned char *from, size_t from_length,
00505 size_t *to_length);
00506 extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
00507 size_t *retbuflen);
00508
00509
00510 extern size_t PQescapeString(char *to, const char *from, size_t length);
00511 extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
00512 size_t *to_length);
00513
00514
00515
00516
00517
00518 extern void PQprint(FILE *fout,
00519 const PGresult *res,
00520 const PQprintOpt *ps);
00521
00522
00523
00524
00525 extern void PQdisplayTuples(const PGresult *res,
00526 FILE *fp,
00527 int fillAlign,
00528 const char *fieldSep,
00529 int printHeader,
00530 int quiet);
00531
00532 extern void PQprintTuples(const PGresult *res,
00533 FILE *fout,
00534 int printAttName,
00535 int terseOutput,
00536 int width);
00537
00538
00539
00540
00541
00542 extern int lo_open(PGconn *conn, Oid lobjId, int mode);
00543 extern int lo_close(PGconn *conn, int fd);
00544 extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
00545 extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
00546 extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
00547 extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
00548 extern Oid lo_creat(PGconn *conn, int mode);
00549 extern Oid lo_create(PGconn *conn, Oid lobjId);
00550 extern int lo_tell(PGconn *conn, int fd);
00551 extern pg_int64 lo_tell64(PGconn *conn, int fd);
00552 extern int lo_truncate(PGconn *conn, int fd, size_t len);
00553 extern int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
00554 extern int lo_unlink(PGconn *conn, Oid lobjId);
00555 extern Oid lo_import(PGconn *conn, const char *filename);
00556 extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
00557 extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
00558
00559
00560
00561
00562 extern int PQlibVersion(void);
00563
00564
00565 extern int PQmblen(const char *s, int encoding);
00566
00567
00568 extern int PQdsplen(const char *s, int encoding);
00569
00570
00571 extern int PQenv2encoding(void);
00572
00573
00574
00575 extern char *PQencryptPassword(const char *passwd, const char *user);
00576
00577
00578
00579 extern int pg_char_to_encoding(const char *name);
00580 extern const char *pg_encoding_to_char(int encoding);
00581 extern int pg_valid_server_encoding_id(int encoding);
00582
00583 #ifdef __cplusplus
00584 }
00585 #endif
00586
00587 #endif