mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Make ecpg SQLSTATE-aware. Map existing SQLCODE assignments to SQLSTATEs,
rather than parsing the message. Add some documentation about embedded SQL.
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user