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 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -822,8 +822,8 @@ PQsetenv(PGconn *conn)
sprintf(envbuf, "%s=%s", envname, encoding); sprintf(envbuf, "%s=%s", envname, encoding);
putenv(envbuf); putenv(envbuf);
} }
PQclear(rtn);
} }
PQclear(rtn);
if (!encoding) if (!encoding)
{ /* this should not happen */ { /* this should not happen */
sprintf(envbuf, "%s=%s", envname, pg_encoding_to_char(MULTIBYTE)); sprintf(envbuf, "%s=%s", envname, pg_encoding_to_char(MULTIBYTE));
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -76,7 +76,10 @@ lo_open(PGconn *conn, Oid lobjId, int mode)
return fd; return fd;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -111,7 +114,10 @@ lo_close(PGconn *conn, int fd) ...@@ -111,7 +114,10 @@ lo_close(PGconn *conn, int fd)
return retval; return retval;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -151,7 +157,10 @@ lo_read(PGconn *conn, int fd, char *buf, int len) ...@@ -151,7 +157,10 @@ lo_read(PGconn *conn, int fd, char *buf, int len)
return result_len; return result_len;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -192,7 +201,10 @@ lo_write(PGconn *conn, int fd, char *buf, int len) ...@@ -192,7 +201,10 @@ lo_write(PGconn *conn, int fd, char *buf, int len)
return retval; return retval;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -236,7 +248,10 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence) ...@@ -236,7 +248,10 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence)
return retval; return retval;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -273,7 +288,10 @@ lo_creat(PGconn *conn, int mode) ...@@ -273,7 +288,10 @@ lo_creat(PGconn *conn, int mode)
return (Oid) retval; return (Oid) retval;
} }
else else
{
PQclear(res);
return InvalidOid; return InvalidOid;
}
} }
...@@ -309,7 +327,10 @@ lo_tell(PGconn *conn, int fd) ...@@ -309,7 +327,10 @@ lo_tell(PGconn *conn, int fd)
return retval; return retval;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
...@@ -344,7 +365,10 @@ lo_unlink(PGconn *conn, Oid lobjId) ...@@ -344,7 +365,10 @@ lo_unlink(PGconn *conn, Oid lobjId)
return retval; return retval;
} }
else else
{
PQclear(res);
return -1; return -1;
}
} }
/* /*
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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" ...@@ -67,6 +67,8 @@ extern "C"
/* PGnotify represents the occurrence of a NOTIFY message. /* PGnotify represents the occurrence of a NOTIFY message.
* Ideally this would be an opaque typedef, but it's so simple that it's * Ideally this would be an opaque typedef, but it's so simple that it's
* unlikely to change. * 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 typedef struct pgNotify
{ {
...@@ -78,7 +80,7 @@ extern "C" ...@@ -78,7 +80,7 @@ extern "C"
/* PQnoticeProcessor is the function type for the notice-message callback. /* 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() */ /* Print options for PQprint() */
...@@ -228,6 +230,7 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message); ...@@ -228,6 +230,7 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message);
/* Accessor functions for PGresult objects */ /* Accessor functions for PGresult objects */
extern ExecStatusType PQresultStatus(PGresult *res); extern ExecStatusType PQresultStatus(PGresult *res);
extern const char *PQresultErrorMessage(PGresult *res);
extern int PQntuples(PGresult *res); extern int PQntuples(PGresult *res);
extern int PQnfields(PGresult *res); extern int PQnfields(PGresult *res);
extern int PQbinaryTuples(PGresult *res); extern int PQbinaryTuples(PGresult *res);
...@@ -246,7 +249,10 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message); ...@@ -246,7 +249,10 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message);
/* Delete a PGresult */ /* Delete a PGresult */
extern void PQclear(PGresult *res); 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); extern PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
/* === in fe-print.c === */ /* === in fe-print.c === */
...@@ -267,6 +273,7 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message); ...@@ -267,6 +273,7 @@ typedef void (*PQnoticeProcessor) (void * arg, const char * message);
const char *fieldSep, /* field separator */ const char *fieldSep, /* field separator */
int printHeader, /* display headers? */ int printHeader, /* display headers? */
int quiet); int quiet);
extern void PQprintTuples(PGresult *res, extern void PQprintTuples(PGresult *res,
FILE *fout, /* output stream */ FILE *fout, /* output stream */
int printAttName, /* print attribute names int printAttName, /* print attribute names
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -91,7 +91,15 @@ ...@@ -91,7 +91,15 @@
* last insert query */ * last insert query */
int binary; /* binary tuple values if binary == 1, int binary; /* binary tuple values if binary == 1,
* otherwise ASCII */ * 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 */ 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 */ /* PGAsyncStatusType defines the state of the query-execution state machine */
...@@ -174,12 +182,8 @@ ...@@ -174,12 +182,8 @@
PGresult *result; /* result being constructed */ PGresult *result; /* result being constructed */
PGresAttValue *curTuple; /* tuple currently being read */ PGresAttValue *curTuple; /* tuple currently being read */
/* Message space. Placed last for code-size reasons. /* 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. */
char errorMessage[ERROR_MSG_LENGTH]; 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); ...@@ -197,6 +201,7 @@ extern int pqPacketSend(PGconn *conn, const char *buf, size_t len);
/* === in fe-exec.c === */ /* === in fe-exec.c === */
extern void pqSetResultError(PGresult *res, const char *msg);
extern void pqClearAsyncResult(PGconn *conn); extern void pqClearAsyncResult(PGconn *conn);
/* === in fe-misc.c === */ /* === in fe-misc.c === */
......
...@@ -63,3 +63,4 @@ EXPORTS ...@@ -63,3 +63,4 @@ EXPORTS
lo_unlink @ 60 lo_unlink @ 60
lo_import @ 61 lo_import @ 61
lo_export @ 62 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