From 42df5e311f4444ed8bf773e3e8f6ee1195209bd7 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 15 Jul 2003 12:38:38 +0000 Subject: [PATCH] Started to create different error codes for different backend messages. --- src/interfaces/ecpg/ChangeLog | 10 +++++++ src/interfaces/ecpg/ecpglib/connect.c | 10 +++---- src/interfaces/ecpg/ecpglib/error.c | 34 ++++------------------ src/interfaces/ecpg/ecpglib/execute.c | 4 +-- src/interfaces/ecpg/ecpglib/extern.h | 7 ----- src/interfaces/ecpg/include/ecpgerrno.h | 2 ++ src/interfaces/ecpg/test/test_informix.pgc | 10 +++++++ 7 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 93622d5142..4074ab0232 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1569,6 +1569,16 @@ Wed Jul 9 11:45:02 CEST 2003 - Made all Informix functions honor Informix NULLs. - Extended compatibility functions for INFORMIX handling of DECLARE statement to work with indicators. + +Mon Jul 14 09:34:04 CEST 2003 + + - Synced preproc.y with gram.y + - Init sqlca in ECPGprepare(). + - Added CLOSE DATABASE for Informix compatibility. + +Tue Jul 15 14:28:53 CEST 2003 + + _ Started to add error codes for backend error messages. - Set ecpg version to 3.0.0 - Set ecpg library to 4.0.0 - Set pgtypes library to 1.0.0 diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 433a5e2960..d187d32f70 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.11 2003/07/08 07:13:48 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.12 2003/07/15 12:38:38 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -68,7 +68,6 @@ ecpg_finish(struct connection * act) struct ECPGtype_information_cache *cache, *ptr; - ECPGlog("ecpg_finish: finishing %s.\n", act->name); PQfinish(act->connection); /* no need to lock connections_mutex - we're always called @@ -90,6 +89,8 @@ ecpg_finish(struct connection * act) if (actual_connection == act) actual_connection = all_connections; + ECPGlog("ecpg_finish: Connection %s closed.\n", act->name); + for (cache = act->cache_head; cache; ptr = cache, cache = cache->next, ECPGfree(ptr)); ECPGfree(act->name); ECPGfree(act); @@ -481,10 +482,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p if (PQstatus(this->connection) == CONNECTION_BAD) { - const char *errmsg = PQerrorMessage(this->connection); - char *db = realname ? realname : ""; + const char *errmsg = PQerrorMessage(this->connection); + char *db = realname ? realname : ""; - set_backend_err(errmsg, lineno); ecpg_finish(this); #ifdef USE_THREADS pthread_mutex_unlock(&connections_mutex); diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c index 2203b7214a..5566c0edf6 100644 --- a/src/interfaces/ecpg/ecpglib/error.c +++ b/src/interfaces/ecpg/ecpglib/error.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.2 2003/06/15 04:07:58 momjian Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.3 2003/07/15 12:38:38 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -11,10 +11,6 @@ #include "extern.h" #include "sqlca.h" -/* This should hold the back-end error message from - * the last back-end operation. */ -static char *ECPGerr; - void ECPGraise(int line, int code, const char *str) { @@ -142,6 +138,11 @@ ECPGraise(int line, int code, const char *str) slen--; snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "'%.*s' in line %d.", slen, str, line); + if (strncmp(str, "ERROR: Cannot insert a duplicate key", strlen("ERROR: Cannot insert a duplicate key")) == 0) + sqlca->sqlcode = ECPG_DUPLICATE_KEY; + else if (strncmp(str, "ERROR: More than one tuple returned by a subselect", strlen("ERROR: More than one tuple returned by a subselect")) == 0) + sqlca->sqlcode = ECPG_SUBSELECT_NOT_ONE; + break; } @@ -168,29 +169,6 @@ 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/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 0115362a0f..4af3ba53e4 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.18 2003/07/08 12:11:29 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.19 2003/07/15 12:38:38 meskes Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -1131,7 +1131,6 @@ ECPGexecute(struct statement * stmt) 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 @@ -1144,7 +1143,6 @@ ECPGexecute(struct statement * stmt) struct sqlca_t *sqlca = ECPGget_sqlca(); errmsg = PQresultErrorMessage(results); - set_backend_err(errmsg, stmt->lineno); var = stmt->outlist; switch (PQresultStatus(results)) diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index b6b25b8328..9f16fc24ef 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -10,13 +10,6 @@ enum COMPAT_MODE { ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFO /* 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); - -/* Store and retrieve the backend error message for client access */ -void set_backend_err(const char *err, int lineon); -char *ECPGerrmsg(void); - /* Returns a pointer to a string containing a simple type name. */ void ECPGadd_mem(void *ptr, int lineno); diff --git a/src/interfaces/ecpg/include/ecpgerrno.h b/src/interfaces/ecpg/include/ecpgerrno.h index 05a1a592eb..b78ecc634c 100644 --- a/src/interfaces/ecpg/include/ecpgerrno.h +++ b/src/interfaces/ecpg/include/ecpgerrno.h @@ -47,6 +47,8 @@ #define ECPG_PGSQL -400 #define ECPG_TRANS -401 #define ECPG_CONNECT -402 +#define ECPG_DUPLICATE_KEY -403 +#define ECPG_SUBSELECT_NOT_ONE -404 /* backend WARNINGs, starting at 600 */ #define ECPG_WARNING_UNRECOGNIZED -600 diff --git a/src/interfaces/ecpg/test/test_informix.pgc b/src/interfaces/ecpg/test/test_informix.pgc index abcd65ac2d..755dab2ef2 100644 --- a/src/interfaces/ecpg/test/test_informix.pgc +++ b/src/interfaces/ecpg/test/test_informix.pgc @@ -17,8 +17,18 @@ int main() rsetnull(CDECIMALTYPE, (char *)&j); $insert into test (i, j) values (7, :j); + $commit; + + $insert into test (i, j) values (7, 2); + printf("%ld: %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); + if (sqlca.sqlcode != 0) $rollback; + $insert into test (i, j) values (:i, 1); + $select i from test where j=(select j from test); + printf("%ld: %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); + if (sqlca.sqlcode != 0) $rollback; + $declare c cursor for select * from test where i <= :i; openit();