diff options
author | Michael Meskes <meskes@postgresql.org> | 2007-08-14 10:01:54 +0000 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2007-08-14 10:01:54 +0000 |
commit | 635a0b9a8640bb7f2944a3f77ddc370f8dd7b010 (patch) | |
tree | d54146b2416fecd2a544f3bf786108079b879cfc /src/interfaces/ecpg/ecpglib/error.c | |
parent | b83bd31bd953b6daa22bcbdaee5ade2a27ec7324 (diff) | |
download | postgresql-635a0b9a8640bb7f2944a3f77ddc370f8dd7b010.tar.gz postgresql-635a0b9a8640bb7f2944a3f77ddc370f8dd7b010.zip |
- Finished major rewrite to use new protocol version
- Really prepare statements
- Added more regression tests
- Added auto-prepare mode
- Use '$n' for positional variables, '?' is still possible via ecpg option
- Cleaned up the sources a little bit
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/error.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/error.c | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c index 12d948b3d17..ef15cccb94a 100644 --- a/src/interfaces/ecpg/ecpglib/error.c +++ b/src/interfaces/ecpg/ecpglib/error.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.16 2007/05/31 15:13:05 petere Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.17 2007/08/14 10:01:52 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -9,7 +9,6 @@ #include "extern.h" #include "sqlca.h" - void ECPGraise(int line, int code, const char *sqlstate, const char *str) { @@ -196,6 +195,59 @@ ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat) ECPGfree_auto_mem(); } +/* filter out all error codes */ +bool +ECPGcheck_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat) +{ + if (results == NULL) + { + ECPGlog("ECPGcheck_PQresult line %d: error: %s", lineno, PQerrorMessage(connection)); + ECPGraise_backend(lineno, NULL, connection, compat); + return (false); + } + + switch (PQresultStatus(results)) + { + + case PGRES_TUPLES_OK: + return (true); + break; + case PGRES_EMPTY_QUERY: + /* do nothing */ + ECPGraise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL); + PQclear(results); + return (false); + break; + case PGRES_COMMAND_OK: + return (true); + break; + case PGRES_NONFATAL_ERROR: + case PGRES_FATAL_ERROR: + case PGRES_BAD_RESPONSE: + ECPGlog("ECPGcheck_PQresult line %d: Error: %s", lineno, PQresultErrorMessage(results)); + ECPGraise_backend(lineno, results, connection, compat); + PQclear(results); + return (false); + break; + case PGRES_COPY_OUT: + return(true); + break; + case PGRES_COPY_IN: + ECPGlog("ECPGcheck_PQresult line %d: Got PGRES_COPY_IN ... tossing.\n", lineno); + PQendcopy(connection); + PQclear(results); + return(false); + break; + default: + ECPGlog("ECPGcheck_PQresult line %d: Got something else, postgres error.\n", + lineno); + ECPGraise_backend(lineno, results, connection, compat); + PQclear(results); + return(false); + break; + } +} + /* print out an error message */ void sqlprint(void) |