diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/portalcmds.c | 5 | ||||
-rw-r--r-- | src/interfaces/ecpg/compatlib/Makefile | 4 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/connect.c | 174 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/data.c | 34 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/descriptor.c | 22 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/error.c | 55 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 56 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/extern.h | 26 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/memory.c | 8 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/misc.c | 13 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/prepare.c | 4 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/ecpglib.h | 6 | ||||
-rw-r--r-- | src/interfaces/ecpg/include/sqlca.h | 2 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/Makefile | 4 |
14 files changed, 176 insertions, 237 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 978f05ef928..cf4a0638717 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.18 2003/07/28 00:09:14 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.19 2003/08/01 13:53:36 petere Exp $ * *------------------------------------------------------------------------- */ @@ -169,8 +169,7 @@ PerformPortalFetch(FetchStmt *stmt, /* FIXME: shouldn't this be an ERROR? */ ereport(WARNING, (errcode(ERRCODE_UNDEFINED_CURSOR), - errmsg("portal \"%s\" does not exist", stmt->portalname), - errfunction("PerformPortalFetch"))); /* for ecpg */ + errmsg("portal \"%s\" does not exist", stmt->portalname))); if (completionTag) strcpy(completionTag, stmt->ismove ? "MOVE 0" : "FETCH 0"); return; diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile index 5bd527d98a8..83d9193dfd4 100644 --- a/src/interfaces/ecpg/compatlib/Makefile +++ b/src/interfaces/ecpg/compatlib/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.5 2003/06/24 14:45:46 momjian Exp $ +# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.6 2003/08/01 13:53:36 petere Exp $ # #------------------------------------------------------------------------- @@ -16,7 +16,7 @@ NAME= ecpg_compat SO_MAJOR_VERSION= 1 SO_MINOR_VERSION= 0.0 -override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) +override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS) SHLIB_LINK = -L../pgtypeslib -lpgtypes -L../ecpglib -lecpg OBJS= informix.o diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 44b088481c7..1030b041ab1 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.13 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.14 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -116,7 +116,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name) { if ((results = PQexec(con->connection, "begin transaction")) == NULL) { - ECPGraise(lineno, ECPG_TRANS, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); return false; } PQclear(results); @@ -130,7 +130,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name) { if ((results = PQexec(con->connection, "commit")) == NULL) { - ECPGraise(lineno, ECPG_TRANS, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); return false; } PQclear(results); @@ -154,151 +154,47 @@ ECPGsetconn(int lineno, const char *connection_name) return true; } -static void -ECPGnoticeProcessor_raise(int code, const char *message) -{ - struct sqlca_t *sqlca = ECPGget_sqlca(); - sqlca->sqlcode = code; - strncpy(sqlca->sqlerrm.sqlerrmc, message, sizeof(sqlca->sqlerrm.sqlerrmc)); - sqlca->sqlerrm.sqlerrmc[sizeof(sqlca->sqlerrm.sqlerrmc) - 1] = 0; - sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc); - - /* remove trailing newline */ - if (sqlca->sqlerrm.sqlerrml - && sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml - 1] == '\n') - { - sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml - 1] = 0; - sqlca->sqlerrm.sqlerrml--; - } - - ECPGlog("raising sqlcode %d\n", code); -} - -/* - * I know this is a mess, but we can't redesign the backend - */ static void -ECPGnoticeProcessor(void *arg, const char *message) +ECPGnoticeReceiver(void *arg, const PGresult *result) { + char *sqlstate = PQresultErrorField(result, 'C'); + char *message = PQresultErrorField(result, 'M'); struct sqlca_t *sqlca = ECPGget_sqlca(); - /* these notices raise an error */ - if (strncmp(message, "WARNING: ", 9) && strncmp(message, "NOTICE: ", 8)) - { - ECPGlog("ECPGnoticeProcessor: strange warning '%s'\n", message); - ECPGnoticeProcessor_raise(ECPG_WARNING_UNRECOGNIZED, message); - return; - } - - message += 8; - while (*message == ' ') - message++; - ECPGlog("WARNING: %s", message); - - /* WARNING: (transaction aborted): queries ignored until END */ - - /* - * WARNING: current transaction is aborted, queries ignored until end - * of transaction block - */ - if (strstr(message, "queries ignored") && strstr(message, "transaction") - && strstr(message, "aborted")) - { - ECPGnoticeProcessor_raise(ECPG_WARNING_QUERY_IGNORED, message); - return; - } + int sqlcode; - /* WARNING: PerformPortalClose: portal "*" not found */ - if ((!strncmp(message, "PerformPortalClose: portal", 26) - || !strncmp(message, "PerformPortalFetch: portal", 26)) - && strstr(message + 26, "not found")) - { - ECPGnoticeProcessor_raise(ECPG_WARNING_UNKNOWN_PORTAL, message); + /* these are not warnings */ + if (strncmp(sqlstate, "00", 2)==0) return; - } - /* WARNING: BEGIN: already a transaction in progress */ - if (!strncmp(message, "BEGIN: already a transaction in progress", 40)) - { - ECPGnoticeProcessor_raise(ECPG_WARNING_IN_TRANSACTION, message); - return; - } - - /* WARNING: AbortTransaction and not in in-progress state */ - /* WARNING: COMMIT: no transaction in progress */ - /* WARNING: ROLLBACK: no transaction in progress */ - if (!strncmp(message, "AbortTransaction and not in in-progress state", 45) - || !strncmp(message, "COMMIT: no transaction in progress", 34) - || !strncmp(message, "ROLLBACK: no transaction in progress", 36)) - { - ECPGnoticeProcessor_raise(ECPG_WARNING_NO_TRANSACTION, message); - return; - } - - /* WARNING: BlankPortalAssignName: portal * already exists */ - if (!strncmp(message, "BlankPortalAssignName: portal", 29) - && strstr(message + 29, "already exists")) - { - ECPGnoticeProcessor_raise(ECPG_WARNING_PORTAL_EXISTS, message); - return; - } - - /* these are harmless - do nothing */ - - /* - * WARNING: CREATE TABLE / PRIMARY KEY will create implicit index '*' - * for table '*' - */ - - /* - * WARNING: ALTER TABLE ... ADD CONSTRAINT will create implicit - * trigger(s) for FOREIGN KEY check(s) - */ - - /* - * WARNING: CREATE TABLE will create implicit sequence '*' for SERIAL - * column '*.*' - */ - - /* - * WARNING: CREATE TABLE will create implicit trigger(s) for FOREIGN - * KEY check(s) - */ - if ((!strncmp(message, "CREATE TABLE", 12) || !strncmp(message, "ALTER TABLE", 11)) - && strstr(message + 11, "will create implicit")) - return; - - /* WARNING: QUERY PLAN: */ - if (!strncmp(message, "QUERY PLAN:", 11)) /* do we really see these? */ - return; - - /* - * WARNING: DROP TABLE implicitly drops referential integrity trigger - * from table "*" - */ - if (!strncmp(message, "DROP TABLE implicitly drops", 27)) - return; - - /* - * WARNING: Caution: DROP INDEX cannot be rolled back, so don't abort - * now - */ - if (strstr(message, "cannot be rolled back")) - return; + ECPGlog("%s", message); + + /* map to SQLCODE for backward compatibility */ + if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME)==0) + sqlcode = ECPG_WARNING_UNKNOWN_PORTAL; + else if (strcmp(sqlstate, ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION)==0) + sqlcode = ECPG_WARNING_IN_TRANSACTION; + else if (strcmp(sqlstate, ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION)==0) + sqlcode = ECPG_WARNING_NO_TRANSACTION; + else if (strcmp(sqlstate, ECPG_SQLSTATE_DUPLICATE_CURSOR)==0) + sqlcode = ECPG_WARNING_PORTAL_EXISTS; + else + sqlcode = 0; - /* these and other unmentioned should set sqlca->sqlwarn[2] */ - /* WARNING: The ':' operator is deprecated. Use exp(x) instead. */ - /* WARNING: Rel *: Uninitialized page 0 - fixing */ - /* WARNING: PortalHeapMemoryFree: * not in alloc set! */ - /* WARNING: Too old parent tuple found - can't continue vc_repair_frag */ - /* WARNING: identifier "*" will be truncated to "*" */ - /* WARNING: InvalidateSharedInvalid: cache state reset */ - /* WARNING: RegisterSharedInvalid: SI buffer overflow */ + strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate)); + sqlca->sqlcode = sqlcode; sqlca->sqlwarn[2] = 'W'; sqlca->sqlwarn[0] = 'W'; + + strncpy(sqlca->sqlerrm.sqlerrmc, message, sizeof(sqlca->sqlerrm.sqlerrmc)); + sqlca->sqlerrm.sqlerrmc[sizeof(sqlca->sqlerrm.sqlerrmc) - 1] = 0; + sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc); + + ECPGlog("raising sqlcode %d\n", sqlcode); } + /* this contains some quick hacks, needs to be cleaned up, but it works */ bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit) @@ -406,7 +302,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p if (strncmp(dbname, "unix:", 5) != 0) { ECPGlog("connect: socketname %s given for TCP connection in line %d\n", host, lineno); - ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>", ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>"); if (host) ECPGfree(host); if (port) @@ -429,7 +325,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p if (strcmp(dbname + offset, "localhost") != 0 && strcmp(dbname + offset, "127.0.0.1") != 0) { ECPGlog("connect: non-localhost access via sockets in line %d\n", lineno); - ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>", ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, realname ? realname : "<DEFAULT>"); if (host) ECPGfree(host); if (port) @@ -497,7 +393,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p user ? "for user " : "", user ? user : "", lineno, errmsg); - ECPGraise(lineno, ECPG_CONNECT, db, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db); if (host) ECPGfree(host); if (port) @@ -528,7 +424,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p this->committed = true; this->autocommit = autocommit; - PQsetNoticeProcessor(this->connection, &ECPGnoticeProcessor, (void *) this); + PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this); return true; } diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 361dfa73a4a..14e459d1b60 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.14 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.15 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -34,7 +34,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, { if (*pval != '{') { - ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, NULL, compat); + ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); return (false); } @@ -90,13 +90,13 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, } else { - ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL, compat); + ECPGraise(lineno, ECPG_MISSING_INDICATOR, ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, NULL); return (false); } } break; default: - ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(ind_type), compat); + ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(ind_type)); return (false); break; } @@ -126,7 +126,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_INT_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -159,7 +159,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_UINT_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -192,7 +192,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_INT_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -209,7 +209,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_UINT_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -235,7 +235,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_FLOAT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -266,7 +266,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, else if (offset == sizeof(int)) *((int *) (var + offset * act_tuple)) = false; else - ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size", compat); + ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size"); break; } else if (pval[0] == 't' && pval[1] == '\0') @@ -276,7 +276,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, else if (offset == sizeof(int)) *((int *) (var + offset * act_tuple)) = true; else - ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size", compat); + ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size"); break; } else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field)) @@ -286,7 +286,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, } } - ECPGraise(lineno, ECPG_CONVERT_BOOL, pval, compat); + ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); break; @@ -396,7 +396,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_NUMERIC_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -423,7 +423,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_INTERVAL_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } } @@ -446,7 +446,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_DATE_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } @@ -468,7 +468,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, if ((isarray && *scan_length != ',' && *scan_length != '}') || (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */ { - ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, pval, compat); + ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } @@ -477,7 +477,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, break; default: - ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type), compat); + ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(type)); return (false); break; } diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c index bdb308810da..0beae2d93ab 100644 --- a/src/interfaces/ecpg/ecpglib/descriptor.c +++ b/src/interfaces/ecpg/ecpglib/descriptor.c @@ -1,6 +1,6 @@ /* dynamic SQL support routines * - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.4 2003/08/01 08:21:04 meskes Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.5 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL @@ -103,7 +103,7 @@ get_int_item(int lineno, void *var, enum ECPGttype vartype, int value) *(double *) var = (double) value; break; default: - ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION, NULL); return (false); } @@ -135,7 +135,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va } break; default: - ECPGraise(lineno, ECPG_VAR_NOT_CHAR, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_VAR_NOT_CHAR, ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION, NULL); return (false); } @@ -162,13 +162,13 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) ntuples = PQntuples(ECPGresult); if (ntuples < 1) { - ECPGraise(lineno, ECPG_NOT_FOUND, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); return (false); } if (index < 1 || index > PQnfields(ECPGresult)) { - ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX, NULL); return (false); } @@ -300,7 +300,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) { ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n", lineno, ntuples, arrsize); - ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } /* allocate storage if needed */ @@ -324,7 +324,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) default: snprintf(type_str, sizeof(type_str), "%d", type); - ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, type_str); return (false); } @@ -361,7 +361,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) { ECPGlog("ECPGget_desc line %d: Incorrect number of matches (indicator): %d don't fit into array of %d\n", lineno, ntuples, data_var.ind_arrsize); - ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } /* allocate storage if needed */ @@ -404,7 +404,7 @@ ECPGdeallocate_desc(int line, const char *name) return true; } } - ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name, ECPG_COMPAT_PGSQL); + ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, name); return false; } @@ -430,7 +430,7 @@ ECPGallocate_desc(int line, const char *name) { ECPGfree(new->name); ECPGfree(new); - ECPGraise(line, ECPG_OUT_OF_MEMORY, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(line, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); return false; } strcpy(new->name, name); @@ -449,7 +449,7 @@ ECPGdescriptor_lvalue(int line, const char *descriptor) return &i->result; } - ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, (char *) descriptor, ECPG_COMPAT_PGSQL); + ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, (char *) descriptor); return NULL; } diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c index 0b4b563d85a..cfeb4e65b0b 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.4 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.5 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -11,11 +11,13 @@ #include "extern.h" #include "sqlca.h" + void -ECPGraise(int line, int code, const char *str, int compat) +ECPGraise(int line, int code, const char * sqlstate, const char *str) { struct sqlca_t *sqlca = ECPGget_sqlca(); sqlca->sqlcode = code; + strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate)); switch (code) { @@ -129,23 +131,6 @@ ECPGraise(int line, int code, const char *str, int compat) "Variable is not a character type in line %d.", line); break; - case ECPG_PGSQL: - { - int slen = strlen(str); - - /* strip trailing newline */ - if (slen > 0 && str[slen - 1] == '\n') - 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 = INFORMIX_MODE(compat) ? ECPG_INFORMIX_DUPLICATE_KEY : 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 = INFORMIX_MODE(compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_SUBSELECT_NOT_ONE; - - break; - } - case ECPG_TRANS: snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "Error in transaction processing in line %d.", line); @@ -169,6 +154,38 @@ ECPGraise(int line, int code, const char *str, int compat) ECPGfree_auto_mem(); } +void +ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat) +{ + struct sqlca_t *sqlca = ECPGget_sqlca(); + + /* copy error message */ + snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), + "'%s' in line %d.", + result ? PQresultErrorField(result, 'M') : PQerrorMessage(conn), + line); + sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc); + + /* copy SQLSTATE */ + strncpy(sqlca->sqlstate, + result ? PQresultErrorField(result, 'C') : ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, + sizeof(sqlca->sqlstate)); + + /* assign SQLCODE for backward compatibility */ + if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate))==0) + sqlca->sqlcode = INFORMIX_MODE(compat) ? ECPG_INFORMIX_DUPLICATE_KEY : ECPG_DUPLICATE_KEY; + if (strncmp(sqlca->sqlstate, "21000", sizeof(sqlca->sqlstate))==0) + sqlca->sqlcode = INFORMIX_MODE(compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_SUBSELECT_NOT_ONE; + else + sqlca->sqlcode = ECPG_PGSQL; + + ECPGlog("raising sqlstate %.*s in line %d, '%s'.\n", + sqlca->sqlstate, sizeof(sqlca->sqlstate), line, sqlca->sqlerrm.sqlerrmc); + + /* free all memory we have allocated for the user */ + ECPGfree_auto_mem(); +} + /* 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 8e9545f0ab4..0d4247897d5 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.21 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.22 2003/08/01 13:53:36 petere Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -124,7 +124,7 @@ create_statement(int lineno, int compat, int force_indicator, struct connection /* if variable is NULL, the statement hasn't been prepared */ if (var->pointer == NULL) { - ECPGraise(lineno, ECPG_INVALID_STMT, NULL, compat); + ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL); ECPGfree(var); return false; } @@ -351,7 +351,7 @@ ECPGstore_result(const PGresult *results, int act_field, { ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d\n", stmt->lineno, ntuples, var->arrsize); - ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } } @@ -362,7 +362,7 @@ ECPGstore_result(const PGresult *results, int act_field, */ if (var->arrsize == 0) { - ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(stmt->lineno, ECPG_NO_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); return false; } } @@ -481,12 +481,13 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, * arrays are not possible unless the attribute is an array too FIXME: * we do not know if the attribute is an array here */ - -/* if (var->arrsize > 1 && ...) +#if 0 + if (var->arrsize > 1 && ...) { - ECPGraise(stmt->lineno, ECPG_ARRAY_INSERT, NULL, compat); + ECPGraise(stmt->lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); return false; - }*/ + } +#endif /* * Some special treatment is needed for records since we want their @@ -757,7 +758,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f'); else - ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size", ECPG_COMPAT_PGSQL); + ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size"); strcpy(mallocedval + strlen(mallocedval) - 1, "]"); } @@ -768,7 +769,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, else if (var->offset == sizeof(int)) sprintf(mallocedval, "'%c'", (*((int *) var->value)) ? 't' : 'f'); else - ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size", ECPG_COMPAT_PGSQL); + ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size"); } *tobeinserted_p = mallocedval; @@ -1021,7 +1022,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var, default: /* Not implemented yet */ - ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type), ECPG_COMPAT_PGSQL); + ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (char *) ECPGtype_name(var->type)); return false; break; } @@ -1034,7 +1035,7 @@ ECPGexecute(struct statement * stmt) { bool status = false; char *copiedquery; - char *errmsg, *cmdstat; + char *cmdstat; PGresult *results; PGnotify *notify; struct variable *var; @@ -1073,7 +1074,7 @@ ECPGexecute(struct statement * stmt) * We have an argument but we dont have the matched up string * in the string */ - ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); return false; } else @@ -1111,7 +1112,7 @@ ECPGexecute(struct statement * stmt) /* Check if there are unmatched things left. */ if (next_insert(copiedquery) != NULL) { - ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); return false; } @@ -1121,7 +1122,7 @@ ECPGexecute(struct statement * stmt) { if ((results = PQexec(stmt->connection->connection, "begin transaction")) == NULL) { - ECPGraise(stmt->lineno, ECPG_TRANS, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); return false; } PQclear(results); @@ -1134,9 +1135,8 @@ ECPGexecute(struct statement * stmt) if (results == NULL) { - errmsg = PQerrorMessage(stmt->connection->connection); - ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno, errmsg); - ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg, stmt->compat); + ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno, PQerrorMessage(stmt->connection->connection)); + ECPGraise_backend(stmt->lineno, NULL, stmt->connection->connection, stmt->compat); } else @@ -1148,8 +1148,6 @@ ECPGexecute(struct statement * stmt) bool clear_result = TRUE; struct sqlca_t *sqlca = ECPGget_sqlca(); - errmsg = PQresultErrorMessage(results); - var = stmt->outlist; switch (PQresultStatus(results)) { @@ -1167,7 +1165,7 @@ ECPGexecute(struct statement * stmt) if (ntuples) ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n", stmt->lineno, ntuples); - ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); status = false; break; } @@ -1198,21 +1196,21 @@ ECPGexecute(struct statement * stmt) } else if (!INFORMIX_MODE(stmt->compat)) { - ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL); return (false); } } if (status && var != NULL) { - ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL); status = false; } break; case PGRES_EMPTY_QUERY: /* do nothing */ - ECPGraise(stmt->lineno, ECPG_EMPTY, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL); break; case PGRES_COMMAND_OK: status = true; @@ -1225,13 +1223,13 @@ ECPGexecute(struct statement * stmt) ( !strncmp(cmdstat, "UPDATE", 6) || !strncmp(cmdstat, "INSERT", 6) || !strncmp(cmdstat, "DELETE", 6))) - ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL, stmt->compat); + ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); break; case PGRES_NONFATAL_ERROR: case PGRES_FATAL_ERROR: case PGRES_BAD_RESPONSE: - ECPGlog("ECPGexecute line %d: Error: %s", stmt->lineno, errmsg); - ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg, stmt->compat); + ECPGlog("ECPGexecute line %d: Error: %s", stmt->lineno, PQresultErrorMessage(results)); + ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat); status = false; break; case PGRES_COPY_OUT: @@ -1245,7 +1243,7 @@ ECPGexecute(struct statement * stmt) default: ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n", stmt->lineno); - ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg, stmt->compat); + ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat); status = false; break; } @@ -1300,7 +1298,7 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, if (con == NULL || con->connection == NULL) { free_statement(stmt); - ECPGraise(lineno, ECPG_NOT_CONN, (con) ? con->name : "<empty>", stmt->compat); + ECPGraise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : "<empty>"); setlocale(LC_NUMERIC, oldlocale); ECPGfree(oldlocale); return false; diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index 9f16fc24efa..d98f158bacc 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -98,4 +98,30 @@ PGresult ** bool ECPGstore_result(const PGresult *results, int act_field, const struct statement * stmt, struct variable * var); +/* SQLSTATE values generated or processed by ecpglib (intentionally + * not exported -- users should refer to the codes directly) */ + +#define ECPG_SQLSTATE_NO_DATA "02000" +#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS "07001" +#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS "07002" +#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION "07006" +#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX "07009" +#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001" +#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003" +#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007" +#define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000" +#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002" +#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001" +#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01" +#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME "26000" +#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME "33000" +#define ECPG_SQLSTATE_INVALID_CURSOR_NAME "34000" +#define ECPG_SQLSTATE_SYNTAX_ERROR "42601" +#define ECPG_SQLSTATE_DATATYPE_MISMATCH "42804" +#define ECPG_SQLSTATE_DUPLICATE_CURSOR "42P03" + +/* implementation-defined internal errors of ecpg */ +#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000" +#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001" + #endif /* _ECPG_LIB_EXTERN_H */ diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c index 0a77da4f095..524192d7ca8 100644 --- a/src/interfaces/ecpg/ecpglib/memory.c +++ b/src/interfaces/ecpg/ecpglib/memory.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.3 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.4 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -21,7 +21,7 @@ ECPGalloc(long size, int lineno) if (!new) { - ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); return NULL; } @@ -36,7 +36,7 @@ ECPGrealloc(void *ptr, long size, int lineno) if (!new) { - ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); return NULL; } @@ -50,7 +50,7 @@ ECPGstrdup(const char *string, int lineno) if (!new) { - ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); return NULL; } diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index 4334844d61d..f42b8f721e7 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.11 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.12 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -47,7 +47,7 @@ static struct sqlca_t sqlca_init = 0, 0, 0, 0, 0, 0, 0, 0 }, { - 0, 0, 0, 0, 0, 0, 0, 0 + '0', '0', '0', '0', '0' } }; @@ -78,7 +78,7 @@ static struct sqlca_t sqlca = 0, 0, 0, 0, 0, 0, 0, 0 }, { - 0, 0, 0, 0, 0, 0, 0, 0 + '0', '0', '0', '0', '0' } }; #endif @@ -103,7 +103,8 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l ECPGinit_sqlca(sqlca); if (con == NULL) { - ECPGraise(lineno, ECPG_NO_CONN, connection_name ? connection_name : "NULL", ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_NO_CONN, ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST, + connection_name ? connection_name : "NULL"); return (false); } @@ -150,7 +151,7 @@ ECPGstatus(int lineno, const char *connection_name) /* are we connected? */ if (con->connection == NULL) { - ECPGraise(lineno, ECPG_NOT_CONN, con->name, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, con->name); return false; } @@ -179,7 +180,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) { if ((res = PQexec(con->connection, transaction)) == NULL) { - ECPGraise(lineno, ECPG_TRANS, NULL, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL); return FALSE; } PQclear(res); diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c index 76c58d1238c..5569d36da07 100644 --- a/src/interfaces/ecpg/ecpglib/prepare.c +++ b/src/interfaces/ecpg/ecpglib/prepare.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.7 2003/08/01 08:21:04 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.8 2003/08/01 13:53:36 petere Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -120,7 +120,7 @@ ECPGdeallocate(int lineno, int c, char *name) } if (!ret) - ECPGraise(lineno, ECPG_INVALID_STMT, name, ECPG_COMPAT_PGSQL); + ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, name); return ret; } diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index e99c50bc866..3f510fbfa60 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -6,7 +6,8 @@ #ifndef _ECPGLIB_H #define _ECPGLIB_H -#include <stdio.h> +#include "postgres_fe.h" +#include "libpq-fe.h" #ifndef __BEOS__ #ifndef __cplusplus @@ -71,7 +72,8 @@ bool ECPGdo_descriptor(int line, const char *connection, const char *descriptor, const char *query); bool ECPGdeallocate_desc(int line, const char *name); bool ECPGallocate_desc(int line, const char *name); -void ECPGraise(int line, int code, const char *str, int); +void ECPGraise(int line, int code, const char *sqlstate, const char *str); +void ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat); bool ECPGget_desc_header(int, char *, int *); bool ECPGget_desc(int, char *, int,...); diff --git a/src/interfaces/ecpg/include/sqlca.h b/src/interfaces/ecpg/include/sqlca.h index 8af23921d78..37370b6f605 100644 --- a/src/interfaces/ecpg/include/sqlca.h +++ b/src/interfaces/ecpg/include/sqlca.h @@ -50,7 +50,7 @@ struct sqlca_t /* 6: empty */ /* 7: empty */ - char sqlext[8]; + char sqlstate[5]; }; struct sqlca_t *ECPGget_sqlca(void); diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index 7e7f1fee07d..357779863d0 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -1,10 +1,10 @@ -# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.38 2003/07/01 12:40:52 meskes Exp $ +# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.39 2003/08/01 13:53:36 petere Exp $ subdir = src/interfaces/ecpg/test top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -override CPPFLAGS := -I$(srcdir)/../include $(CPPFLAGS) +override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) ECPG = ../preproc/ecpg -I$(srcdir)/../include |