libpq-fe.h 9.9 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * libpq-fe.h--
4 5
 *	  This file contains definitions for structures and
 *	  externs for functions used by frontend postgres applications.
6 7 8
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: libpq-fe.h,v 1.44 1998/10/01 01:40:23 tgl Exp $
10 11 12 13 14 15 16 17
 *
 *-------------------------------------------------------------------------
 */

#ifndef LIBPQ_FE_H
#define LIBPQ_FE_H

#ifdef __cplusplus
18
extern		"C"
19
{
20 21
#endif

22
#include <stdio.h>
23 24
/* postgres_ext.h defines the backend's externally visible types,
 * such as Oid.
25
 */
26
#include "postgres_ext.h"
27

B
Bruce Momjian 已提交
28 29
/* Application-visible enum types */

30 31 32 33
	typedef enum
	{
		CONNECTION_OK,
		CONNECTION_BAD
34
	} ConnStatusType;
35 36 37 38

	typedef enum
	{
		PGRES_EMPTY_QUERY = 0,
39 40 41 42 43
		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 */
B
Bruce Momjian 已提交
44 45
		PGRES_COPY_OUT,			/* Copy Out data transfer in progress */
		PGRES_COPY_IN,			/* Copy In data transfer in progress */
46 47 48 49
		PGRES_BAD_RESPONSE,		/* an unexpected response was recv'd from
								 * the backend */
		PGRES_NONFATAL_ERROR,
		PGRES_FATAL_ERROR
50
	} ExecStatusType;
51

52 53
/* String descriptions of the ExecStatusTypes */
	extern const char * const pgresStatus[];
54

55 56
/* PGconn encapsulates a connection to the backend.
 * The contents of this struct are not supposed to be known to applications.
57
 */
58
	typedef struct pg_conn PGconn;
59

60 61 62 63
/* 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.
64
 */
65
	typedef struct pg_result PGresult;
66

67 68 69
/* 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.
70 71
 * 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.
M
 
Marc G. Fournier 已提交
72
 */
73 74
	typedef struct pgNotify
	{
75
		char		relname[NAMEDATALEN];		/* name of relation
76
												 * containing data */
77
		int			be_pid;						/* process id of backend */
78
	} PGnotify;
79

80
/* PQnoticeProcessor is the function type for the notice-message callback.
B
Bruce Momjian 已提交
81
 */
82

83
	typedef void (*PQnoticeProcessor) (void * arg, const char * message);
M
 
Marc G. Fournier 已提交
84

B
Bruce Momjian 已提交
85
/* Print options for PQprint() */
86 87 88 89 90 91 92
  
  	/*
  	 * 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;
B
Bruce Momjian 已提交
93 94

	typedef struct _PQprintOpt
95
	{
96
		pqbool		header;		/* print output field headings and row
97
								 * count */
98 99 100 101 102 103 104 105 106 107
		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 */
B
Bruce Momjian 已提交
108
	} PQprintOpt;
109

M
Marc G. Fournier 已提交
110
/* ----------------
M
 
Marc G. Fournier 已提交
111
 * Structure for the conninfo parameter definitions returned by PQconndefaults
M
Marc G. Fournier 已提交
112 113
 * ----------------
 */
B
Bruce Momjian 已提交
114
	typedef struct _PQconninfoOption
115
	{
116
		char	   *keyword;	/* The keyword of the option			*/
B
Bruce Momjian 已提交
117
		char	   *envvar;	/* Fallback environment variable name	*/
118 119 120 121
		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	*/
122 123 124 125 126
								/* 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	*/
127
		int			dispsize;	/* Field size in characters for dialog	*/
B
Bruce Momjian 已提交
128
	} PQconninfoOption;
129

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
/* ----------------
 * 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;

M
 
Marc G. Fournier 已提交
145 146 147 148 149
/* ----------------
 * Exported functions of libpq
 * ----------------
 */

150
/* ===	in fe-connect.c === */
M
 
Marc G. Fournier 已提交
151

152
	/* make a new client connection to the backend */
153
	extern PGconn *PQconnectdb(const char *conninfo);
M
 
Marc G. Fournier 已提交
154 155
	extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
								const char *pgoptions, const char *pgtty,
156 157
											const char *dbName,
									 const char *login, const char *pwd);
M
 
Marc G. Fournier 已提交
158 159 160 161
#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 */
162
	extern PQconninfoOption *PQconndefaults(void);
M
 
Marc G. Fournier 已提交
163

164
	/* close the current connection and free the PGconn data structure */
165
	extern void PQfinish(PGconn *conn);
166

167 168 169 170
	/*
	 * close the current connection and restablish a new one with the same
	 * parameters
	 */
171 172
	extern void PQreset(PGconn *conn);

M
 
Marc G. Fournier 已提交
173 174 175
	/* issue a cancel request */
	extern int	PQrequestCancel(PGconn *conn);

B
Bruce Momjian 已提交
176
	/* Accessor functions for PGconn objects */
177 178
	extern char *PQdb(PGconn *conn);
	extern char *PQuser(PGconn *conn);
179
	extern char *PQpass(PGconn *conn);
180 181 182
	extern char *PQhost(PGconn *conn);
	extern char *PQport(PGconn *conn);
	extern char *PQtty(PGconn *conn);
183
	extern char *PQoptions(PGconn *conn);
184 185
	extern ConnStatusType PQstatus(PGconn *conn);
	extern char *PQerrorMessage(PGconn *conn);
186
	extern int	PQsocket(PGconn *conn);
187
	extern int	PQbackendPID(PGconn *conn);
B
Bruce Momjian 已提交
188 189

	/* Enable/disable tracing */
190 191
	extern void PQtrace(PGconn *conn, FILE *debug_port);
	extern void PQuntrace(PGconn *conn);
192

B
 
Bruce Momjian 已提交
193
	/* Override default notice processor */
194 195 196
	extern void PQsetNoticeProcessor(PGconn *conn,
												 PQnoticeProcessor proc,
												 void *arg);
B
 
Bruce Momjian 已提交
197

198
/* === in fe-exec.c === */
M
 
Marc G. Fournier 已提交
199

B
Bruce Momjian 已提交
200
	/* Simple synchronous query */
201
	extern PGresult *PQexec(PGconn *conn, const char *query);
B
Bruce Momjian 已提交
202
	extern PGnotify *PQnotifies(PGconn *conn);
M
 
Marc G. Fournier 已提交
203

B
Bruce Momjian 已提交
204
	/* Interface for multiple-result or asynchronous queries */
205
	extern int	PQsendQuery(PGconn *conn, const char *query);
B
Bruce Momjian 已提交
206
	extern PGresult *PQgetResult(PGconn *conn);
M
 
Marc G. Fournier 已提交
207

B
Bruce Momjian 已提交
208 209
	/* Routines for managing an asychronous query */
	extern int	PQisBusy(PGconn *conn);
210
	extern int	PQconsumeInput(PGconn *conn);
M
 
Marc G. Fournier 已提交
211

B
Bruce Momjian 已提交
212
	/* Routines for copy in/out */
213
	extern int	PQgetline(PGconn *conn, char *string, int length);
214 215 216
	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);
B
Bruce Momjian 已提交
217
	extern int	PQendcopy(PGconn *conn);
M
 
Marc G. Fournier 已提交
218

219 220 221 222
	/*
	 * "Fast path" interface --- not really recommended for application
	 * use
	 */
B
Bruce Momjian 已提交
223
	extern PGresult *PQfn(PGconn *conn,
224 225 226 227 228 229
						  int fnid,
						  int *result_buf,
						  int *result_len,
						  int result_is_int,
						  PQArgBlock *args,
						  int nargs);
B
Bruce Momjian 已提交
230 231

	/* Accessor functions for PGresult objects */
232
	extern ExecStatusType PQresultStatus(PGresult *res);
233
	extern const char *PQresultErrorMessage(PGresult *res);
234 235
	extern int	PQntuples(PGresult *res);
	extern int	PQnfields(PGresult *res);
236
	extern int	PQbinaryTuples(PGresult *res);
237 238 239
	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);
240
	extern int	PQfsize(PGresult *res, int field_num);
241
	extern int	PQfmod(PGresult *res, int field_num);
242 243 244 245 246 247
	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);
M
 
Marc G. Fournier 已提交
248

B
Bruce Momjian 已提交
249
	/* Delete a PGresult */
250
	extern void PQclear(PGresult *res);
B
Bruce Momjian 已提交
251

252 253 254 255
	/* 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.
	 */
256 257
	extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);

B
Bruce Momjian 已提交
258
/* === in fe-print.c === */
M
 
Marc G. Fournier 已提交
259

260 261 262
	extern void PQprint(FILE *fout,			/* output stream */
						PGresult *res,
						PQprintOpt *ps);	/* option structure */
M
 
Marc G. Fournier 已提交
263

264 265 266
	/*
	 * PQdisplayTuples() is a better version of PQprintTuples(), but both
	 * are obsoleted by PQprint().
B
Bruce Momjian 已提交
267
	 */
268
	extern void PQdisplayTuples(PGresult *res,
269 270 271 272 273 274 275 276
								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);

277
	extern void PQprintTuples(PGresult *res,
278 279 280 281 282 283 284
							  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 */
B
Bruce Momjian 已提交
285

286
#ifdef MULTIBYTE
287
	extern int	PQmblen(unsigned char *s);
288 289
#endif

290
/* === in fe-lobj.c === */
M
 
Marc G. Fournier 已提交
291 292

	/* Large-object access routines */
B
Bruce Momjian 已提交
293 294 295 296 297 298 299 300 301 302 303
	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);

304 305
#ifdef __cplusplus
};
306

307
#endif
308

309
#endif	 /* LIBPQ_FE_H */