Commit 6428074e authored by Tom Lane's avatar Tom Lane

Update libpq to store an error message in PGresult, per pgsq-interfaces discussion of 21-Sep.

parent 502769d0
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.83 1998/09/20 04:51:10 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.84 1998/10/01 01:40:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -822,8 +822,8 @@ PQsetenv(PGconn *conn)
sprintf(envbuf, "%s=%s", envname, encoding);
putenv(envbuf);
}
PQclear(rtn);
}
PQclear(rtn);
if (!encoding)
{ /* this should not happen */
sprintf(envbuf, "%s=%s", envname, pg_encoding_to_char(MULTIBYTE));
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.16 1998/09/01 04:40:07 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.17 1998/10/01 01:40:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -76,7 +76,10 @@ lo_open(PGconn *conn, Oid lobjId, int mode)
return fd;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -111,7 +114,10 @@ lo_close(PGconn *conn, int fd)
return retval;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -151,7 +157,10 @@ lo_read(PGconn *conn, int fd, char *buf, int len)
return result_len;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -192,7 +201,10 @@ lo_write(PGconn *conn, int fd, char *buf, int len)
return retval;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -236,7 +248,10 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence)
return retval;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -273,7 +288,10 @@ lo_creat(PGconn *conn, int mode)
return (Oid) retval;
}
else
{
PQclear(res);
return InvalidOid;
}
}
......@@ -309,7 +327,10 @@ lo_tell(PGconn *conn, int fd)
return retval;
}
else
{
PQclear(res);
return -1;
}
}
/*
......@@ -344,7 +365,10 @@ lo_unlink(PGconn *conn, Oid lobjId)
return retval;
}
else
{
PQclear(res);
return -1;
}
}
/*
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-fe.h,v 1.43 1998/09/18 16:46:06 momjian Exp $
* $Id: libpq-fe.h,v 1.44 1998/10/01 01:40:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -67,6 +67,8 @@ extern "C"
/* 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.
* 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.
*/
typedef struct pgNotify
{
......@@ -78,7 +80,7 @@ extern "C"
/* PQnoticeProcessor is the function type for the notice-message callback.
*/
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
typedef void (*PQnoticeProcessor) (void * arg, const char * message);
/* Print options for PQprint() */
......@@ -219,15 +221,16 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message);
* use
*/
extern PGresult *PQfn(PGconn *conn,
int fnid,
int *result_buf,
int *result_len,
int result_is_int,
PQArgBlock *args,
int nargs);
int fnid,
int *result_buf,
int *result_len,
int result_is_int,
PQArgBlock *args,
int nargs);
/* Accessor functions for PGresult objects */
extern ExecStatusType PQresultStatus(PGresult *res);
extern const char *PQresultErrorMessage(PGresult *res);
extern int PQntuples(PGresult *res);
extern int PQnfields(PGresult *res);
extern int PQbinaryTuples(PGresult *res);
......@@ -246,35 +249,39 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message);
/* Delete a PGresult */
extern void PQclear(PGresult *res);
/* Make an empty PGresult with given status (some apps find this useful) */
/* 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.
*/
extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
/* === in fe-print.c === */
extern void PQprint(FILE *fout, /* output stream */
PGresult *res,
PQprintOpt *ps); /* option structure */
extern void PQprint(FILE *fout, /* output stream */
PGresult *res,
PQprintOpt *ps); /* option structure */
/*
* PQdisplayTuples() is a better version of PQprintTuples(), but both
* are obsoleted by PQprint().
*/
extern void PQdisplayTuples(PGresult *res,
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);
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);
extern void PQprintTuples(PGresult *res,
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 */
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 */
#ifdef MULTIBYTE
extern int PQmblen(unsigned char *s);
......
......@@ -11,7 +11,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq-int.h,v 1.3 1998/09/03 02:10:53 momjian Exp $
* $Id: libpq-int.h,v 1.4 1998/10/01 01:40:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -78,7 +78,7 @@
char *value; /* actual value */
} PGresAttValue;
struct pg_result
struct pg_result
{
int ntups;
int numAttributes;
......@@ -91,7 +91,15 @@
* last insert query */
int binary; /* binary tuple values if binary == 1,
* otherwise ASCII */
/* NOTE: conn is kept here only for the temporary convenience of
* applications that rely on it being here. It will go away in a
* future release, because relying on it is a bad idea --- what if
* the PGresult has outlived the PGconn? About the only thing it was
* really good for was fetching the errorMessage, and we stash that
* here now anyway.
*/
PGconn *conn; /* connection we did the query on */
char *errMsg; /* error message, or NULL if no error */
};
/* PGAsyncStatusType defines the state of the query-execution state machine */
......@@ -174,12 +182,8 @@
PGresult *result; /* result being constructed */
PGresAttValue *curTuple; /* tuple currently being read */
/* Message space. Placed last for code-size reasons.
* errorMessage is the message last returned to the application.
* When asyncStatus=READY, asyncErrorMessage is the pending message
* that will be put in errorMessage by PQgetResult. */
/* Message space. Placed last for code-size reasons. */
char errorMessage[ERROR_MSG_LENGTH];
char asyncErrorMessage[ERROR_MSG_LENGTH];
};
/* ----------------
......@@ -197,6 +201,7 @@ extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
/* === in fe-exec.c === */
extern void pqSetResultError(PGresult *res, const char *msg);
extern void pqClearAsyncResult(PGconn *conn);
/* === in fe-misc.c === */
......
......@@ -63,3 +63,4 @@ EXPORTS
lo_unlink @ 60
lo_import @ 61
lo_export @ 62
PQresultErrorMessage @ 63
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment