libpq-fe.h 9.6 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
 *
B
Bruce Momjian 已提交
9
 * $Id: libpq-fe.h,v 1.43 1998/09/18 16:46:06 momjian 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.
M
 
Marc G. Fournier 已提交
70
 */
71 72
	typedef struct pgNotify
	{
73
		char		relname[NAMEDATALEN];		/* name of relation
74
												 * containing data */
75
		int			be_pid;						/* process id of backend */
76
	} PGnotify;
77

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

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

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

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

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

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
/* ----------------
 * 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 已提交
143 144 145 146 147
/* ----------------
 * Exported functions of libpq
 * ----------------
 */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/* Accessor functions for PGresult objects */
230 231 232
	extern ExecStatusType PQresultStatus(PGresult *res);
	extern int	PQntuples(PGresult *res);
	extern int	PQnfields(PGresult *res);
233
	extern int	PQbinaryTuples(PGresult *res);
234 235 236
	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);
237
	extern int	PQfsize(PGresult *res, int field_num);
238
	extern int	PQfmod(PGresult *res, int field_num);
239 240 241 242 243 244
	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 已提交
245

B
Bruce Momjian 已提交
246
	/* Delete a PGresult */
247
	extern void PQclear(PGresult *res);
B
Bruce Momjian 已提交
248

249 250 251
	/* Make an empty PGresult with given status (some apps find this useful) */
	extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);

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

B
Bruce Momjian 已提交
254
	extern void PQprint(FILE *fout,		/* output stream */
255 256
									PGresult *res,
									PQprintOpt *ps);	/* option structure */
M
 
Marc G. Fournier 已提交
257

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

279
#ifdef MULTIBYTE
280
	extern int	PQmblen(unsigned char *s);
281 282
#endif

283
/* === in fe-lobj.c === */
M
 
Marc G. Fournier 已提交
284 285

	/* Large-object access routines */
B
Bruce Momjian 已提交
286 287 288 289 290 291 292 293 294 295 296
	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);

297 298
#ifdef __cplusplus
};
299

300
#endif
301

302
#endif	 /* LIBPQ_FE_H */