1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* libpq-fe.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* This file contains definitions for structures and
|
|
|
|
* externs for functions used by frontend postgres applications.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1998-10-06 16:16:50 +02:00
|
|
|
* $Id: libpq-fe.h,v 1.45 1998/10/06 14:16:49 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBPQ_FE_H
|
|
|
|
#define LIBPQ_FE_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
1997-09-08 04:41:22 +02:00
|
|
|
extern "C"
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
|
|
|
|
1996-11-22 05:39:53 +01:00
|
|
|
#include <stdio.h>
|
1998-09-03 04:10:56 +02:00
|
|
|
/* postgres_ext.h defines the backend's externally visible types,
|
|
|
|
* such as Oid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1996-12-10 08:05:12 +01:00
|
|
|
#include "postgres_ext.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Application-visible enum types */
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CONNECTION_OK,
|
|
|
|
CONNECTION_BAD
|
1997-09-08 23:56:23 +02:00
|
|
|
} ConnStatusType;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PGRES_EMPTY_QUERY = 0,
|
1998-09-03 04:10:56 +02:00
|
|
|
PGRES_COMMAND_OK, /* a query command that doesn't return anything
|
|
|
|
* was executed properly by the backend */
|
|
|
|
PGRES_TUPLES_OK, /* a query command that returns tuples
|
|
|
|
* was executed properly by the backend,
|
|
|
|
* PGresult contains the result tuples */
|
1998-05-07 01:51:16 +02:00
|
|
|
PGRES_COPY_OUT, /* Copy Out data transfer in progress */
|
|
|
|
PGRES_COPY_IN, /* Copy In data transfer in progress */
|
1997-09-07 07:04:48 +02:00
|
|
|
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from
|
|
|
|
* the backend */
|
|
|
|
PGRES_NONFATAL_ERROR,
|
|
|
|
PGRES_FATAL_ERROR
|
1997-09-08 23:56:23 +02:00
|
|
|
} ExecStatusType;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* String descriptions of the ExecStatusTypes */
|
|
|
|
extern const char * const pgresStatus[];
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* PGconn encapsulates a connection to the backend.
|
|
|
|
* The contents of this struct are not supposed to be known to applications.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-09-03 04:10:56 +02:00
|
|
|
typedef struct pg_conn PGconn;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* PGresult encapsulates the result of a query (or more precisely, of a single
|
|
|
|
* SQL command --- a query string given to PQsendQuery can contain multiple
|
|
|
|
* commands and thus return multiple PGresult objects).
|
|
|
|
* The contents of this struct are not supposed to be known to applications.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-09-03 04:10:56 +02:00
|
|
|
typedef struct pg_result PGresult;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* PGnotify represents the occurrence of a NOTIFY message.
|
|
|
|
* Ideally this would be an opaque typedef, but it's so simple that it's
|
|
|
|
* unlikely to change.
|
1998-10-01 03:40:26 +02:00
|
|
|
* NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
|
|
|
|
* whereas in earlier versions it was always your own backend's PID.
|
1998-08-17 05:50:43 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct pgNotify
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char relname[NAMEDATALEN]; /* name of relation
|
1997-09-07 07:04:48 +02:00
|
|
|
* containing data */
|
1998-09-03 04:10:56 +02:00
|
|
|
int be_pid; /* process id of backend */
|
1997-09-08 23:56:23 +02:00
|
|
|
} PGnotify;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* PQnoticeProcessor is the function type for the notice-message callback.
|
1998-05-07 01:51:16 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-10-01 03:40:26 +02:00
|
|
|
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Print options for PQprint() */
|
1998-09-03 04:10:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't use the conventional "bool", because we are designed to be
|
|
|
|
* included in a user's program, and user may already have that type
|
|
|
|
* defined. Pqbool, on the other hand, is unlikely to be used.
|
|
|
|
*/
|
|
|
|
typedef char pqbool;
|
1998-05-07 01:51:16 +02:00
|
|
|
|
|
|
|
typedef struct _PQprintOpt
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
pqbool header; /* print output field headings and row
|
1997-09-07 07:04:48 +02:00
|
|
|
* count */
|
1997-09-08 04:41:22 +02:00
|
|
|
pqbool align; /* fill align the fields */
|
|
|
|
pqbool standard; /* old brain dead format */
|
|
|
|
pqbool html3; /* output html tables */
|
|
|
|
pqbool expanded; /* expand tables */
|
|
|
|
pqbool pager; /* use pager for output if needed */
|
|
|
|
char *fieldSep; /* field separator */
|
|
|
|
char *tableOpt; /* insert to HTML <table ...> */
|
|
|
|
char *caption; /* HTML <caption> */
|
|
|
|
char **fieldName; /* null terminated array of repalcement
|
|
|
|
* field names */
|
1998-05-07 01:51:16 +02:00
|
|
|
} PQprintOpt;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-11-09 11:39:54 +01:00
|
|
|
/* ----------------
|
1998-08-17 05:50:43 +02:00
|
|
|
* Structure for the conninfo parameter definitions returned by PQconndefaults
|
1996-11-09 11:39:54 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
1998-05-07 01:51:16 +02:00
|
|
|
typedef struct _PQconninfoOption
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *keyword; /* The keyword of the option */
|
1998-09-18 18:46:07 +02:00
|
|
|
char *envvar; /* Fallback environment variable name */
|
1997-09-08 04:41:22 +02:00
|
|
|
char *compiled; /* Fallback compiled in default value */
|
|
|
|
char *val; /* Options value */
|
|
|
|
char *label; /* Label for field in connect dialog */
|
|
|
|
char *dispchar; /* Character to display for this field */
|
1998-09-03 04:10:56 +02:00
|
|
|
/* in a connect dialog. Values are: */
|
|
|
|
/* "" Display entered value as is */
|
|
|
|
/* "*" Password field - hide value */
|
|
|
|
/* "D" Debug options - don't */
|
|
|
|
/* create a field by default */
|
1997-09-08 04:41:22 +02:00
|
|
|
int dispsize; /* Field size in characters for dialog */
|
1998-05-07 01:51:16 +02:00
|
|
|
} PQconninfoOption;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-03 04:10:56 +02:00
|
|
|
/* ----------------
|
|
|
|
* PQArgBlock -- structure for PQfn() arguments
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int isint;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int *ptr; /* can't use void (dec compiler barfs) */
|
|
|
|
int integer;
|
|
|
|
} u;
|
|
|
|
} PQArgBlock;
|
|
|
|
|
1998-08-17 05:50:43 +02:00
|
|
|
/* ----------------
|
|
|
|
* Exported functions of libpq
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* === in fe-connect.c === */
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* make a new client connection to the backend */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern PGconn *PQconnectdb(const char *conninfo);
|
1998-08-17 05:50:43 +02:00
|
|
|
extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
|
|
|
|
const char *pgoptions, const char *pgtty,
|
1998-09-01 06:40:42 +02:00
|
|
|
const char *dbName,
|
|
|
|
const char *login, const char *pwd);
|
1998-08-17 05:50:43 +02:00
|
|
|
#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
|
|
|
|
PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
|
|
|
|
|
|
|
|
/* get info about connection options known to PQconnectdb */
|
1997-09-07 07:04:48 +02:00
|
|
|
extern PQconninfoOption *PQconndefaults(void);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* close the current connection and free the PGconn data structure */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQfinish(PGconn *conn);
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
|
|
|
* close the current connection and restablish a new one with the same
|
|
|
|
* parameters
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQreset(PGconn *conn);
|
|
|
|
|
1998-08-17 05:50:43 +02:00
|
|
|
/* issue a cancel request */
|
|
|
|
extern int PQrequestCancel(PGconn *conn);
|
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Accessor functions for PGconn objects */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern char *PQdb(PGconn *conn);
|
|
|
|
extern char *PQuser(PGconn *conn);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern char *PQpass(PGconn *conn);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern char *PQhost(PGconn *conn);
|
|
|
|
extern char *PQport(PGconn *conn);
|
|
|
|
extern char *PQtty(PGconn *conn);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern char *PQoptions(PGconn *conn);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern ConnStatusType PQstatus(PGconn *conn);
|
|
|
|
extern char *PQerrorMessage(PGconn *conn);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int PQsocket(PGconn *conn);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern int PQbackendPID(PGconn *conn);
|
1998-05-07 01:51:16 +02:00
|
|
|
|
|
|
|
/* Enable/disable tracing */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQtrace(PGconn *conn, FILE *debug_port);
|
|
|
|
extern void PQuntrace(PGconn *conn);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-08-09 04:59:33 +02:00
|
|
|
/* Override default notice processor */
|
1998-09-01 06:40:42 +02:00
|
|
|
extern void PQsetNoticeProcessor(PGconn *conn,
|
|
|
|
PQnoticeProcessor proc,
|
|
|
|
void *arg);
|
1998-08-09 04:59:33 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* === in fe-exec.c === */
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Simple synchronous query */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern PGresult *PQexec(PGconn *conn, const char *query);
|
1998-05-07 01:51:16 +02:00
|
|
|
extern PGnotify *PQnotifies(PGconn *conn);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Interface for multiple-result or asynchronous queries */
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int PQsendQuery(PGconn *conn, const char *query);
|
1998-05-07 01:51:16 +02:00
|
|
|
extern PGresult *PQgetResult(PGconn *conn);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Routines for managing an asychronous query */
|
|
|
|
extern int PQisBusy(PGconn *conn);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern int PQconsumeInput(PGconn *conn);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Routines for copy in/out */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern int PQgetline(PGconn *conn, char *string, int length);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern int PQputline(PGconn *conn, const char *string);
|
|
|
|
extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
|
|
|
|
extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
|
1998-05-07 01:51:16 +02:00
|
|
|
extern int PQendcopy(PGconn *conn);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
/*
|
|
|
|
* "Fast path" interface --- not really recommended for application
|
|
|
|
* use
|
|
|
|
*/
|
1998-05-07 01:51:16 +02:00
|
|
|
extern PGresult *PQfn(PGconn *conn,
|
1998-10-01 03:40:26 +02:00
|
|
|
int fnid,
|
|
|
|
int *result_buf,
|
|
|
|
int *result_len,
|
|
|
|
int result_is_int,
|
|
|
|
PQArgBlock *args,
|
|
|
|
int nargs);
|
1998-05-07 01:51:16 +02:00
|
|
|
|
|
|
|
/* Accessor functions for PGresult objects */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern ExecStatusType PQresultStatus(PGresult *res);
|
1998-10-01 03:40:26 +02:00
|
|
|
extern const char *PQresultErrorMessage(PGresult *res);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern int PQntuples(PGresult *res);
|
|
|
|
extern int PQnfields(PGresult *res);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern int PQbinaryTuples(PGresult *res);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern char *PQfname(PGresult *res, int field_num);
|
|
|
|
extern int PQfnumber(PGresult *res, const char *field_name);
|
|
|
|
extern Oid PQftype(PGresult *res, int field_num);
|
1998-09-03 04:10:56 +02:00
|
|
|
extern int PQfsize(PGresult *res, int field_num);
|
1998-07-14 04:41:26 +02:00
|
|
|
extern int PQfmod(PGresult *res, int field_num);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern char *PQcmdStatus(PGresult *res);
|
|
|
|
extern const char *PQoidStatus(PGresult *res);
|
|
|
|
extern const char *PQcmdTuples(PGresult *res);
|
|
|
|
extern char *PQgetvalue(PGresult *res, int tup_num, int field_num);
|
|
|
|
extern int PQgetlength(PGresult *res, int tup_num, int field_num);
|
|
|
|
extern int PQgetisnull(PGresult *res, int tup_num, int field_num);
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* Delete a PGresult */
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQclear(PGresult *res);
|
1998-05-07 01:51:16 +02:00
|
|
|
|
1998-10-01 03:40:26 +02:00
|
|
|
/* Make an empty PGresult with given status (some apps find this useful).
|
|
|
|
* If conn is not NULL and status indicates an error, the conn's
|
|
|
|
* errorMessage is copied.
|
|
|
|
*/
|
1998-09-03 04:10:56 +02:00
|
|
|
extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
|
|
|
|
|
1998-05-07 01:51:16 +02:00
|
|
|
/* === in fe-print.c === */
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-10-01 03:40:26 +02:00
|
|
|
extern void PQprint(FILE *fout, /* output stream */
|
|
|
|
PGresult *res,
|
|
|
|
PQprintOpt *ps); /* option structure */
|
1998-08-17 05:50:43 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
/*
|
|
|
|
* PQdisplayTuples() is a better version of PQprintTuples(), but both
|
|
|
|
* are obsoleted by PQprint().
|
1998-05-07 01:51:16 +02:00
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQdisplayTuples(PGresult *res,
|
1998-10-01 03:40:26 +02:00
|
|
|
FILE *fp, /* where to send the
|
|
|
|
* output */
|
|
|
|
int fillAlign, /* pad the fields with
|
|
|
|
* spaces */
|
|
|
|
const char *fieldSep, /* field separator */
|
|
|
|
int printHeader, /* display headers? */
|
|
|
|
int quiet);
|
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void PQprintTuples(PGresult *res,
|
1998-10-01 03:40:26 +02:00
|
|
|
FILE *fout, /* output stream */
|
|
|
|
int printAttName, /* print attribute names
|
|
|
|
* or not */
|
|
|
|
int terseOutput, /* delimiter bars or
|
|
|
|
* not? */
|
|
|
|
int width); /* width of column, if
|
|
|
|
* 0, use variable width */
|
1998-05-07 01:51:16 +02:00
|
|
|
|
1998-10-06 16:16:50 +02:00
|
|
|
/* Determine length of multibyte encoded char at *s */
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int PQmblen(unsigned char *s);
|
1998-06-16 09:29:54 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* === in fe-lobj.c === */
|
1998-08-17 05:50:43 +02:00
|
|
|
|
|
|
|
/* Large-object access routines */
|
1998-05-07 01:51:16 +02:00
|
|
|
extern int lo_open(PGconn *conn, Oid lobjId, int mode);
|
|
|
|
extern int lo_close(PGconn *conn, int fd);
|
|
|
|
extern int lo_read(PGconn *conn, int fd, char *buf, int len);
|
|
|
|
extern int lo_write(PGconn *conn, int fd, char *buf, int len);
|
|
|
|
extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
|
|
|
|
extern Oid lo_creat(PGconn *conn, int mode);
|
|
|
|
extern int lo_tell(PGconn *conn, int fd);
|
|
|
|
extern int lo_unlink(PGconn *conn, Oid lobjId);
|
|
|
|
extern Oid lo_import(PGconn *conn, char *filename);
|
|
|
|
extern int lo_export(PGconn *conn, Oid lobjId, char *filename);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* LIBPQ_FE_H */
|