aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/lib')
-rw-r--r--src/interfaces/ecpg/lib/Makefile4
-rw-r--r--src/interfaces/ecpg/lib/connect.c15
-rw-r--r--src/interfaces/ecpg/lib/error.c29
-rw-r--r--src/interfaces/ecpg/lib/execute.c30
-rw-r--r--src/interfaces/ecpg/lib/extern.h4
5 files changed, 61 insertions, 21 deletions
diff --git a/src/interfaces/ecpg/lib/Makefile b/src/interfaces/ecpg/lib/Makefile
index cfc630537c1..20b49ca0afd 100644
--- a/src/interfaces/ecpg/lib/Makefile
+++ b/src/interfaces/ecpg/lib/Makefile
@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.18 2002/12/11 04:07:39 momjian Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.19 2003/02/13 13:11:52 meskes Exp $
#
#-------------------------------------------------------------------------
@@ -16,7 +16,7 @@ NAME= ecpg
SO_MAJOR_VERSION= 3
SO_MINOR_VERSION= 4.2
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c
index 6cc1f0cb5ef..197f9f1cafd 100644
--- a/src/interfaces/ecpg/lib/connect.c
+++ b/src/interfaces/ecpg/lib/connect.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.19 2002/09/04 20:31:46 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.20 2003/02/13 13:11:52 meskes Exp $ */
#include "postgres_fe.h"
@@ -419,15 +419,20 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
if (PQstatus(this->connection) == CONNECTION_BAD)
{
+ const char *errmsg = PQerrorMessage(this->connection);
+ char *db = realname ? realname : "<DEFAULT>";
+
+ set_backend_err(errmsg, lineno);
ecpg_finish(this);
- ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n",
- realname ? realname : "<DEFAULT>",
+ ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
+ db,
host ? host : "<DEFAULT>",
port ? port : "<DEFAULT>",
options ? "with options " : "", options ? options : "",
user ? "for user " : "", user ? user : "",
- lineno);
- ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>");
+ lineno, errmsg);
+
+ ECPGraise(lineno, ECPG_CONNECT, db);
if (host)
ECPGfree(host);
if (port)
diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c
index 526634a0f6e..d58f6767afe 100644
--- a/src/interfaces/ecpg/lib/error.c
+++ b/src/interfaces/ecpg/lib/error.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.16 2002/09/04 20:31:46 momjian Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.17 2003/02/13 13:11:52 meskes Exp $ */
#include "postgres_fe.h"
@@ -10,6 +10,10 @@
#include "extern.h"
#include "sqlca.h"
+/* This should hold the back-end error message from
+ * the last back-end operation. */
+char *ECPGerr;
+
void
ECPGraise(int line, int code, const char *str)
{
@@ -162,6 +166,29 @@ ECPGraise(int line, int code, const char *str)
ECPGfree_auto_mem();
}
+/* Set the error message string from the backend */
+void
+set_backend_err(const char *err, int lineno)
+{
+ if (ECPGerr)
+ ECPGfree(ECPGerr);
+
+ if (!err)
+ {
+ ECPGerr = NULL;
+ return;
+ }
+
+ ECPGerr = ECPGstrdup(err, lineno);
+}
+
+/* Retrieve the error message from the backend. */
+char *
+ECPGerrmsg(void)
+{
+ return ECPGerr;
+}
+
/* print out an error message */
void
sqlprint(void)
diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c
index 70e1d633c80..10f0d8404bd 100644
--- a/src/interfaces/ecpg/lib/execute.c
+++ b/src/interfaces/ecpg/lib/execute.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.40 2002/10/21 13:09:31 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.41 2003/02/13 13:11:52 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -850,6 +850,7 @@ ECPGexecute(struct statement * stmt)
{
bool status = false;
char *copiedquery;
+ char *errmsg, *cmdstat;
PGresult *results;
PGnotify *notify;
struct variable *var;
@@ -949,9 +950,10 @@ ECPGexecute(struct statement * stmt)
if (results == NULL)
{
- ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno,
- PQerrorMessage(stmt->connection->connection));
- ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
+ errmsg = PQerrorMessage(stmt->connection->connection);
+ ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno, errmsg);
+ ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
+ set_backend_err(errmsg, stmt->lineno);
}
else
@@ -961,7 +963,9 @@ ECPGexecute(struct statement * stmt)
*/
{
bool clear_result = TRUE;
-
+ errmsg = PQresultErrorMessage(results);
+ set_backend_err(errmsg, stmt->lineno);
+
var = stmt->outlist;
switch (PQresultStatus(results))
{
@@ -1027,20 +1031,20 @@ ECPGexecute(struct statement * stmt)
break;
case PGRES_COMMAND_OK:
status = true;
+ cmdstat = PQcmdStatus(results);
sqlca.sqlerrd[1] = PQoidValue(results);
sqlca.sqlerrd[2] = atol(PQcmdTuples(results));
- ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, PQcmdStatus(results));
- if (!sqlca.sqlerrd[2] && (!strncmp(PQcmdStatus(results), "UPDATE", 6)
- || !strncmp(PQcmdStatus(results), "INSERT", 6)
- || !strncmp(PQcmdStatus(results), "DELETE", 6)))
+ ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
+ if (!sqlca.sqlerrd[2] && ( !strncmp(cmdstat, "UPDATE", 6)
+ || !strncmp(cmdstat, "INSERT", 6)
+ || !strncmp(cmdstat, "DELETE", 6)))
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
break;
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
case PGRES_BAD_RESPONSE:
- ECPGlog("ECPGexecute line %d: Error: %s",
- stmt->lineno, PQerrorMessage(stmt->connection->connection));
- ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
+ ECPGlog("ECPGexecute line %d: Error: %s", stmt->lineno, errmsg);
+ ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
status = false;
break;
case PGRES_COPY_OUT:
@@ -1054,7 +1058,7 @@ ECPGexecute(struct statement * stmt)
default:
ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
stmt->lineno);
- ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
+ ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
status = false;
break;
}
diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h
index 00a65b94e21..ad0e6b332bc 100644
--- a/src/interfaces/ecpg/lib/extern.h
+++ b/src/interfaces/ecpg/lib/extern.h
@@ -5,6 +5,10 @@
#include "libpq-fe.h"
/* Here are some methods used by the lib. */
+
+/* Stores the backend error message for client access */
+void set_backend_err(const char *err, int lineon);
+
/* Returns a pointer to a string containing a simple type name. */
void ECPGadd_mem(void *ptr, int lineno);