Started to create different error codes for different backend messages.
authorMichael Meskes
Tue, 15 Jul 2003 12:38:38 +0000 (12:38 +0000)
committerMichael Meskes
Tue, 15 Jul 2003 12:38:38 +0000 (12:38 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ecpglib/connect.c
src/interfaces/ecpg/ecpglib/error.c
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/extern.h
src/interfaces/ecpg/include/ecpgerrno.h
src/interfaces/ecpg/test/test_informix.pgc

index 93622d5142efab22a94a17196588451a8550dabc..4074ab023202de9b5da7890de93b09127a644b6a 100644 (file)
@@ -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
index 433a5e2960210f16b3f076a6afa469568d64b794..d187d32f7081bda0e82e0ae18a307dfffdabb0db 100644 (file)
@@ -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);
index 2203b7214a283e1d9878ef6d320732899ae61bbf..5566c0edf66584babcec20a53aba5bb85efa1f73 100644 (file)
@@ -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"
 #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)
index 0115362a0fff40d7504de5dc8772b6d8c7e3fda2..4af3ba53e4504d121bf2868cd37e0f63dc07bb1c 100644 (file)
@@ -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))
index b6b25b8328a926709b0e3bffd765aba3f71f247f..9f16fc24efaf49386d3cce1027967e4dd9723062 100644 (file)
@@ -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);
 
index 05a1a592eb452521d04d3202a97d449ed4b182a8..b78ecc634cfc27bc62a5e6a8948d0435ca2db815 100644 (file)
@@ -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
index abcd65ac2d6f8fd133f0a0311f7fcb53399f8e2d..755dab2ef2458eb80ea2d472e6bfd0369276609b 100644 (file)
@@ -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();