Commit 3b04893f authored by Tom Lane's avatar Tom Lane

Error message editing in src/pl. The plpython module could use another

look ... I'm not real certain which errors are strictly internal and which
are likely to be provoked by users.
parent 400fedc8
#include "postgres.h" #include "postgres.h"
#include "utils/elog.h"
/* /*
* This kludge is necessary because of the conflicting * This kludge is necessary because of the conflicting
* definitions of 'DEBUG' between postgres and perl. * definitions of 'DEBUG' between postgres and perl.
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* ENHANCEMENTS, OR MODIFICATIONS. * ENHANCEMENTS, OR MODIFICATIONS.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.36 2003/04/20 21:15:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.37 2003/07/25 23:37:28 tgl Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
/* postgreSQL stuff */ /* postgreSQL stuff */
#include "executor/spi.h" #include "executor/spi.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "utils/elog.h"
#include "fmgr.h" #include "fmgr.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
...@@ -193,7 +192,7 @@ plperl_init_interp(void) ...@@ -193,7 +192,7 @@ plperl_init_interp(void)
plperl_interp = perl_alloc(); plperl_interp = perl_alloc();
if (!plperl_interp) if (!plperl_interp)
elog(ERROR, "plperl_init_interp(): could not allocate perl interpreter"); elog(ERROR, "could not allocate perl interpreter");
perl_construct(plperl_interp); perl_construct(plperl_interp);
perl_parse(plperl_interp, plperl_init_shared_libs, 3, embedding, NULL); perl_parse(plperl_interp, plperl_init_shared_libs, 3, embedding, NULL);
...@@ -232,7 +231,7 @@ plperl_call_handler(PG_FUNCTION_ARGS) ...@@ -232,7 +231,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
* Connect to SPI manager * Connect to SPI manager
************************************************************/ ************************************************************/
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "plperl: cannot connect to SPI manager"); elog(ERROR, "could not connect to SPI manager");
/************************************************************ /************************************************************
* Determine if called as function or trigger and * Determine if called as function or trigger and
...@@ -240,7 +239,9 @@ plperl_call_handler(PG_FUNCTION_ARGS) ...@@ -240,7 +239,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
************************************************************/ ************************************************************/
if (CALLED_AS_TRIGGER(fcinfo)) if (CALLED_AS_TRIGGER(fcinfo))
{ {
elog(ERROR, "plperl: can't use perl in triggers yet."); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot use perl in triggers yet")));
/* /*
* retval = PointerGetDatum(plperl_trigger_handler(fcinfo)); * retval = PointerGetDatum(plperl_trigger_handler(fcinfo));
...@@ -286,7 +287,7 @@ plperl_create_sub(char *s, bool trusted) ...@@ -286,7 +287,7 @@ plperl_create_sub(char *s, bool trusted)
PUTBACK; PUTBACK;
FREETMPS; FREETMPS;
LEAVE; LEAVE;
elog(ERROR, "plperl: didn't get a return item from mksafefunc"); elog(ERROR, "didn't get a return item from mksafefunc");
} }
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
...@@ -314,7 +315,7 @@ plperl_create_sub(char *s, bool trusted) ...@@ -314,7 +315,7 @@ plperl_create_sub(char *s, bool trusted)
* subref is our responsibility because it is not mortal * subref is our responsibility because it is not mortal
*/ */
SvREFCNT_dec(subref); SvREFCNT_dec(subref);
elog(ERROR, "plperl_create_sub: didn't get a code ref"); elog(ERROR, "didn't get a code ref");
} }
PUTBACK; PUTBACK;
...@@ -406,7 +407,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo) ...@@ -406,7 +407,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
PUTBACK; PUTBACK;
FREETMPS; FREETMPS;
LEAVE; LEAVE;
elog(ERROR, "plperl: didn't get a return item from function"); elog(ERROR, "didn't get a return item from function");
} }
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
...@@ -415,7 +416,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo) ...@@ -415,7 +416,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
PUTBACK; PUTBACK;
FREETMPS; FREETMPS;
LEAVE; LEAVE;
elog(ERROR, "plperl: error from function: %s", SvPV(ERRSV, PL_na)); elog(ERROR, "error from function: %s", SvPV(ERRSV, PL_na));
} }
retval = newSVsv(POPs); retval = newSVsv(POPs);
...@@ -453,7 +454,7 @@ plperl_func_handler(PG_FUNCTION_ARGS) ...@@ -453,7 +454,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
* because SPI_finish would free it). * because SPI_finish would free it).
************************************************************/ ************************************************************/
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "plperl: SPI_finish() failed"); elog(ERROR, "SPI_finish() failed");
if (!(perlret && SvOK(perlret))) if (!(perlret && SvOK(perlret)))
{ {
...@@ -493,7 +494,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -493,7 +494,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
ObjectIdGetDatum(fn_oid), ObjectIdGetDatum(fn_oid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procTup)) if (!HeapTupleIsValid(procTup))
elog(ERROR, "plperl: cache lookup for proc %u failed", fn_oid); elog(ERROR, "cache lookup failed for function %u", fn_oid);
procStruct = (Form_pg_proc) GETSTRUCT(procTup); procStruct = (Form_pg_proc) GETSTRUCT(procTup);
/************************************************************ /************************************************************
...@@ -551,7 +552,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -551,7 +552,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
************************************************************/ ************************************************************/
prodesc = (plperl_proc_desc *) malloc(sizeof(plperl_proc_desc)); prodesc = (plperl_proc_desc *) malloc(sizeof(plperl_proc_desc));
if (prodesc == NULL) if (prodesc == NULL)
elog(ERROR, "plperl: out of memory"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
MemSet(prodesc, 0, sizeof(plperl_proc_desc)); MemSet(prodesc, 0, sizeof(plperl_proc_desc));
prodesc->proname = strdup(internal_proname); prodesc->proname = strdup(internal_proname);
prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data); prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
...@@ -567,7 +570,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -567,7 +570,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl: cache lookup for language %u failed", elog(ERROR, "cache lookup failed for language %u",
procStruct->prolang); procStruct->prolang);
} }
langStruct = (Form_pg_language) GETSTRUCT(langTup); langStruct = (Form_pg_language) GETSTRUCT(langTup);
...@@ -587,7 +590,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -587,7 +590,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl: cache lookup for return type %u failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->prorettype); procStruct->prorettype);
} }
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
...@@ -601,16 +604,18 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -601,16 +604,18 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl functions cannot return type %s" ereport(ERROR,
"\n\texcept when used as triggers", (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
format_type_be(procStruct->prorettype)); errmsg("trigger functions may only be called as triggers")));
} }
else else
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl functions cannot return type %s", ereport(ERROR,
format_type_be(procStruct->prorettype)); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plperl functions cannot return type %s",
format_type_be(procStruct->prorettype))));
} }
} }
...@@ -618,7 +623,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -618,7 +623,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl: return types of tuples not supported yet"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plperl functions cannot return tuples yet")));
} }
perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func)); perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func));
...@@ -643,7 +650,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -643,7 +650,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl: cache lookup for argument type %u failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->proargtypes[i]); procStruct->proargtypes[i]);
} }
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
...@@ -653,8 +660,10 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -653,8 +660,10 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl functions cannot take type %s", ereport(ERROR,
format_type_be(procStruct->proargtypes[i])); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plperl functions cannot take type %s",
format_type_be(procStruct->proargtypes[i]))));
} }
if (typeStruct->typrelid != InvalidOid) if (typeStruct->typrelid != InvalidOid)
...@@ -686,7 +695,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ...@@ -686,7 +695,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "plperl: cannot create internal procedure %s", elog(ERROR, "could not create internal procedure \"%s\"",
internal_proname); internal_proname);
} }
...@@ -751,8 +760,8 @@ plperl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc) ...@@ -751,8 +760,8 @@ plperl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc)
ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), ObjectIdGetDatum(tupdesc->attrs[i]->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
elog(ERROR, "plperl: Cache lookup for attribute '%s' type %u failed", elog(ERROR, "cache lookup failed for type %u",
attname, tupdesc->attrs[i]->atttypid); tupdesc->attrs[i]->atttypid);
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.44 2003/05/27 17:49:47 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.45 2003/07/25 23:37:28 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -340,11 +340,17 @@ decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval ...@@ -340,11 +340,17 @@ decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval
row->lineno = $1.lineno; row->lineno = $1.lineno;
if ($2) if ($2)
elog(ERROR, "Rowtype variable cannot be CONSTANT"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("rowtype variable cannot be CONSTANT")));
if ($4) if ($4)
elog(ERROR, "Rowtype variable cannot be NOT NULL"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("rowtype variable cannot be NOT NULL")));
if ($5 != NULL) if ($5 != NULL)
elog(ERROR, "Default value for rowtype variable is not supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("default value for rowtype variable is not supported")));
plpgsql_adddatum((PLpgSQL_datum *)row); plpgsql_adddatum((PLpgSQL_datum *)row);
plpgsql_ns_additem(PLPGSQL_NSTYPE_ROW, plpgsql_ns_additem(PLPGSQL_NSTYPE_ROW,
...@@ -554,7 +560,10 @@ decl_aliasitem : T_WORD ...@@ -554,7 +560,10 @@ decl_aliasitem : T_WORD
if (nsi == NULL) if (nsi == NULL)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "function has no parameter %s", name); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_PARAMETER),
errmsg("function has no parameter \"%s\"",
name)));
} }
plpgsql_ns_setlocal(true); plpgsql_ns_setlocal(true);
...@@ -1087,7 +1096,8 @@ stmt_fors : opt_label K_FOR lno fors_target K_IN K_SELECT expr_until_loop loop_ ...@@ -1087,7 +1096,8 @@ stmt_fors : opt_label K_FOR lno fors_target K_IN K_SELECT expr_until_loop loop_
new->row = (PLpgSQL_row *)$4; new->row = (PLpgSQL_row *)$4;
break; break;
default: default:
elog(ERROR, "unknown dtype %d in stmt_fors", $4->dtype); elog(ERROR, "unrecognized dtype: %d",
$4->dtype);
} }
new->query = $7; new->query = $7;
new->body = $8; new->body = $8;
...@@ -1117,7 +1127,8 @@ stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop lo ...@@ -1117,7 +1127,8 @@ stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop lo
new->row = (PLpgSQL_row *)$4; new->row = (PLpgSQL_row *)$4;
break; break;
default: default:
elog(ERROR, "unknown dtype %d in stmt_dynfors", $4->dtype); elog(ERROR, "unrecognized dtype: %d",
$4->dtype);
} }
new->query = $7; new->query = $7;
new->body = $8; new->body = $8;
...@@ -1375,7 +1386,11 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1375,7 +1386,11 @@ stmt_open : K_OPEN lno cursor_varptr
if (tok != K_FOR) if (tok != K_FOR)
{ {
plpgsql_error_lineno = $2; plpgsql_error_lineno = $2;
elog(ERROR, "syntax error at \"%s\" - expected FOR to open a reference cursor", yytext); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error at \"%s\"",
yytext),
errdetail("Expected FOR to open a reference cursor.")));
} }
tok = yylex(); tok = yylex();
...@@ -1391,7 +1406,10 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1391,7 +1406,10 @@ stmt_open : K_OPEN lno cursor_varptr
default: default:
plpgsql_error_lineno = $2; plpgsql_error_lineno = $2;
elog(ERROR, "syntax error at \"%s\"", yytext); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error at \"%s\"",
yytext)));
} }
} }
...@@ -1406,8 +1424,10 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1406,8 +1424,10 @@ stmt_open : K_OPEN lno cursor_varptr
if (tok != '(') if (tok != '(')
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "cursor %s has arguments", ereport(ERROR,
$3->refname); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cursor \"%s\" has arguments",
$3->refname)));
} }
/* /*
...@@ -1428,7 +1448,8 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1428,7 +1448,8 @@ stmt_open : K_OPEN lno cursor_varptr
if (strncmp(cp, "SELECT", 6) != 0) if (strncmp(cp, "SELECT", 6) != 0)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", /* internal error */
elog(ERROR, "expected \"SELECT (\", got \"%s\"",
new->argquery->query); new->argquery->query);
} }
cp += 6; cp += 6;
...@@ -1437,7 +1458,8 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1437,7 +1458,8 @@ stmt_open : K_OPEN lno cursor_varptr
if (*cp != '(') if (*cp != '(')
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", /* internal error */
elog(ERROR, "expected \"SELECT (\", got \"%s\"",
new->argquery->query); new->argquery->query);
} }
*cp = ' '; *cp = ' ';
...@@ -1455,13 +1477,19 @@ stmt_open : K_OPEN lno cursor_varptr ...@@ -1455,13 +1477,19 @@ stmt_open : K_OPEN lno cursor_varptr
if (tok == '(') if (tok == '(')
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "cursor %s has no arguments", $3->refname); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cursor \"%s\" has no arguments",
$3->refname)));
} }
if (tok != ';') if (tok != ';')
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "syntax error at \"%s\"", yytext); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error at \"%s\"",
yytext)));
} }
} }
} }
...@@ -1503,8 +1531,10 @@ cursor_varptr : T_VARIABLE ...@@ -1503,8 +1531,10 @@ cursor_varptr : T_VARIABLE
if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID) if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "%s must be of type cursor or refcursor", ereport(ERROR,
((PLpgSQL_var *) yylval.variable)->refname); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("\"%s\" must be of type cursor or refcursor",
((PLpgSQL_var *) yylval.variable)->refname)));
} }
$$ = (PLpgSQL_var *) yylval.variable; $$ = (PLpgSQL_var *) yylval.variable;
} }
...@@ -1518,8 +1548,10 @@ cursor_variable : T_VARIABLE ...@@ -1518,8 +1548,10 @@ cursor_variable : T_VARIABLE
if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID) if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "%s must be of type refcursor", ereport(ERROR,
((PLpgSQL_var *) yylval.variable)->refname); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("\"%s\" must be of type refcursor",
((PLpgSQL_var *) yylval.variable)->refname)));
} }
$$ = yylval.variable->dno; $$ = yylval.variable->dno;
} }
...@@ -1632,7 +1664,9 @@ read_sql_construct(int until, ...@@ -1632,7 +1664,9 @@ read_sql_construct(int until,
{ {
parenlevel--; parenlevel--;
if (parenlevel < 0) if (parenlevel < 0)
elog(ERROR, "mismatched parentheses"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("mismatched parentheses")));
} }
/* /*
* End of function definition is an error, and we don't expect to * End of function definition is an error, and we don't expect to
...@@ -1643,13 +1677,19 @@ read_sql_construct(int until, ...@@ -1643,13 +1677,19 @@ read_sql_construct(int until,
{ {
plpgsql_error_lineno = lno; plpgsql_error_lineno = lno;
if (parenlevel != 0) if (parenlevel != 0)
elog(ERROR, "mismatched parentheses"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("mismatched parentheses")));
if (isexpression) if (isexpression)
elog(ERROR, "missing %s at end of SQL expression", ereport(ERROR,
expected); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("missing \"%s\" at end of SQL expression",
expected)));
else else
elog(ERROR, "missing %s at end of SQL statement", ereport(ERROR,
expected); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("missing \"%s\" at end of SQL statement",
expected)));
break; break;
} }
if (plpgsql_SpaceScanned) if (plpgsql_SpaceScanned)
...@@ -1709,8 +1749,12 @@ read_datatype(int tok) ...@@ -1709,8 +1749,12 @@ read_datatype(int tok)
{ {
plpgsql_error_lineno = lno; plpgsql_error_lineno = lno;
if (parenlevel != 0) if (parenlevel != 0)
elog(ERROR, "mismatched parentheses"); ereport(ERROR,
elog(ERROR, "incomplete datatype declaration"); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("mismatched parentheses")));
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("incomplete datatype declaration")));
} }
/* Possible followers for datatype in a declaration */ /* Possible followers for datatype in a declaration */
if (tok == K_NOT || tok == K_ASSIGN || tok == K_DEFAULT) if (tok == K_NOT || tok == K_ASSIGN || tok == K_DEFAULT)
...@@ -1769,14 +1813,18 @@ make_select_stmt(void) ...@@ -1769,14 +1813,18 @@ make_select_stmt(void)
if (tok == 0) if (tok == 0)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "unexpected end of file"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unexpected end of function definition")));
} }
if (tok == K_INTO) if (tok == K_INTO)
{ {
if (have_into) if (have_into)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "INTO specified more than once"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("INTO specified more than once")));
} }
tok = yylex(); tok = yylex();
switch (tok) switch (tok)
...@@ -1814,8 +1862,10 @@ make_select_stmt(void) ...@@ -1814,8 +1862,10 @@ make_select_stmt(void)
default: default:
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "plpgsql: %s is not a variable", ereport(ERROR,
yytext); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"%s\" is not a variable",
yytext)));
} }
} }
have_nexttok = 1; have_nexttok = 1;
...@@ -1945,8 +1995,10 @@ make_fetch_stmt(void) ...@@ -1945,8 +1995,10 @@ make_fetch_stmt(void)
default: default:
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "plpgsql: %s is not a variable", ereport(ERROR,
yytext); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"%s\" is not a variable",
yytext)));
} }
} }
have_nexttok = 1; have_nexttok = 1;
...@@ -2028,8 +2080,10 @@ check_assignable(PLpgSQL_datum *datum) ...@@ -2028,8 +2080,10 @@ check_assignable(PLpgSQL_datum *datum)
if (((PLpgSQL_var *) datum)->isconst) if (((PLpgSQL_var *) datum)->isconst)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "%s is declared CONSTANT", ereport(ERROR,
((PLpgSQL_var *) datum)->refname); (errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
errmsg("\"%s\" is declared CONSTANT",
((PLpgSQL_var *) datum)->refname)));
} }
break; break;
case PLPGSQL_DTYPE_RECFIELD: case PLPGSQL_DTYPE_RECFIELD:
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.59 2003/07/01 21:47:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.60 2003/07/25 23:37:28 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -154,7 +154,7 @@ plpgsql_compile(FunctionCallInfo fcinfo) ...@@ -154,7 +154,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
ObjectIdGetDatum(funcOid), ObjectIdGetDatum(funcOid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procTup)) if (!HeapTupleIsValid(procTup))
elog(ERROR, "plpgsql: cache lookup for proc %u failed", funcOid); elog(ERROR, "cache lookup failed for function %u", funcOid);
procStruct = (Form_pg_proc) GETSTRUCT(procTup); procStruct = (Form_pg_proc) GETSTRUCT(procTup);
/* /*
...@@ -301,15 +301,21 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -301,15 +301,21 @@ do_compile(FunctionCallInfo fcinfo,
* Check for a polymorphic returntype. If found, use the actual * Check for a polymorphic returntype. If found, use the actual
* returntype type from the caller's FuncExpr node, if we * returntype type from the caller's FuncExpr node, if we
* have one. * have one.
*
* Note: errcode is FEATURE_NOT_SUPPORTED because it should always
* work; if it doesn't we're in some context that fails to make
* the info available.
*/ */
rettypeid = procStruct->prorettype; rettypeid = procStruct->prorettype;
if (rettypeid == ANYARRAYOID || rettypeid == ANYELEMENTOID) if (rettypeid == ANYARRAYOID || rettypeid == ANYELEMENTOID)
{ {
rettypeid = get_fn_expr_rettype(fcinfo->flinfo); rettypeid = get_fn_expr_rettype(fcinfo->flinfo);
if (!OidIsValid(rettypeid)) if (!OidIsValid(rettypeid))
elog(ERROR, "could not determine actual return type " ereport(ERROR,
"for polymorphic function %s", (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
plpgsql_error_funcname); errmsg("could not determine actual return type "
"for polymorphic function \"%s\"",
plpgsql_error_funcname)));
} }
/* /*
...@@ -325,8 +331,7 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -325,8 +331,7 @@ do_compile(FunctionCallInfo fcinfo,
ObjectIdGetDatum(rettypeid), ObjectIdGetDatum(rettypeid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup for return type %u failed", elog(ERROR, "cache lookup failed for type %u", rettypeid);
rettypeid);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype result, except VOID or RECORD */ /* Disallow pseudotype result, except VOID or RECORD */
...@@ -337,12 +342,14 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -337,12 +342,14 @@ do_compile(FunctionCallInfo fcinfo,
rettypeid == RECORDOID) rettypeid == RECORDOID)
/* okay */ ; /* okay */ ;
else if (rettypeid == TRIGGEROID) else if (rettypeid == TRIGGEROID)
elog(ERROR, "plpgsql functions cannot return type %s" ereport(ERROR,
"\n\texcept when used as triggers", (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
format_type_be(rettypeid)); errmsg("trigger functions may only be called as triggers")));
else else
elog(ERROR, "plpgsql functions cannot return type %s", ereport(ERROR,
format_type_be(rettypeid)); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plpgsql functions cannot return type %s",
format_type_be(rettypeid))));
} }
if (typeStruct->typrelid != InvalidOid || if (typeStruct->typrelid != InvalidOid ||
...@@ -382,15 +389,16 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -382,15 +389,16 @@ do_compile(FunctionCallInfo fcinfo,
ObjectIdGetDatum(argtypeid), ObjectIdGetDatum(argtypeid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup for argument type %u failed", elog(ERROR, "cache lookup failed for type %u", argtypeid);
argtypeid);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype argument */ /* Disallow pseudotype argument */
/* (note we already replaced ANYARRAY/ANYELEMENT) */ /* (note we already replaced ANYARRAY/ANYELEMENT) */
if (typeStruct->typtype == 'p') if (typeStruct->typtype == 'p')
elog(ERROR, "plpgsql functions cannot take type %s", ereport(ERROR,
format_type_be(argtypeid)); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plpgsql functions cannot take type %s",
format_type_be(argtypeid))));
if (typeStruct->typrelid != InvalidOid) if (typeStruct->typrelid != InvalidOid)
{ {
...@@ -601,8 +609,7 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -601,8 +609,7 @@ do_compile(FunctionCallInfo fcinfo,
break; break;
default: default:
elog(ERROR, "unknown function type %u in plpgsql_compile()", elog(ERROR, "unrecognized function typecode: %u", functype);
functype);
break; break;
} }
...@@ -634,7 +641,7 @@ do_compile(FunctionCallInfo fcinfo, ...@@ -634,7 +641,7 @@ do_compile(FunctionCallInfo fcinfo,
*/ */
parse_rc = plpgsql_yyparse(); parse_rc = plpgsql_yyparse();
if (parse_rc != 0) if (parse_rc != 0)
elog(ERROR, "plpgsql: parser returned %d ???", parse_rc); elog(ERROR, "plpgsql parser returned %d", parse_rc);
plpgsql_scanner_finish(); plpgsql_scanner_finish();
...@@ -864,8 +871,10 @@ plpgsql_parse_dblword(char *word) ...@@ -864,8 +871,10 @@ plpgsql_parse_dblword(char *word)
return T_VARIABLE; return T_VARIABLE;
} }
} }
elog(ERROR, "row %s doesn't have a field %s", ereport(ERROR,
cp[0], cp[1]); (errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("row \"%s\" has no field \"%s\"",
cp[0], cp[1])));
} }
default: default:
...@@ -969,8 +978,10 @@ plpgsql_parse_tripword(char *word) ...@@ -969,8 +978,10 @@ plpgsql_parse_tripword(char *word)
return T_VARIABLE; return T_VARIABLE;
} }
} }
elog(ERROR, "row %s.%s doesn't have a field %s", ereport(ERROR,
cp[0], cp[1], cp[2]); (errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("row \"%s.%s\" has no field \"%s\"",
cp[0], cp[1], cp[2])));
} }
default: default:
...@@ -1188,8 +1199,7 @@ plpgsql_parse_dblwordtype(char *word) ...@@ -1188,8 +1199,7 @@ plpgsql_parse_dblwordtype(char *word)
ObjectIdGetDatum(attrStruct->atttypid), ObjectIdGetDatum(attrStruct->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u of %s.%s failed", elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid);
attrStruct->atttypid, cp[0], cp[1]);
/* /*
* Found that - build a compiler type struct and return it * Found that - build a compiler type struct and return it
...@@ -1300,8 +1310,7 @@ plpgsql_parse_tripwordtype(char *word) ...@@ -1300,8 +1310,7 @@ plpgsql_parse_tripwordtype(char *word)
ObjectIdGetDatum(attrStruct->atttypid), ObjectIdGetDatum(attrStruct->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u of %s.%s failed", elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid);
attrStruct->atttypid, cp[0], cp[1]);
/* /*
* Found that - build a compiler type struct and return it * Found that - build a compiler type struct and return it
...@@ -1339,7 +1348,9 @@ plpgsql_parse_wordrowtype(char *word) ...@@ -1339,7 +1348,9 @@ plpgsql_parse_wordrowtype(char *word)
/* Lookup the relation */ /* Lookup the relation */
classOid = RelnameGetRelid(cp[0]); classOid = RelnameGetRelid(cp[0]);
if (!OidIsValid(classOid)) if (!OidIsValid(classOid))
elog(ERROR, "%s: no such class", cp[0]); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist", cp[0])));
/* /*
* Build and return the complete row definition * Build and return the complete row definition
...@@ -1380,7 +1391,9 @@ plpgsql_parse_dblwordrowtype(char *word) ...@@ -1380,7 +1391,9 @@ plpgsql_parse_dblwordrowtype(char *word)
relvar = makeRangeVarFromNameList(stringToQualifiedNameList(cp, "plpgsql_parse_dblwordrowtype")); relvar = makeRangeVarFromNameList(stringToQualifiedNameList(cp, "plpgsql_parse_dblwordrowtype"));
classOid = RangeVarGetRelid(relvar, true); classOid = RangeVarGetRelid(relvar, true);
if (!OidIsValid(classOid)) if (!OidIsValid(classOid))
elog(ERROR, "%s: no such class", cp); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist", cp)));
/* /*
* Build and return the complete row definition * Build and return the complete row definition
...@@ -1420,7 +1433,9 @@ plpgsql_build_rowtype(Oid classOid) ...@@ -1420,7 +1433,9 @@ plpgsql_build_rowtype(Oid classOid)
classStruct->relkind != RELKIND_SEQUENCE && classStruct->relkind != RELKIND_SEQUENCE &&
classStruct->relkind != RELKIND_VIEW && classStruct->relkind != RELKIND_VIEW &&
classStruct->relkind != RELKIND_COMPOSITE_TYPE) classStruct->relkind != RELKIND_COMPOSITE_TYPE)
elog(ERROR, "%s isn't a table", relname); ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a table", relname)));
/* /*
* Create a row datum entry and all the required variables that it * Create a row datum entry and all the required variables that it
...@@ -1451,8 +1466,8 @@ plpgsql_build_rowtype(Oid classOid) ...@@ -1451,8 +1466,8 @@ plpgsql_build_rowtype(Oid classOid)
Int16GetDatum(i + 1), Int16GetDatum(i + 1),
0, 0); 0, 0);
if (!HeapTupleIsValid(attrtup)) if (!HeapTupleIsValid(attrtup))
elog(ERROR, "cache lookup for attribute %d of class %s failed", elog(ERROR, "cache lookup failed for attribute %d of relation %u",
i + 1, relname); i + 1, classOid);
attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup); attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup);
attname = NameStr(attrStruct->attname); attname = NameStr(attrStruct->attname);
...@@ -1461,8 +1476,8 @@ plpgsql_build_rowtype(Oid classOid) ...@@ -1461,8 +1476,8 @@ plpgsql_build_rowtype(Oid classOid)
ObjectIdGetDatum(attrStruct->atttypid), ObjectIdGetDatum(attrStruct->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u of %s.%s failed", elog(ERROR, "cache lookup failed for type %u",
attrStruct->atttypid, relname, attname); attrStruct->atttypid);
/* /*
* Create the internal variable * Create the internal variable
...@@ -1639,7 +1654,10 @@ void ...@@ -1639,7 +1654,10 @@ void
plpgsql_yyerror(const char *s) plpgsql_yyerror(const char *s)
{ {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "%s at or near \"%s\"", s, plpgsql_yytext); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: first %s is a phrase like "syntax error" */
errmsg("%s at or near \"%s\"", s, plpgsql_yytext)));
} }
...@@ -1678,9 +1696,11 @@ compute_function_hashkey(FmgrInfo *flinfo, ...@@ -1678,9 +1696,11 @@ compute_function_hashkey(FmgrInfo *flinfo,
{ {
argtypeid = get_fn_expr_argtype(flinfo, i); argtypeid = get_fn_expr_argtype(flinfo, i);
if (!OidIsValid(argtypeid)) if (!OidIsValid(argtypeid))
elog(ERROR, "could not determine actual argument " ereport(ERROR,
"type for polymorphic function %s", (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
NameStr(procStruct->proname)); errmsg("could not determine actual argument "
"type for polymorphic function \"%s\"",
NameStr(procStruct->proname))));
} }
hashkey->argtypes[i] = argtypeid; hashkey->argtypes[i] = argtypeid;
...@@ -1729,9 +1749,11 @@ plpgsql_HashTableInsert(PLpgSQL_function *function, ...@@ -1729,9 +1749,11 @@ plpgsql_HashTableInsert(PLpgSQL_function *function,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (hentry == NULL) if (hentry == NULL)
elog(ERROR, "out of memory in plpgsql_HashTable"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found) if (found)
elog(WARNING, "trying to insert a function that exists"); elog(WARNING, "trying to insert a function that already exists");
hentry->function = function; hentry->function = function;
/* prepare back link from function to hashtable key */ /* prepare back link from function to hashtable key */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.87 2003/06/29 00:33:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.88 2003/07/25 23:37:28 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -212,8 +212,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) ...@@ -212,8 +212,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
break; break;
default: default:
elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
func->datums[i]->dtype);
} }
} }
...@@ -252,8 +251,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) ...@@ -252,8 +251,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
break; break;
default: default:
elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
func->datums[i]->dtype);
} }
} }
...@@ -283,8 +281,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) ...@@ -283,8 +281,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
break; break;
default: default:
elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
func->datums[i]->dtype);
} }
} }
...@@ -302,7 +299,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) ...@@ -302,7 +299,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
{ {
estate.err_stmt = NULL; estate.err_stmt = NULL;
estate.err_text = "at END of toplevel PL block"; estate.err_text = "at END of toplevel PL block";
elog(ERROR, "control reaches end of function without RETURN"); ereport(ERROR,
(errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
errmsg("control reached end of function without RETURN")));
} }
/* /*
...@@ -320,7 +319,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) ...@@ -320,7 +319,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
/* Check caller can handle a set result */ /* Check caller can handle a set result */
if (!rsi || !IsA(rsi, ReturnSetInfo) || if (!rsi || !IsA(rsi, ReturnSetInfo) ||
(rsi->allowedModes & SFRM_Materialize) == 0) (rsi->allowedModes & SFRM_Materialize) == 0)
elog(ERROR, "Set-valued function called in context that cannot accept a set"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that cannot accept a set")));
rsi->returnMode = SFRM_Materialize; rsi->returnMode = SFRM_Materialize;
/* If we produced any tuples, send back the result */ /* If we produced any tuples, send back the result */
...@@ -447,8 +448,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -447,8 +448,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
break; break;
default: default:
elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
func->datums[i]->dtype);
} }
} }
...@@ -494,7 +494,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -494,7 +494,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
rec_old->tupdesc = trigdata->tg_relation->rd_att; rec_old->tupdesc = trigdata->tg_relation->rd_att;
} }
else else
elog(ERROR, "Unknown trigger action: not INSERT, DELETE, or UPDATE"); elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE");
/* /*
* Assign the special tg_ variables * Assign the special tg_ variables
...@@ -511,7 +511,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -511,7 +511,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
var->value = DirectFunctionCall1(textin, CStringGetDatum("DELETE")); var->value = DirectFunctionCall1(textin, CStringGetDatum("DELETE"));
else else
elog(ERROR, "Unknown trigger action: not INSERT, DELETE, or UPDATE"); elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE");
var = (PLpgSQL_var *) (estate.datums[func->tg_name_varno]); var = (PLpgSQL_var *) (estate.datums[func->tg_name_varno]);
var->isnull = false; var->isnull = false;
...@@ -527,7 +527,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -527,7 +527,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
else if (TRIGGER_FIRED_AFTER(trigdata->tg_event)) else if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
var->value = DirectFunctionCall1(textin, CStringGetDatum("AFTER")); var->value = DirectFunctionCall1(textin, CStringGetDatum("AFTER"));
else else
elog(ERROR, "Unknown trigger execution time: not BEFORE or AFTER"); elog(ERROR, "unrecognized trigger execution time: not BEFORE or AFTER");
var = (PLpgSQL_var *) (estate.datums[func->tg_level_varno]); var = (PLpgSQL_var *) (estate.datums[func->tg_level_varno]);
var->isnull = false; var->isnull = false;
...@@ -537,7 +537,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -537,7 +537,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event)) else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
var->value = DirectFunctionCall1(textin, CStringGetDatum("STATEMENT")); var->value = DirectFunctionCall1(textin, CStringGetDatum("STATEMENT"));
else else
elog(ERROR, "Unknown trigger event type: not ROW or STATEMENT"); elog(ERROR, "unrecognized trigger event type: not ROW or STATEMENT");
var = (PLpgSQL_var *) (estate.datums[func->tg_relid_varno]); var = (PLpgSQL_var *) (estate.datums[func->tg_relid_varno]);
var->isnull = false; var->isnull = false;
...@@ -598,8 +598,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -598,8 +598,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
break; break;
default: default:
elog(ERROR, "unknown dtype %d in plpgsql_exec_trigger()", elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype);
func->datums[i]->dtype);
} }
} }
...@@ -617,11 +616,15 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -617,11 +616,15 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
{ {
estate.err_stmt = NULL; estate.err_stmt = NULL;
estate.err_text = "at END of toplevel PL block"; estate.err_text = "at END of toplevel PL block";
elog(ERROR, "control reaches end of trigger procedure without RETURN"); ereport(ERROR,
(errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
errmsg("control reached end of trigger procedure without RETURN")));
} }
if (estate.retisset) if (estate.retisset)
elog(ERROR, "trigger procedure cannot return a set"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("trigger procedure cannot return a set")));
/* /*
* Check that the returned tuple structure has the same attributes, * Check that the returned tuple structure has the same attributes,
...@@ -639,7 +642,9 @@ plpgsql_exec_trigger(PLpgSQL_function * func, ...@@ -639,7 +642,9 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
{ {
if (!compatible_tupdesc(estate.rettupdesc, if (!compatible_tupdesc(estate.rettupdesc,
trigdata->tg_relation->rd_att)) trigdata->tg_relation->rd_att))
elog(ERROR, "returned tuple structure doesn't match table of trigger event"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("returned tuple structure does not match table of trigger event")));
/* Copy tuple to upper executor memory */ /* Copy tuple to upper executor memory */
rettup = SPI_copytuple((HeapTuple) (estate.retval)); rettup = SPI_copytuple((HeapTuple) (estate.retval));
} }
...@@ -758,7 +763,10 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) ...@@ -758,7 +763,10 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block)
var->value = (Datum) 0; var->value = (Datum) 0;
var->isnull = true; var->isnull = true;
if (var->notnull) if (var->notnull)
elog(ERROR, "variable '%s' declared NOT NULL cannot default to NULL", var->refname); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("variable \"%s\" declared NOT NULL cannot default to NULL",
var->refname)));
} }
else else
{ {
...@@ -790,7 +798,8 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) ...@@ -790,7 +798,8 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block)
break; break;
default: default:
elog(ERROR, "unknown dtype %d in exec_stmt_block()", estate->datums[n]->dtype); elog(ERROR, "unrecognized dtype: %d",
estate->datums[n]->dtype);
} }
} }
...@@ -822,7 +831,7 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) ...@@ -822,7 +831,7 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block)
return PLPGSQL_RC_RETURN; return PLPGSQL_RC_RETURN;
default: default:
elog(ERROR, "unknown rc %d from exec_stmt()", rc); elog(ERROR, "unrecognized rc: %d", rc);
} }
return PLPGSQL_RC_OK; return PLPGSQL_RC_OK;
...@@ -951,8 +960,7 @@ exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt) ...@@ -951,8 +960,7 @@ exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt)
default: default:
estate->err_stmt = save_estmt; estate->err_stmt = save_estmt;
elog(ERROR, "unknown cmdtype %d in exec_stmt", elog(ERROR, "unrecognized cmdtype: %d", stmt->cmd_type);
stmt->cmd_type);
} }
estate->err_stmt = save_estmt; estate->err_stmt = save_estmt;
...@@ -996,7 +1004,9 @@ exec_stmt_perform(PLpgSQL_execstate * estate, PLpgSQL_stmt_perform * stmt) ...@@ -996,7 +1004,9 @@ exec_stmt_perform(PLpgSQL_execstate * estate, PLpgSQL_stmt_perform * stmt)
rc = exec_run_select(estate, expr, 0, NULL); rc = exec_run_select(estate, expr, 0, NULL);
if (rc != SPI_OK_SELECT) if (rc != SPI_OK_SELECT)
elog(ERROR, "query \"%s\" didn't return data", expr->query); ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("query \"%s\" did not return data", expr->query)));
exec_set_found(estate, (estate->eval_processed != 0)); exec_set_found(estate, (estate->eval_processed != 0));
...@@ -1046,8 +1056,7 @@ exec_stmt_getdiag(PLpgSQL_execstate * estate, PLpgSQL_stmt_getdiag * stmt) ...@@ -1046,8 +1056,7 @@ exec_stmt_getdiag(PLpgSQL_execstate * estate, PLpgSQL_stmt_getdiag * stmt)
break; break;
default: default:
elog(ERROR, "unrecognized attribute request: %d",
elog(ERROR, "unknown attribute request %d in get_diagnostic",
dtitem->item); dtitem->item);
} }
} }
...@@ -1119,7 +1128,7 @@ exec_stmt_loop(PLpgSQL_execstate * estate, PLpgSQL_stmt_loop * stmt) ...@@ -1119,7 +1128,7 @@ exec_stmt_loop(PLpgSQL_execstate * estate, PLpgSQL_stmt_loop * stmt)
return PLPGSQL_RC_RETURN; return PLPGSQL_RC_RETURN;
default: default:
elog(ERROR, "unknown rc %d from exec_stmts()", rc); elog(ERROR, "unrecognized rc: %d", rc);
} }
} }
...@@ -1169,7 +1178,7 @@ exec_stmt_while(PLpgSQL_execstate * estate, PLpgSQL_stmt_while * stmt) ...@@ -1169,7 +1178,7 @@ exec_stmt_while(PLpgSQL_execstate * estate, PLpgSQL_stmt_while * stmt)
return PLPGSQL_RC_RETURN; return PLPGSQL_RC_RETURN;
default: default:
elog(ERROR, "unknown rc %d from exec_stmts()", rc); elog(ERROR, "unrecognized rc: %d", rc);
} }
} }
...@@ -1204,7 +1213,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt) ...@@ -1204,7 +1213,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt)
var->datatype->typelem, var->datatype->typelem,
var->datatype->atttypmod, &isnull); var->datatype->atttypmod, &isnull);
if (isnull) if (isnull)
elog(ERROR, "lower bound of FOR loop cannot be NULL"); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("lower bound of FOR loop cannot be NULL")));
var->value = value; var->value = value;
var->isnull = false; var->isnull = false;
exec_eval_cleanup(estate); exec_eval_cleanup(estate);
...@@ -1218,7 +1229,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt) ...@@ -1218,7 +1229,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt)
var->datatype->typelem, var->datatype->typelem,
var->datatype->atttypmod, &isnull); var->datatype->atttypmod, &isnull);
if (isnull) if (isnull)
elog(ERROR, "upper bound of FOR loop cannot be NULL"); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("upper bound of FOR loop cannot be NULL")));
exec_eval_cleanup(estate); exec_eval_cleanup(estate);
/* /*
...@@ -1319,7 +1332,7 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt) ...@@ -1319,7 +1332,7 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt)
else if (stmt->row != NULL) else if (stmt->row != NULL)
row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
else else
elog(ERROR, "unsupported target in exec_stmt_fors()"); elog(ERROR, "unsupported target");
/* /*
* Open the implicit cursor for the statement and fetch the initial 10 * Open the implicit cursor for the statement and fetch the initial 10
...@@ -1450,7 +1463,7 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt) ...@@ -1450,7 +1463,7 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt)
else if (stmt->row != NULL) else if (stmt->row != NULL)
row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
else else
elog(ERROR, "unsupported target in exec_stmt_select()"); elog(ERROR, "unsupported target");
/* /*
* Run the query * Run the query
...@@ -1592,7 +1605,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1592,7 +1605,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
bool free_tuple = false; bool free_tuple = false;
if (!estate->retisset) if (!estate->retisset)
elog(ERROR, "Cannot use RETURN NEXT in a non-SETOF function"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use RETURN NEXT in a non-SETOF function")));
if (estate->tuple_store == NULL) if (estate->tuple_store == NULL)
exec_init_tuple_store(estate); exec_init_tuple_store(estate);
...@@ -1606,9 +1621,15 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1606,9 +1621,15 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
PLpgSQL_rec *rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]); PLpgSQL_rec *rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
if (!HeapTupleIsValid(rec->tup)) if (!HeapTupleIsValid(rec->tup))
elog(ERROR, "record \"%s\" is unassigned yet", rec->refname); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("record \"%s\" is not assigned yet",
rec->refname),
errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
if (!compatible_tupdesc(tupdesc, rec->tupdesc)) if (!compatible_tupdesc(tupdesc, rec->tupdesc))
elog(ERROR, "Wrong record type supplied in RETURN NEXT"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong record type supplied in RETURN NEXT")));
tuple = rec->tup; tuple = rec->tup;
} }
else if (stmt->row) else if (stmt->row)
...@@ -1618,7 +1639,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1618,7 +1639,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
int i; int i;
if (natts != stmt->row->nfields) if (natts != stmt->row->nfields)
elog(ERROR, "Wrong record type supplied in RETURN NEXT"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong record type supplied in RETURN NEXT")));
dvalues = (Datum *) palloc0(natts * sizeof(Datum)); dvalues = (Datum *) palloc0(natts * sizeof(Datum));
nulls = (char *) palloc(natts * sizeof(char)); nulls = (char *) palloc(natts * sizeof(char));
...@@ -1630,7 +1653,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1630,7 +1653,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
var = (PLpgSQL_var *) (estate->datums[stmt->row->varnos[i]]); var = (PLpgSQL_var *) (estate->datums[stmt->row->varnos[i]]);
if (var->datatype->typoid != tupdesc->attrs[i]->atttypid) if (var->datatype->typoid != tupdesc->attrs[i]->atttypid)
elog(ERROR, "Wrong record type supplied in RETURN NEXT"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong record type supplied in RETURN NEXT")));
dvalues[i] = var->value; dvalues[i] = var->value;
if (!var->isnull) if (!var->isnull)
nulls[i] = ' '; nulls[i] = ' ';
...@@ -1650,7 +1675,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1650,7 +1675,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
char nullflag; char nullflag;
if (natts != 1) if (natts != 1)
elog(ERROR, "Wrong result type supplied in RETURN NEXT"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong result type supplied in RETURN NEXT")));
retval = exec_eval_expr(estate, retval = exec_eval_expr(estate,
stmt->expr, stmt->expr,
...@@ -1674,7 +1701,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, ...@@ -1674,7 +1701,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate,
} }
else else
{ {
elog(ERROR, "Blank RETURN NEXT not allowed"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("RETURN NEXT must have a parameter")));
tuple = NULL; /* keep compiler quiet */ tuple = NULL; /* keep compiler quiet */
} }
...@@ -1705,7 +1734,9 @@ exec_init_tuple_store(PLpgSQL_execstate * estate) ...@@ -1705,7 +1734,9 @@ exec_init_tuple_store(PLpgSQL_execstate * estate)
if (!rsi || !IsA(rsi, ReturnSetInfo) || if (!rsi || !IsA(rsi, ReturnSetInfo) ||
(rsi->allowedModes & SFRM_Materialize) == 0 || (rsi->allowedModes & SFRM_Materialize) == 0 ||
rsi->expectedDesc == NULL) rsi->expectedDesc == NULL)
elog(ERROR, "Set-valued function called in context that cannot accept a set"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that cannot accept a set")));
estate->tuple_store_cxt = rsi->econtext->ecxt_per_query_memory; estate->tuple_store_cxt = rsi->econtext->ecxt_per_query_memory;
...@@ -1717,8 +1748,7 @@ exec_init_tuple_store(PLpgSQL_execstate * estate) ...@@ -1717,8 +1748,7 @@ exec_init_tuple_store(PLpgSQL_execstate * estate)
} }
/* ---------- /* ----------
* exec_stmt_raise Build a message and throw it with * exec_stmt_raise Build a message and throw it with elog()
* elog()
* ---------- * ----------
*/ */
static int static int
...@@ -1741,23 +1771,20 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) ...@@ -1741,23 +1771,20 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt)
for (cp = stmt->message; *cp; cp++) for (cp = stmt->message; *cp; cp++)
{ {
/* /*
* Occurences of a single % are replaced by the next arguments * Occurences of a single % are replaced by the next argument's
* external representation. Double %'s are left as is so elog() * external representation. Double %'s are converted to one %.
* will also don't touch them.
*/ */
if ((c[0] = *cp) == '%') if ((c[0] = *cp) == '%')
{ {
cp++; cp++;
if (*cp == '%') if (*cp == '%')
{ {
plpgsql_dstring_append(&ds, c);
plpgsql_dstring_append(&ds, c); plpgsql_dstring_append(&ds, c);
continue; continue;
} }
cp--; cp--;
if (pidx >= stmt->nparams) if (pidx >= stmt->nparams)
{ {
plpgsql_dstring_append(&ds, c);
plpgsql_dstring_append(&ds, c); plpgsql_dstring_append(&ds, c);
continue; continue;
} }
...@@ -1774,7 +1801,7 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) ...@@ -1774,7 +1801,7 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt)
ObjectIdGetDatum(paramtypeid), ObjectIdGetDatum(paramtypeid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u failed", elog(ERROR, "cache lookup failed for type %u",
paramtypeid); paramtypeid);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
...@@ -1792,7 +1819,9 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) ...@@ -1792,7 +1819,9 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt)
/* /*
* Occurrences of single ' are removed. double ' are reduced to * Occurrences of single ' are removed. double ' are reduced to
* single ones. * single ones. We must do this because the parameter stored
* by the grammar is the raw T_STRING input literal, rather than
* the de-lexed string as you might expect ...
*/ */
if (*cp == '\'') if (*cp == '\'')
{ {
...@@ -1998,8 +2027,10 @@ exec_stmt_execsql(PLpgSQL_execstate * estate, ...@@ -1998,8 +2027,10 @@ exec_stmt_execsql(PLpgSQL_execstate * estate,
break; break;
case SPI_OK_SELECT: case SPI_OK_SELECT:
elog(ERROR, "SELECT query has no destination for result data." ereport(ERROR,
"\n\tIf you want to discard the results, use PERFORM instead."); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("SELECT query has no destination for result data"),
errhint("If you want to discard the results, use PERFORM instead.")));
default: default:
elog(ERROR, "error executing query \"%s\"", expr->query); elog(ERROR, "error executing query \"%s\"", expr->query);
...@@ -2046,7 +2077,9 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, ...@@ -2046,7 +2077,9 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
*/ */
query = exec_eval_expr(estate, stmt->query, &isnull, &restype); query = exec_eval_expr(estate, stmt->query, &isnull, &restype);
if (isnull) if (isnull)
elog(ERROR, "cannot EXECUTE NULL query"); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("cannot EXECUTE a null querystring")));
/* /*
* Get the C-String representation. * Get the C-String representation.
...@@ -2055,7 +2088,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, ...@@ -2055,7 +2088,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
ObjectIdGetDatum(restype), ObjectIdGetDatum(restype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u failed", restype); elog(ERROR, "cache lookup failed for type %u", restype);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
fmgr_info(typeStruct->typoutput, &finfo_output); fmgr_info(typeStruct->typoutput, &finfo_output);
...@@ -2109,12 +2142,14 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, ...@@ -2109,12 +2142,14 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
if (!isspace((unsigned char) *ptr)) if (!isspace((unsigned char) *ptr))
break; break;
if (*ptr == 'S' || *ptr == 's') if (*ptr == 'S' || *ptr == 's')
elog(ERROR, "EXECUTE of SELECT ... INTO is not implemented yet"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("EXECUTE of SELECT ... INTO is not implemented yet")));
break; break;
} }
default: default:
elog(ERROR, "unexpected error %d in EXECUTE of query '%s'", elog(ERROR, "unexpected error %d in EXECUTE of query \"%s\"",
exec_res, querystr); exec_res, querystr);
break; break;
} }
...@@ -2166,7 +2201,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) ...@@ -2166,7 +2201,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
else if (stmt->row != NULL) else if (stmt->row != NULL)
row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
else else
elog(ERROR, "unsupported target in exec_stmt_dynfors()"); elog(ERROR, "unsupported target");
/* /*
* Evaluate the string expression after the EXECUTE keyword. It's * Evaluate the string expression after the EXECUTE keyword. It's
...@@ -2174,7 +2209,9 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) ...@@ -2174,7 +2209,9 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
*/ */
query = exec_eval_expr(estate, stmt->query, &isnull, &restype); query = exec_eval_expr(estate, stmt->query, &isnull, &restype);
if (isnull) if (isnull)
elog(ERROR, "cannot EXECUTE NULL-query"); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("cannot EXECUTE a null querystring")));
/* /*
* Get the C-String representation. * Get the C-String representation.
...@@ -2183,7 +2220,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) ...@@ -2183,7 +2220,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
ObjectIdGetDatum(restype), ObjectIdGetDatum(restype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u failed", restype); elog(ERROR, "cache lookup failed for type %u", restype);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
fmgr_info(typeStruct->typoutput, &finfo_output); fmgr_info(typeStruct->typoutput, &finfo_output);
...@@ -2335,7 +2372,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2335,7 +2372,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
{ {
curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value));
if (SPI_cursor_find(curname) != NULL) if (SPI_cursor_find(curname) != NULL)
elog(ERROR, "cursor \"%s\" already in use", curname); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_CURSOR),
errmsg("cursor \"%s\" already in use", curname)));
} }
/* ---------- /* ----------
...@@ -2377,7 +2416,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2377,7 +2416,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
*/ */
queryD = exec_eval_expr(estate, stmt->dynquery, &isnull, &restype); queryD = exec_eval_expr(estate, stmt->dynquery, &isnull, &restype);
if (isnull) if (isnull)
elog(ERROR, "cannot EXECUTE NULL query"); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("cannot EXECUTE a null querystring")));
/* ---------- /* ----------
* Get the C-String representation. * Get the C-String representation.
...@@ -2387,7 +2428,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2387,7 +2428,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
ObjectIdGetDatum(restype), ObjectIdGetDatum(restype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u failed", restype); elog(ERROR, "cache lookup failed for type %u", restype);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
fmgr_info(typeStruct->typoutput, &finfo_output); fmgr_info(typeStruct->typoutput, &finfo_output);
...@@ -2409,7 +2450,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2409,7 +2450,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
querystr); querystr);
portal = SPI_cursor_open(curname, curplan, NULL, NULL); portal = SPI_cursor_open(curname, curplan, NULL, NULL);
if (portal == NULL) if (portal == NULL)
elog(ERROR, "Failed to open cursor"); elog(ERROR, "failed to open cursor");
pfree(querystr); pfree(querystr);
SPI_freeplan(curplan); SPI_freeplan(curplan);
...@@ -2446,7 +2487,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2446,7 +2487,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
PLpgSQL_stmt_select set_args; PLpgSQL_stmt_select set_args;
if (curvar->cursor_explicit_argrow < 0) if (curvar->cursor_explicit_argrow < 0)
elog(ERROR, "arguments given for cursor without arguments"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("arguments given for cursor without arguments")));
memset(&set_args, 0, sizeof(set_args)); memset(&set_args, 0, sizeof(set_args));
set_args.cmd_type = PLPGSQL_STMT_SELECT; set_args.cmd_type = PLPGSQL_STMT_SELECT;
...@@ -2461,7 +2504,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2461,7 +2504,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
else else
{ {
if (curvar->cursor_explicit_argrow >= 0) if (curvar->cursor_explicit_argrow >= 0)
elog(ERROR, "arguments required for cursor"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("arguments required for cursor")));
} }
query = curvar->cursor_explicit_expr; query = curvar->cursor_explicit_expr;
...@@ -2498,7 +2543,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ...@@ -2498,7 +2543,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt)
*/ */
portal = SPI_cursor_open(curname, query->plan, values, nulls); portal = SPI_cursor_open(curname, query->plan, values, nulls);
if (portal == NULL) if (portal == NULL)
elog(ERROR, "Failed to open cursor"); elog(ERROR, "failed to open cursor");
pfree(values); pfree(values);
pfree(nulls); pfree(nulls);
...@@ -2541,12 +2586,16 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt) ...@@ -2541,12 +2586,16 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt)
*/ */
curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]); curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]);
if (curvar->isnull) if (curvar->isnull)
elog(ERROR, "cursor variable \"%s\" is NULL", curvar->refname); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("cursor variable \"%s\" is NULL", curvar->refname)));
curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value));
portal = SPI_cursor_find(curname); portal = SPI_cursor_find(curname);
if (portal == NULL) if (portal == NULL)
elog(ERROR, "cursor \"%s\" is invalid", curname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_CURSOR),
errmsg("cursor \"%s\" does not exist", curname)));
pfree(curname); pfree(curname);
/* ---------- /* ----------
...@@ -2558,7 +2607,7 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt) ...@@ -2558,7 +2607,7 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt)
else if (stmt->row != NULL) else if (stmt->row != NULL)
row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
else else
elog(ERROR, "unsupported target in exec_stmt_fetch()"); elog(ERROR, "unsupported target");
/* ---------- /* ----------
* Fetch 1 tuple from the cursor * Fetch 1 tuple from the cursor
...@@ -2606,12 +2655,16 @@ exec_stmt_close(PLpgSQL_execstate * estate, PLpgSQL_stmt_close * stmt) ...@@ -2606,12 +2655,16 @@ exec_stmt_close(PLpgSQL_execstate * estate, PLpgSQL_stmt_close * stmt)
*/ */
curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]); curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]);
if (curvar->isnull) if (curvar->isnull)
elog(ERROR, "cursor variable \"%s\" is NULL", curvar->refname); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("cursor variable \"%s\" is NULL", curvar->refname)));
curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value));
portal = SPI_cursor_find(curname); portal = SPI_cursor_find(curname);
if (portal == NULL) if (portal == NULL)
elog(ERROR, "cursor \"%s\" is invalid", curname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_CURSOR),
errmsg("cursor \"%s\" does not exist", curname)));
pfree(curname); pfree(curname);
/* ---------- /* ----------
...@@ -2703,7 +2756,10 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2703,7 +2756,10 @@ exec_assign_value(PLpgSQL_execstate * estate,
isNull); isNull);
if (*isNull && var->notnull) if (*isNull && var->notnull)
elog(ERROR, "NULL assignment to variable '%s' declared NOT NULL", var->refname); ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("NULL cannot be assigned to variable \"%s\" declared NOT NULL",
var->refname)));
/* /*
* If type is by-reference, make sure we have a freshly * If type is by-reference, make sure we have a freshly
...@@ -2741,7 +2797,11 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2741,7 +2797,11 @@ exec_assign_value(PLpgSQL_execstate * estate,
* structure. * structure.
*/ */
if (!HeapTupleIsValid(rec->tup)) if (!HeapTupleIsValid(rec->tup))
elog(ERROR, "record \"%s\" is unassigned yet - don't know its tuple structure", rec->refname); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("record \"%s\" is not assigned yet",
rec->refname),
errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
/* /*
* Get the number of the records field to change and the * Get the number of the records field to change and the
...@@ -2749,7 +2809,10 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2749,7 +2809,10 @@ exec_assign_value(PLpgSQL_execstate * estate,
*/ */
fno = SPI_fnumber(rec->tupdesc, recfield->fieldname); fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
if (fno == SPI_ERROR_NOATTRIBUTE) if (fno == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "record \"%s\" has no field named \"%s\"", rec->refname, recfield->fieldname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("record \"%s\" has no field \"%s\"",
rec->refname, recfield->fieldname)));
fno--; fno--;
natts = rec->tupdesc->natts; natts = rec->tupdesc->natts;
...@@ -2835,7 +2898,10 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2835,7 +2898,10 @@ exec_assign_value(PLpgSQL_execstate * estate,
PLpgSQL_arrayelem *arrayelem = (PLpgSQL_arrayelem *) target; PLpgSQL_arrayelem *arrayelem = (PLpgSQL_arrayelem *) target;
if (nsubscripts >= MAXDIM) if (nsubscripts >= MAXDIM)
elog(ERROR, "Too many subscripts"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
subscripts[nsubscripts++] = arrayelem->subscript; subscripts[nsubscripts++] = arrayelem->subscript;
target = estate->datums[arrayelem->arrayparentno]; target = estate->datums[arrayelem->arrayparentno];
} while (target->dtype == PLPGSQL_DTYPE_ARRAYELEM); } while (target->dtype == PLPGSQL_DTYPE_ARRAYELEM);
...@@ -2846,7 +2912,9 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2846,7 +2912,9 @@ exec_assign_value(PLpgSQL_execstate * estate,
getTypeInputInfo(arraytypeid, &arrayInputFn, &arrayelemtypeid); getTypeInputInfo(arraytypeid, &arrayInputFn, &arrayelemtypeid);
if (!OidIsValid(arrayelemtypeid)) if (!OidIsValid(arrayelemtypeid))
elog(ERROR, "Subscripted item is not an array"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("subscripted object is not an array")));
/* Evaluate the subscripts, switch into left-to-right order */ /* Evaluate the subscripts, switch into left-to-right order */
havenullsubscript = false; havenullsubscript = false;
...@@ -2916,8 +2984,7 @@ exec_assign_value(PLpgSQL_execstate * estate, ...@@ -2916,8 +2984,7 @@ exec_assign_value(PLpgSQL_execstate * estate,
break; break;
default: default:
elog(ERROR, "unknown dtype %d in exec_assign_value()", elog(ERROR, "unrecognized dtype: %d", target->dtype);
target->dtype);
} }
} }
...@@ -2957,24 +3024,34 @@ exec_eval_datum(PLpgSQL_execstate *estate, ...@@ -2957,24 +3024,34 @@ exec_eval_datum(PLpgSQL_execstate *estate,
*value = var->value; *value = var->value;
*isnull = var->isnull; *isnull = var->isnull;
if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) if (expectedtypeid != InvalidOid && expectedtypeid != *typeid)
elog(ERROR, "type of %s doesn't match that when preparing the plan", ereport(ERROR,
var->refname); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("type of \"%s\" does not match that when preparing the plan",
var->refname)));
break; break;
case PLPGSQL_DTYPE_RECFIELD: case PLPGSQL_DTYPE_RECFIELD:
recfield = (PLpgSQL_recfield *) datum; recfield = (PLpgSQL_recfield *) datum;
rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]); rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]);
if (!HeapTupleIsValid(rec->tup)) if (!HeapTupleIsValid(rec->tup))
elog(ERROR, "record \"%s\" is unassigned yet", rec->refname); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("record \"%s\" is not assigned yet",
rec->refname),
errdetail("The tuple structure of a not-yet-assigned record is indeterminate.")));
fno = SPI_fnumber(rec->tupdesc, recfield->fieldname); fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
if (fno == SPI_ERROR_NOATTRIBUTE) if (fno == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "record \"%s\" has no field named \"%s\"", ereport(ERROR,
rec->refname, recfield->fieldname); (errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("record \"%s\" has no field \"%s\"",
rec->refname, recfield->fieldname)));
*typeid = SPI_gettypeid(rec->tupdesc, fno); *typeid = SPI_gettypeid(rec->tupdesc, fno);
*value = SPI_getbinval(rec->tup, rec->tupdesc, fno, isnull); *value = SPI_getbinval(rec->tup, rec->tupdesc, fno, isnull);
if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) if (expectedtypeid != InvalidOid && expectedtypeid != *typeid)
elog(ERROR, "type of %s.%s doesn't match that when preparing the plan", ereport(ERROR,
rec->refname, recfield->fieldname); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("type of \"%s.%s\" does not match that when preparing the plan",
rec->refname, recfield->fieldname)));
break; break;
case PLPGSQL_DTYPE_TRIGARG: case PLPGSQL_DTYPE_TRIGARG:
...@@ -2992,13 +3069,14 @@ exec_eval_datum(PLpgSQL_execstate *estate, ...@@ -2992,13 +3069,14 @@ exec_eval_datum(PLpgSQL_execstate *estate,
*isnull = false; *isnull = false;
} }
if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) if (expectedtypeid != InvalidOid && expectedtypeid != *typeid)
elog(ERROR, "type of tgargv[%d] doesn't match that when preparing the plan", ereport(ERROR,
tgargno); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("type of tgargv[%d] does not match that when preparing the plan",
tgargno)));
break; break;
default: default:
elog(ERROR, "unknown datum dtype %d in exec_eval_datum()", elog(ERROR, "unrecognized dtype: %d", datum->dtype);
datum->dtype);
} }
} }
...@@ -3062,7 +3140,9 @@ exec_eval_expr(PLpgSQL_execstate * estate, ...@@ -3062,7 +3140,9 @@ exec_eval_expr(PLpgSQL_execstate * estate,
rc = exec_run_select(estate, expr, 2, NULL); rc = exec_run_select(estate, expr, 2, NULL);
if (rc != SPI_OK_SELECT) if (rc != SPI_OK_SELECT)
elog(ERROR, "query \"%s\" didn't return data", expr->query); ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("query \"%s\" did not return data", expr->query)));
/* /*
* If there are no rows selected, the result is NULL. * If there are no rows selected, the result is NULL.
...@@ -3077,10 +3157,15 @@ exec_eval_expr(PLpgSQL_execstate * estate, ...@@ -3077,10 +3157,15 @@ exec_eval_expr(PLpgSQL_execstate * estate,
* Check that the expression returned one single Datum * Check that the expression returned one single Datum
*/ */
if (estate->eval_processed > 1) if (estate->eval_processed > 1)
elog(ERROR, "query \"%s\" returned more than one row", expr->query); ereport(ERROR,
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("query \"%s\" returned more than one row",
expr->query)));
if (estate->eval_tuptable->tupdesc->natts != 1) if (estate->eval_tuptable->tupdesc->natts != 1)
elog(ERROR, "query \"%s\" returned %d columns", expr->query, ereport(ERROR,
estate->eval_tuptable->tupdesc->natts); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("query \"%s\" returned %d columns", expr->query,
estate->eval_tuptable->tupdesc->natts)));
/* /*
* Return the result and its type * Return the result and its type
...@@ -3149,7 +3234,9 @@ exec_run_select(PLpgSQL_execstate * estate, ...@@ -3149,7 +3234,9 @@ exec_run_select(PLpgSQL_execstate * estate,
*/ */
rc = SPI_execp(expr->plan, values, nulls, maxtuples); rc = SPI_execp(expr->plan, values, nulls, maxtuples);
if (rc != SPI_OK_SELECT) if (rc != SPI_OK_SELECT)
elog(ERROR, "query \"%s\" isn't a SELECT", expr->query); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("query \"%s\" is not a SELECT", expr->query)));
/* Save query results for eventual cleanup */ /* Save query results for eventual cleanup */
Assert(estate->eval_tuptable == NULL); Assert(estate->eval_tuptable == NULL);
...@@ -3356,7 +3443,7 @@ exec_move_row(PLpgSQL_execstate * estate, ...@@ -3356,7 +3443,7 @@ exec_move_row(PLpgSQL_execstate * estate,
return; return;
} }
elog(ERROR, "unsupported target in exec_move_row()"); elog(ERROR, "unsupported target");
} }
...@@ -3389,7 +3476,7 @@ exec_cast_value(Datum value, Oid valtype, ...@@ -3389,7 +3476,7 @@ exec_cast_value(Datum value, Oid valtype,
ObjectIdGetDatum(valtype), ObjectIdGetDatum(valtype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typetup)) if (!HeapTupleIsValid(typetup))
elog(ERROR, "cache lookup for type %u failed", valtype); elog(ERROR, "cache lookup failed for type %u", valtype);
typeStruct = (Form_pg_type) GETSTRUCT(typetup); typeStruct = (Form_pg_type) GETSTRUCT(typetup);
fmgr_info(typeStruct->typoutput, &finfo_output); fmgr_info(typeStruct->typoutput, &finfo_output);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.26 2003/05/23 04:08:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.27 2003/07/25 23:37:29 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -313,7 +313,10 @@ plpgsql_ns_rename(char *oldname, char *newname) ...@@ -313,7 +313,10 @@ plpgsql_ns_rename(char *oldname, char *newname)
} }
} }
elog(ERROR, "there is no variable '%s' in the current block", oldname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("there is no variable \"%s\" in the current block",
oldname)));
} }
...@@ -366,7 +369,9 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) ...@@ -366,7 +369,9 @@ plpgsql_convert_ident(const char *s, char **output, int numidents)
*cp++ = *s++; *cp++ = *s++;
} }
if (*s != '"') /* should not happen if lexer checked */ if (*s != '"') /* should not happen if lexer checked */
elog(ERROR, "unterminated \" in name: %s", sstart); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unterminated \" in name: %s", sstart)));
s++; s++;
} }
else else
...@@ -403,8 +408,10 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) ...@@ -403,8 +408,10 @@ plpgsql_convert_ident(const char *s, char **output, int numidents)
if (identctr < numidents) if (identctr < numidents)
output[identctr++] = curident; output[identctr++] = curident;
else else
elog(ERROR, "Qualified identifier cannot be used here: %s", ereport(ERROR,
sstart); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("qualified identifier cannot be used here: %s",
sstart)));
/* If not done, skip whitespace, dot, whitespace */ /* If not done, skip whitespace, dot, whitespace */
if (*s) if (*s)
...@@ -412,16 +419,16 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) ...@@ -412,16 +419,16 @@ plpgsql_convert_ident(const char *s, char **output, int numidents)
while (*s && isspace((unsigned char) *s)) while (*s && isspace((unsigned char) *s))
s++; s++;
if (*s++ != '.') if (*s++ != '.')
elog(ERROR, "Expected dot between identifiers: %s", sstart); elog(ERROR, "expected dot between identifiers: %s", sstart);
while (*s && isspace((unsigned char) *s)) while (*s && isspace((unsigned char) *s))
s++; s++;
if (*s == '\0') if (*s == '\0')
elog(ERROR, "Expected another identifier: %s", sstart); elog(ERROR, "expected another identifier: %s", sstart);
} }
} }
if (identctr != numidents) if (identctr != numidents)
elog(ERROR, "Improperly qualified identifier: %s", elog(ERROR, "improperly qualified identifier: %s",
sstart); sstart);
} }
...@@ -586,7 +593,7 @@ dump_stmt(PLpgSQL_stmt * stmt) ...@@ -586,7 +593,7 @@ dump_stmt(PLpgSQL_stmt * stmt)
dump_perform((PLpgSQL_stmt_perform *) stmt); dump_perform((PLpgSQL_stmt_perform *) stmt);
break; break;
default: default:
elog(ERROR, "plpgsql_dump: unknown cmd_type %d\n", stmt->cmd_type); elog(ERROR, "unknown cmd_type: %d", stmt->cmd_type);
break; break;
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.13 2003/07/01 21:47:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.14 2003/07/25 23:37:29 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -65,7 +65,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS) ...@@ -65,7 +65,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS)
* Connect to SPI manager * Connect to SPI manager
*/ */
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "plpgsql: cannot connect to SPI manager"); elog(ERROR, "could not connect to SPI manager");
/* Find or compile the function */ /* Find or compile the function */
func = plpgsql_compile(fcinfo); func = plpgsql_compile(fcinfo);
...@@ -84,7 +84,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS) ...@@ -84,7 +84,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS)
* Disconnect from SPI manager * Disconnect from SPI manager
*/ */
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "plpgsql: SPI_finish() failed"); elog(ERROR, "SPI_finish() failed");
return retval; return retval;
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.28 2003/06/19 23:22:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.29 2003/07/25 23:37:29 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -228,7 +228,9 @@ dump { return O_DUMP; } ...@@ -228,7 +228,9 @@ dump { return O_DUMP; }
\". { \". {
plpgsql_error_lineno = plpgsql_scanner_lineno(); plpgsql_error_lineno = plpgsql_scanner_lineno();
elog(ERROR, "unterminated quoted identifier"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("unterminated quoted identifier")));
} }
/* ---------- /* ----------
...@@ -251,7 +253,9 @@ dump { return O_DUMP; } ...@@ -251,7 +253,9 @@ dump { return O_DUMP; }
<IN_COMMENT>. ; <IN_COMMENT>. ;
<IN_COMMENT><<EOF>> { <IN_COMMENT><<EOF>> {
plpgsql_error_lineno = start_lineno; plpgsql_error_lineno = start_lineno;
elog(ERROR, "unterminated comment"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("unterminated comment")));
} }
/* ---------- /* ----------
...@@ -277,7 +281,9 @@ dump { return O_DUMP; } ...@@ -277,7 +281,9 @@ dump { return O_DUMP; }
} }
<IN_STRING><<EOF>> { <IN_STRING><<EOF>> {
plpgsql_error_lineno = start_lineno; plpgsql_error_lineno = start_lineno;
elog(ERROR, "unterminated string"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("unterminated string")));
} }
<IN_STRING>[^'\\]* { } <IN_STRING>[^'\\]* { }
...@@ -344,7 +350,7 @@ void ...@@ -344,7 +350,7 @@ void
plpgsql_push_back_token(int token) plpgsql_push_back_token(int token)
{ {
if (have_pushback_token) if (have_pushback_token)
elog(ERROR, "plpgsql_push_back_token: can't push back multiple tokens"); elog(ERROR, "cannot push back multiple tokens");
pushback_token = token; pushback_token = token;
have_pushback_token = true; have_pushback_token = true;
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.34 2003/06/25 01:18:58 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.35 2003/07/25 23:37:30 tgl Exp $
* *
********************************************************************* *********************************************************************
*/ */
...@@ -333,7 +333,7 @@ plpython_call_handler(PG_FUNCTION_ARGS) ...@@ -333,7 +333,7 @@ plpython_call_handler(PG_FUNCTION_ARGS)
PLy_init_all(); PLy_init_all();
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "plpython: Unable to connect to SPI manager"); elog(ERROR, "could not connect to SPI manager");
CALL_LEVEL_INC(); CALL_LEVEL_INC();
is_trigger = CALLED_AS_TRIGGER(fcinfo); is_trigger = CALLED_AS_TRIGGER(fcinfo);
...@@ -420,13 +420,13 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) ...@@ -420,13 +420,13 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
* Disconnect from SPI manager * Disconnect from SPI manager
*/ */
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "plpython: SPI_finish failed"); elog(ERROR, "SPI_finish failed");
if (plrv == NULL) if (plrv == NULL)
elog(FATAL, "Aiieee, PLy_procedure_call returned NULL"); elog(FATAL, "PLy_procedure_call returned NULL");
if (PLy_restart_in_progress) if (PLy_restart_in_progress)
elog(FATAL, "Aiieee, restart in progress not expected"); elog(FATAL, "restart in progress not expected");
/* /*
* return of None means we're happy with the tuple * return of None means we're happy with the tuple
...@@ -436,7 +436,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) ...@@ -436,7 +436,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
char *srv; char *srv;
if (!PyString_Check(plrv)) if (!PyString_Check(plrv))
elog(ERROR, "plpython: Expected trigger to return None or a String"); elog(ERROR, "expected trigger to return None or a String");
srv = PyString_AsString(plrv); srv = PyString_AsString(plrv);
if (strcasecmp(srv, "SKIP") == 0) if (strcasecmp(srv, "SKIP") == 0)
...@@ -449,7 +449,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) ...@@ -449,7 +449,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
(TRIGGER_FIRED_BY_UPDATE(tdata->tg_event))) (TRIGGER_FIRED_BY_UPDATE(tdata->tg_event)))
rv = PLy_modify_tuple(proc, plargs, tdata, rv); rv = PLy_modify_tuple(proc, plargs, tdata, rv);
else else
elog(WARNING, "plpython: Ignoring modified tuple in DELETE trigger"); elog(WARNING, "ignoring modified tuple in DELETE trigger");
} }
else if (strcasecmp(srv, "OK")) else if (strcasecmp(srv, "OK"))
{ {
...@@ -458,7 +458,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) ...@@ -458,7 +458,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
* surprising thing since i've written no documentation, so * surprising thing since i've written no documentation, so
* accept a belated OK * accept a belated OK
*/ */
elog(ERROR, "plpython: Expected return to be 'SKIP' or 'MODIFY'"); elog(ERROR, "expected return to be \"SKIP\" or \"MODIFY\"");
} }
} }
...@@ -520,16 +520,16 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, ...@@ -520,16 +520,16 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata,
} }
if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL) if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL)
elog(ERROR, "plpython: TD[\"new\"] deleted, unable to modify tuple"); elog(ERROR, "TD[\"new\"] deleted, unable to modify tuple");
if (!PyDict_Check(plntup)) if (!PyDict_Check(plntup))
elog(ERROR, "plpython: TD[\"new\"] is not a dictionary object"); elog(ERROR, "TD[\"new\"] is not a dictionary object");
Py_INCREF(plntup); Py_INCREF(plntup);
plkeys = PyDict_Keys(plntup); plkeys = PyDict_Keys(plntup);
natts = PyList_Size(plkeys); natts = PyList_Size(plkeys);
if (natts != proc->result.out.r.natts) if (natts != proc->result.out.r.natts)
elog(ERROR, "plpython: TD[\"new\"] has an incorrect number of keys."); elog(ERROR, "TD[\"new\"] has an incorrect number of keys");
modattrs = palloc(natts * sizeof(int)); modattrs = palloc(natts * sizeof(int));
modvalues = palloc(natts * sizeof(Datum)); modvalues = palloc(natts * sizeof(Datum));
...@@ -550,17 +550,17 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, ...@@ -550,17 +550,17 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata,
platt = PyList_GetItem(plkeys, j); platt = PyList_GetItem(plkeys, j);
if (!PyString_Check(platt)) if (!PyString_Check(platt))
elog(ERROR, "plpython: attribute is not a string"); elog(ERROR, "attribute is not a string");
attn = modattrs[j] = SPI_fnumber(tupdesc, PyString_AsString(platt)); attn = modattrs[j] = SPI_fnumber(tupdesc, PyString_AsString(platt));
if (attn == SPI_ERROR_NOATTRIBUTE) if (attn == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "plpython: invalid attribute `%s' in tuple.", elog(ERROR, "invalid attribute \"%s\" in tuple",
PyString_AsString(platt)); PyString_AsString(platt));
atti = attn - 1; atti = attn - 1;
plval = PyDict_GetItem(plntup, platt); plval = PyDict_GetItem(plntup, platt);
if (plval == NULL) if (plval == NULL)
elog(FATAL, "plpython: interpreter is probably corrupted"); elog(FATAL, "python interpreter is probably corrupted");
Py_INCREF(plval); Py_INCREF(plval);
...@@ -594,7 +594,7 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, ...@@ -594,7 +594,7 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata,
pfree(modnulls); pfree(modnulls);
if (rtup == NULL) if (rtup == NULL)
elog(ERROR, "plpython: SPI_modifytuple failed -- error %d", SPI_result); elog(ERROR, "SPI_modifytuple failed -- error %d", SPI_result);
Py_DECREF(plntup); Py_DECREF(plntup);
Py_DECREF(plkeys); Py_DECREF(plkeys);
...@@ -636,7 +636,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple * ...@@ -636,7 +636,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple *
pltdata = PyDict_New(); pltdata = PyDict_New();
if (!pltdata) if (!pltdata)
PLy_elog(ERROR, "Unable to build arguments for trigger procedure"); PLy_elog(ERROR, "could not build arguments for trigger procedure");
pltname = PyString_FromString(tdata->tg_trigger->tgname); pltname = PyString_FromString(tdata->tg_trigger->tgname);
PyDict_SetItemString(pltdata, "name", pltname); PyDict_SetItemString(pltdata, "name", pltname);
...@@ -786,14 +786,14 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) ...@@ -786,14 +786,14 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
* it). * it).
*/ */
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "plpython: SPI_finish failed"); elog(ERROR, "SPI_finish failed");
if (plrv == NULL) if (plrv == NULL)
{ {
elog(FATAL, "Aiieee, PLy_procedure_call returned NULL"); elog(FATAL, "PLy_procedure_call returned NULL");
#ifdef NOT_USED #ifdef NOT_USED
if (!PLy_restart_in_progress) if (!PLy_restart_in_progress)
PLy_elog(ERROR, "plpython: Function \"%s\" failed.", proc->proname); PLy_elog(ERROR, "function \"%s\" failed", proc->proname);
/* /*
* FIXME is this dead code? i'm pretty sure it is for unnested * FIXME is this dead code? i'm pretty sure it is for unnested
...@@ -853,7 +853,7 @@ PLy_procedure_call(PLyProcedure * proc, char *kargs, PyObject * vargs) ...@@ -853,7 +853,7 @@ PLy_procedure_call(PLyProcedure * proc, char *kargs, PyObject * vargs)
{ {
Py_XDECREF(rv); Py_XDECREF(rv);
if (!PLy_restart_in_progress) if (!PLy_restart_in_progress)
PLy_elog(ERROR, "Call of function `%s' failed.", proc->proname); PLy_elog(ERROR, "function \"%s\" failed", proc->proname);
RAISE_EXC(1); RAISE_EXC(1);
} }
...@@ -951,13 +951,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger) ...@@ -951,13 +951,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger)
ObjectIdGetDatum(fn_oid), ObjectIdGetDatum(fn_oid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procTup)) if (!HeapTupleIsValid(procTup))
elog(ERROR, "plpython: cache lookup for procedure %u failed", fn_oid); elog(ERROR, "cache lookup failed for function %u", fn_oid);
rv = snprintf(key, sizeof(key), "%u%s", rv = snprintf(key, sizeof(key), "%u%s",
fn_oid, fn_oid,
is_trigger ? "_trigger" : ""); is_trigger ? "_trigger" : "");
if ((rv >= sizeof(key)) || (rv < 0)) if ((rv >= sizeof(key)) || (rv < 0))
elog(FATAL, "plpython: Buffer overrun in %s:%d", __FILE__, __LINE__); elog(ERROR, "key too long");
plproc = PyDict_GetItemString(PLy_procedure_cache, key); plproc = PyDict_GetItemString(PLy_procedure_cache, key);
...@@ -965,13 +965,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger) ...@@ -965,13 +965,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger)
{ {
Py_INCREF(plproc); Py_INCREF(plproc);
if (!PyCObject_Check(plproc)) if (!PyCObject_Check(plproc))
elog(FATAL, "plpython: Expected a PyCObject, didn't get one"); elog(FATAL, "expected a PyCObject, didn't get one");
mark(); mark();
proc = PyCObject_AsVoidPtr(plproc); proc = PyCObject_AsVoidPtr(plproc);
if (proc->me != plproc) if (proc->me != plproc)
elog(FATAL, "plpython: Aiieee, proc->me != plproc"); elog(FATAL, "proc->me != plproc");
/* did we find an up-to-date cache entry? */ /* did we find an up-to-date cache entry? */
if (proc->fn_xmin != HeapTupleHeaderGetXmin(procTup->t_data) || if (proc->fn_xmin != HeapTupleHeaderGetXmin(procTup->t_data) ||
proc->fn_cmin != HeapTupleHeaderGetCmin(procTup->t_data)) proc->fn_cmin != HeapTupleHeaderGetCmin(procTup->t_data))
...@@ -1013,7 +1013,7 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, ...@@ -1013,7 +1013,7 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
fcinfo->flinfo->fn_oid, fcinfo->flinfo->fn_oid,
is_trigger ? "_trigger" : ""); is_trigger ? "_trigger" : "");
if ((rv >= sizeof(procName)) || (rv < 0)) if ((rv >= sizeof(procName)) || (rv < 0))
elog(FATAL, "plpython: Procedure name would overrun buffer"); elog(ERROR, "procedure name would overrun buffer");
proc = PLy_malloc(sizeof(PLyProcedure)); proc = PLy_malloc(sizeof(PLyProcedure));
proc->proname = PLy_malloc(strlen(NameStr(procStruct->proname)) + 1); proc->proname = PLy_malloc(strlen(NameStr(procStruct->proname)) + 1);
...@@ -1047,19 +1047,21 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, ...@@ -1047,19 +1047,21 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
{ {
HeapTuple rvTypeTup; HeapTuple rvTypeTup;
Form_pg_type rvTypeStruct; Form_pg_type rvTypeStruct;
Datum rvDatum;
rvDatum = ObjectIdGetDatum(procStruct->prorettype); rvTypeTup = SearchSysCache(TYPEOID,
rvTypeTup = SearchSysCache(TYPEOID, rvDatum, 0, 0, 0); ObjectIdGetDatum(procStruct->prorettype),
0, 0, 0);
if (!HeapTupleIsValid(rvTypeTup)) if (!HeapTupleIsValid(rvTypeTup))
elog(ERROR, "plpython: cache lookup for type \"%u\" failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->prorettype); procStruct->prorettype);
rvTypeStruct = (Form_pg_type) GETSTRUCT(rvTypeTup); rvTypeStruct = (Form_pg_type) GETSTRUCT(rvTypeTup);
if (rvTypeStruct->typrelid == InvalidOid) if (rvTypeStruct->typrelid == InvalidOid)
PLy_output_datum_func(&proc->result, rvTypeStruct); PLy_output_datum_func(&proc->result, rvTypeStruct);
else else
elog(ERROR, "plpython: tuple return types not supported, yet"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("tuple return types are not supported yet")));
ReleaseSysCache(rvTypeTup); ReleaseSysCache(rvTypeTup);
} }
...@@ -1084,12 +1086,12 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, ...@@ -1084,12 +1086,12 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
{ {
HeapTuple argTypeTup; HeapTuple argTypeTup;
Form_pg_type argTypeStruct; Form_pg_type argTypeStruct;
Datum argDatum;
argDatum = ObjectIdGetDatum(procStruct->proargtypes[i]); argTypeTup = SearchSysCache(TYPEOID,
argTypeTup = SearchSysCache(TYPEOID, argDatum, 0, 0, 0); ObjectIdGetDatum(procStruct->proargtypes[i]),
0, 0, 0);
if (!HeapTupleIsValid(argTypeTup)) if (!HeapTupleIsValid(argTypeTup))
elog(ERROR, "plpython: cache lookup for type \"%u\" failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->proargtypes[i]); procStruct->proargtypes[i]);
argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup); argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup);
...@@ -1164,7 +1166,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src) ...@@ -1164,7 +1166,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src)
*/ */
clen = snprintf(call, sizeof(call), "%s()", proc->pyname); clen = snprintf(call, sizeof(call), "%s()", proc->pyname);
if ((clen < 0) || (clen >= sizeof(call))) if ((clen < 0) || (clen >= sizeof(call)))
elog(ERROR, "plpython: string would overflow buffer."); elog(ERROR, "string would overflow buffer");
proc->code = Py_CompileString(call, "<string>", Py_eval_input); proc->code = Py_CompileString(call, "<string>", Py_eval_input);
if ((proc->code != NULL) && (!PyErr_Occurred())) if ((proc->code != NULL) && (!PyErr_Occurred()))
return; return;
...@@ -1172,7 +1174,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src) ...@@ -1172,7 +1174,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src)
else else
Py_XDECREF(crv); Py_XDECREF(crv);
PLy_elog(ERROR, "Unable to compile function %s", proc->proname); PLy_elog(ERROR, "could not compile function \"%s\"", proc->proname);
} }
char * char *
...@@ -1193,8 +1195,7 @@ PLy_procedure_munge_source(const char *name, const char *src) ...@@ -1193,8 +1195,7 @@ PLy_procedure_munge_source(const char *name, const char *src)
mrc = PLy_malloc(mlen); mrc = PLy_malloc(mlen);
plen = snprintf(mrc, mlen, "def %s():\n\t", name); plen = snprintf(mrc, mlen, "def %s():\n\t", name);
if ((plen < 0) || (plen >= mlen)) Assert(plen >= 0 && plen < mlen);
elog(FATAL, "Aiieee, impossible buffer overrun (or snprintf failure)");
sp = src; sp = src;
mp = mrc + plen; mp = mrc + plen;
...@@ -1214,7 +1215,7 @@ PLy_procedure_munge_source(const char *name, const char *src) ...@@ -1214,7 +1215,7 @@ PLy_procedure_munge_source(const char *name, const char *src)
*mp = '\0'; *mp = '\0';
if (mp > (mrc + mlen)) if (mp > (mrc + mlen))
elog(FATAL, "plpython: Buffer overrun in PLy_munge_source"); elog(FATAL, "buffer overrun in PLy_munge_source");
return mrc; return mrc;
} }
...@@ -1253,12 +1254,11 @@ void ...@@ -1253,12 +1254,11 @@ void
PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc)
{ {
int i; int i;
Datum datum;
enter(); enter();
if (arg->is_rel == 0) if (arg->is_rel == 0)
elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Datum"); elog(ERROR, "PLyTypeInfo struct is initialized for a Datum");
arg->is_rel = 1; arg->is_rel = 1;
arg->in.r.natts = desc->natts; arg->in.r.natts = desc->natts;
...@@ -1269,16 +1269,12 @@ PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) ...@@ -1269,16 +1269,12 @@ PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc)
HeapTuple typeTup; HeapTuple typeTup;
Form_pg_type typeStruct; Form_pg_type typeStruct;
datum = ObjectIdGetDatum(desc->attrs[i]->atttypid); typeTup = SearchSysCache(TYPEOID,
typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0); ObjectIdGetDatum(desc->attrs[i]->atttypid),
0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
{ elog(ERROR, "cache lookup failed for type %u",
char *attname = NameStr(desc->attrs[i]->attname); desc->attrs[i]->atttypid);
elog(ERROR, "plpython: Cache lookup for attribute `%s' type `%u' failed",
attname, desc->attrs[i]->atttypid);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
PLy_input_datum_func2(&(arg->in.r.atts[i]), PLy_input_datum_func2(&(arg->in.r.atts[i]),
...@@ -1293,12 +1289,11 @@ void ...@@ -1293,12 +1289,11 @@ void
PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc)
{ {
int i; int i;
Datum datum;
enter(); enter();
if (arg->is_rel == 0) if (arg->is_rel == 0)
elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Datum"); elog(ERROR, "PLyTypeInfo struct is initialized for a Datum");
arg->is_rel = 1; arg->is_rel = 1;
arg->out.r.natts = desc->natts; arg->out.r.natts = desc->natts;
...@@ -1309,16 +1304,12 @@ PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) ...@@ -1309,16 +1304,12 @@ PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc)
HeapTuple typeTup; HeapTuple typeTup;
Form_pg_type typeStruct; Form_pg_type typeStruct;
datum = ObjectIdGetDatum(desc->attrs[i]->atttypid); typeTup = SearchSysCache(TYPEOID,
typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0); ObjectIdGetDatum(desc->attrs[i]->atttypid),
0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
{ elog(ERROR, "cache lookup failed for type %u",
char *attname = NameStr(desc->attrs[i]->attname); desc->attrs[i]->atttypid);
elog(ERROR, "plpython: Cache lookup for attribute `%s' type `%u' failed",
attname, desc->attrs[i]->atttypid);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
PLy_output_datum_func2(&(arg->out.r.atts[i]), typeStruct); PLy_output_datum_func2(&(arg->out.r.atts[i]), typeStruct);
...@@ -1333,7 +1324,7 @@ PLy_output_datum_func(PLyTypeInfo * arg, Form_pg_type typeStruct) ...@@ -1333,7 +1324,7 @@ PLy_output_datum_func(PLyTypeInfo * arg, Form_pg_type typeStruct)
enter(); enter();
if (arg->is_rel == 1) if (arg->is_rel == 1)
elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Tuple"); elog(ERROR, "PLyTypeInfo struct is initialized for a Tuple");
arg->is_rel = 0; arg->is_rel = 0;
PLy_output_datum_func2(&(arg->out.d), typeStruct); PLy_output_datum_func2(&(arg->out.d), typeStruct);
} }
...@@ -1354,7 +1345,7 @@ PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, Form_pg_type typeStruct) ...@@ -1354,7 +1345,7 @@ PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, Form_pg_type typeStruct)
enter(); enter();
if (arg->is_rel == 1) if (arg->is_rel == 1)
elog(FATAL, "plpython: PLyTypeInfo struct is initialized for Tuple"); elog(ERROR, "PLyTypeInfo struct is initialized for Tuple");
arg->is_rel = 0; arg->is_rel = 0;
PLy_input_datum_func2(&(arg->in.d), typeOid, typeStruct); PLy_input_datum_func2(&(arg->in.d), typeOid, typeStruct);
} }
...@@ -1476,11 +1467,11 @@ PLyDict_FromTuple(PLyTypeInfo * info, HeapTuple tuple, TupleDesc desc) ...@@ -1476,11 +1467,11 @@ PLyDict_FromTuple(PLyTypeInfo * info, HeapTuple tuple, TupleDesc desc)
enter(); enter();
if (info->is_rel != 1) if (info->is_rel != 1)
elog(FATAL, "plpython: PLyTypeInfo structure describes a datum."); elog(ERROR, "PLyTypeInfo structure describes a datum");
dict = PyDict_New(); dict = PyDict_New();
if (dict == NULL) if (dict == NULL)
PLy_elog(ERROR, "Unable to create tuple dictionary."); PLy_elog(ERROR, "could not create tuple dictionary");
SAVE_EXC(); SAVE_EXC();
if (TRAP_EXC()) if (TRAP_EXC())
...@@ -1915,7 +1906,8 @@ PLy_spi_prepare(PyObject * self, PyObject * args) ...@@ -1915,7 +1906,8 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
Py_XDECREF(optr); Py_XDECREF(optr);
if (!PyErr_Occurred()) if (!PyErr_Occurred())
PyErr_SetString(PLy_exc_spi_error, PyErr_SetString(PLy_exc_spi_error,
"Unknown error in PLy_spi_prepare."); "Unknown error in PLy_spi_prepare");
/* XXX this oughta be replaced with errcontext mechanism */
PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure)); PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure));
RERAISE_EXC(); RERAISE_EXC();
} }
...@@ -2191,7 +2183,7 @@ PLy_spi_execute_query(char *query, int limit) ...@@ -2191,7 +2183,7 @@ PLy_spi_execute_query(char *query, int limit)
RESTORE_EXC(); RESTORE_EXC();
if ((!PLy_restart_in_progress) && (!PyErr_Occurred())) if ((!PLy_restart_in_progress) && (!PyErr_Occurred()))
PyErr_SetString(PLy_exc_spi_error, PyErr_SetString(PLy_exc_spi_error,
"Unknown error in PLy_spi_execute_query."); "Unknown error in PLy_spi_execute_query");
PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure)); PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure));
RERAISE_EXC(); RERAISE_EXC();
} }
...@@ -2318,17 +2310,17 @@ PLy_init_all(void) ...@@ -2318,17 +2310,17 @@ PLy_init_all(void)
enter(); enter();
if (init_active) if (init_active)
elog(FATAL, "plpython: Initialization of language module failed."); elog(FATAL, "initialization of language module failed");
init_active = 1; init_active = 1;
Py_Initialize(); Py_Initialize();
PLy_init_interp(); PLy_init_interp();
PLy_init_plpy(); PLy_init_plpy();
if (PyErr_Occurred()) if (PyErr_Occurred())
PLy_elog(FATAL, "Untrapped error in initialization."); PLy_elog(FATAL, "untrapped error in initialization");
PLy_procedure_cache = PyDict_New(); PLy_procedure_cache = PyDict_New();
if (PLy_procedure_cache == NULL) if (PLy_procedure_cache == NULL)
PLy_elog(ERROR, "Unable to create procedure cache."); PLy_elog(ERROR, "could not create procedure cache");
PLy_first_call = 0; PLy_first_call = 0;
...@@ -2344,14 +2336,14 @@ PLy_init_interp(void) ...@@ -2344,14 +2336,14 @@ PLy_init_interp(void)
mainmod = PyImport_AddModule("__main__"); mainmod = PyImport_AddModule("__main__");
if ((mainmod == NULL) || (PyErr_Occurred())) if ((mainmod == NULL) || (PyErr_Occurred()))
PLy_elog(ERROR, "Unable to import '__main__' module."); PLy_elog(ERROR, "could not import \"__main__\" module.");
Py_INCREF(mainmod); Py_INCREF(mainmod);
PLy_interp_globals = PyModule_GetDict(mainmod); PLy_interp_globals = PyModule_GetDict(mainmod);
PLy_interp_safe_globals = PyDict_New(); PLy_interp_safe_globals = PyDict_New();
PyDict_SetItemString(PLy_interp_globals, "GD", PLy_interp_safe_globals); PyDict_SetItemString(PLy_interp_globals, "GD", PLy_interp_safe_globals);
Py_DECREF(mainmod); Py_DECREF(mainmod);
if ((PLy_interp_globals == NULL) || (PyErr_Occurred())) if ((PLy_interp_globals == NULL) || (PyErr_Occurred()))
PLy_elog(ERROR, "Unable to initialize globals."); PLy_elog(ERROR, "could not initialize globals");
} }
void void
...@@ -2389,7 +2381,7 @@ PLy_init_plpy(void) ...@@ -2389,7 +2381,7 @@ PLy_init_plpy(void)
plpy_mod = PyImport_AddModule("plpy"); plpy_mod = PyImport_AddModule("plpy");
PyDict_SetItemString(main_dict, "plpy", plpy_mod); PyDict_SetItemString(main_dict, "plpy", plpy_mod);
if (PyErr_Occurred()) if (PyErr_Occurred())
elog(ERROR, "Unable to init plpy."); elog(ERROR, "could not init plpy");
} }
/* the python interface to the elog function /* the python interface to the elog function
...@@ -2450,7 +2442,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args) ...@@ -2450,7 +2442,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args)
enter(); enter();
if (args == NULL) if (args == NULL)
elog(WARNING, "plpython, args is NULL in %s", __FUNCTION__); elog(WARNING, "args is NULL");
so = PyObject_Str(args); so = PyObject_Str(args);
if ((so == NULL) || ((sv = PyString_AsString(so)) == NULL)) if ((so == NULL) || ((sv = PyString_AsString(so)) == NULL))
...@@ -2492,7 +2484,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args) ...@@ -2492,7 +2484,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args)
* postgresql log, no? whatever, this shouldn't happen so die * postgresql log, no? whatever, this shouldn't happen so die
* hideously. * hideously.
*/ */
elog(FATAL, "plpython: Aiieee, elog threw an unknown exception!"); elog(FATAL, "elog threw an unknown exception");
RERAISE_EXC(); RERAISE_EXC();
} }
...@@ -2576,18 +2568,18 @@ PLy_elog(int elevel, const char *fmt,...) ...@@ -2576,18 +2568,18 @@ PLy_elog(int elevel, const char *fmt,...)
*/ */
PLy_restart_in_progress += 1; PLy_restart_in_progress += 1;
PLy_free(emsg); PLy_free(emsg);
if (xmsg)
PLy_free(xmsg); PLy_free(xmsg);
RERAISE_EXC(); RERAISE_EXC();
} }
ereport(elevel,
(errmsg("plpython: %s", emsg),
(xmsg) ? errdetail("%s", xmsg) : 0));
PLy_free(emsg);
if (xmsg) if (xmsg)
{
elog(elevel, "plpython: %s\n%s", emsg, xmsg);
PLy_free(xmsg); PLy_free(xmsg);
}
else
elog(elevel, "plpython: %s", emsg);
PLy_free(emsg);
leave(); leave();
...@@ -2706,7 +2698,9 @@ PLy_malloc(size_t bytes) ...@@ -2706,7 +2698,9 @@ PLy_malloc(size_t bytes)
void *ptr = malloc(bytes); void *ptr = malloc(bytes);
if (ptr == NULL) if (ptr == NULL)
elog(FATAL, "plpython: Memory exhausted."); ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
return ptr; return ptr;
} }
...@@ -2716,7 +2710,9 @@ PLy_realloc(void *optr, size_t bytes) ...@@ -2716,7 +2710,9 @@ PLy_realloc(void *optr, size_t bytes)
void *nptr = realloc(optr, bytes); void *nptr = realloc(optr, bytes);
if (nptr == NULL) if (nptr == NULL)
elog(FATAL, "plpython: Memory exhausted."); ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
return nptr; return nptr;
} }
......
/* $Header: /cvsroot/pgsql/src/pl/plpython/Attic/plpython.h,v 1.7 2003/05/27 17:49:47 momjian Exp $ */ /* $Header: /cvsroot/pgsql/src/pl/plpython/Attic/plpython.h,v 1.8 2003/07/25 23:37:30 tgl Exp $ */
#ifndef PLPYTHON_H #ifndef PLPYTHON_H
#define PLPYTHON_H #define PLPYTHON_H
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
#if DEBUG_LEVEL #if DEBUG_LEVEL
#define CALL_LEVEL_INC() do { PLy_call_level += 1; \ #define CALL_LEVEL_INC() do { PLy_call_level += 1; \
elog(DEBUG4, "Level: %d", PLy_call_level); } while (0) elog(DEBUG4, "level: %d", PLy_call_level); } while (0)
#define CALL_LEVEL_DEC() do { elog(DEBUG4, "Level: %d", PLy_call_level); \ #define CALL_LEVEL_DEC() do { elog(DEBUG4, "level: %d", PLy_call_level); \
PLy_call_level -= 1; } while (0) PLy_call_level -= 1; } while (0)
#else #else
#define CALL_LEVEL_INC() do { PLy_call_level += 1; } while (0) #define CALL_LEVEL_INC() do { PLy_call_level += 1; } while (0)
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* ENHANCEMENTS, OR MODIFICATIONS. * ENHANCEMENTS, OR MODIFICATIONS.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.71 2003/05/27 17:49:47 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.72 2003/07/25 23:37:31 tgl Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -215,28 +215,19 @@ pltcl_init_all(void) ...@@ -215,28 +215,19 @@ pltcl_init_all(void)
* stdout and stderr on DeleteInterp * stdout and stderr on DeleteInterp
************************************************************/ ************************************************************/
if ((pltcl_hold_interp = Tcl_CreateInterp()) == NULL) if ((pltcl_hold_interp = Tcl_CreateInterp()) == NULL)
{ elog(ERROR, "could not create \"hold\" interpreter");
elog(ERROR, "pltcl: internal error - cannot create 'hold' "
"interpreter");
}
/************************************************************ /************************************************************
* Create the two interpreters * Create the two interpreters
************************************************************/ ************************************************************/
if ((pltcl_norm_interp = if ((pltcl_norm_interp =
Tcl_CreateSlave(pltcl_hold_interp, "norm", 0)) == NULL) Tcl_CreateSlave(pltcl_hold_interp, "norm", 0)) == NULL)
{ elog(ERROR, "could not create \"normal\" interpreter");
elog(ERROR,
"pltcl: internal error - cannot create 'normal' interpreter");
}
pltcl_init_interp(pltcl_norm_interp); pltcl_init_interp(pltcl_norm_interp);
if ((pltcl_safe_interp = if ((pltcl_safe_interp =
Tcl_CreateSlave(pltcl_hold_interp, "safe", 1)) == NULL) Tcl_CreateSlave(pltcl_hold_interp, "safe", 1)) == NULL)
{ elog(ERROR, "could not create \"safe\" interpreter");
elog(ERROR,
"pltcl: internal error - cannot create 'safe' interpreter");
}
pltcl_init_interp(pltcl_safe_interp); pltcl_init_interp(pltcl_safe_interp);
/************************************************************ /************************************************************
...@@ -285,10 +276,10 @@ pltcl_init_interp(Tcl_Interp *interp) ...@@ -285,10 +276,10 @@ pltcl_init_interp(Tcl_Interp *interp)
* Try to load the unknown procedure from pltcl_modules * Try to load the unknown procedure from pltcl_modules
************************************************************/ ************************************************************/
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "pltcl_init_interp(): SPI_connect failed"); elog(ERROR, "SPI_connect failed");
pltcl_init_load_unknown(interp); pltcl_init_load_unknown(interp);
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "pltcl_init_interp(): SPI_finish failed"); elog(ERROR, "SPI_finish failed");
} }
...@@ -313,7 +304,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) ...@@ -313,7 +304,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
"where relname = 'pltcl_modules'", 1); "where relname = 'pltcl_modules'", 1);
SPI_freetuptable(SPI_tuptable); SPI_freetuptable(SPI_tuptable);
if (spi_rc != SPI_OK_SELECT) if (spi_rc != SPI_OK_SELECT)
elog(ERROR, "pltcl_init_load_unknown(): select from pg_class failed"); elog(ERROR, "select from pg_class failed");
if (SPI_processed == 0) if (SPI_processed == 0)
return; return;
...@@ -327,10 +318,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) ...@@ -327,10 +318,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
"where modname = 'unknown' " "where modname = 'unknown' "
"order by modseq", 0); "order by modseq", 0);
if (spi_rc != SPI_OK_SELECT) if (spi_rc != SPI_OK_SELECT)
{ elog(ERROR, "select from pltcl_modules failed");
elog(ERROR, "pltcl_init_load_unknown(): select from pltcl_modules "
"failed");
}
/************************************************************ /************************************************************
* If there's nothing, module unknown doesn't exist * If there's nothing, module unknown doesn't exist
...@@ -339,7 +327,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) ...@@ -339,7 +327,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
{ {
Tcl_DStringFree(&unknown_src); Tcl_DStringFree(&unknown_src);
SPI_freetuptable(SPI_tuptable); SPI_freetuptable(SPI_tuptable);
elog(WARNING, "pltcl: Module unknown not found in pltcl_modules"); elog(WARNING, "module \"unknown\" not found in pltcl_modules");
return; return;
} }
...@@ -394,7 +382,7 @@ pltcl_call_handler(PG_FUNCTION_ARGS) ...@@ -394,7 +382,7 @@ pltcl_call_handler(PG_FUNCTION_ARGS)
* Connect to SPI manager * Connect to SPI manager
************************************************************/ ************************************************************/
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "pltcl: cannot connect to SPI manager"); elog(ERROR, "could not connect to SPI manager");
/************************************************************ /************************************************************
* Keep track about the nesting of Tcl-SPI-Tcl-... calls * Keep track about the nesting of Tcl-SPI-Tcl-... calls
************************************************************/ ************************************************************/
...@@ -550,9 +538,11 @@ pltcl_func_handler(PG_FUNCTION_ARGS) ...@@ -550,9 +538,11 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
if (--pltcl_call_level == 0) if (--pltcl_call_level == 0)
pltcl_restart_in_progress = 0; pltcl_restart_in_progress = 0;
UTF_BEGIN; UTF_BEGIN;
elog(ERROR, "pltcl: %s\n%s", interp->result, ereport(ERROR,
(errmsg("pltcl: %s", interp->result),
errdetail("%s",
UTF_U2E(Tcl_GetVar(interp, "errorInfo", UTF_U2E(Tcl_GetVar(interp, "errorInfo",
TCL_GLOBAL_ONLY))); TCL_GLOBAL_ONLY)))));
UTF_END; UTF_END;
} }
if (--pltcl_call_level == 0) if (--pltcl_call_level == 0)
...@@ -586,7 +576,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS) ...@@ -586,7 +576,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
* the result type in that case. * the result type in that case.
************************************************************/ ************************************************************/
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "pltcl: SPI_finish() failed"); elog(ERROR, "SPI_finish() failed");
if (fcinfo->isnull) if (fcinfo->isnull)
retval = (Datum) 0; retval = (Datum) 0;
...@@ -785,9 +775,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -785,9 +775,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
if (--pltcl_call_level == 0) if (--pltcl_call_level == 0)
pltcl_restart_in_progress = 0; pltcl_restart_in_progress = 0;
UTF_BEGIN; UTF_BEGIN;
elog(ERROR, "pltcl: %s\n%s", interp->result, ereport(ERROR,
(errmsg("pltcl: %s", interp->result),
errdetail("%s",
UTF_U2E(Tcl_GetVar(interp, "errorInfo", UTF_U2E(Tcl_GetVar(interp, "errorInfo",
TCL_GLOBAL_ONLY))); TCL_GLOBAL_ONLY)))));
UTF_END; UTF_END;
} }
if (--pltcl_call_level == 0) if (--pltcl_call_level == 0)
...@@ -801,7 +793,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -801,7 +793,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "pltcl: unsupported TCL return code %d", tcl_rc); elog(ERROR, "unsupported TCL return code: %d", tcl_rc);
} }
/************************************************************ /************************************************************
...@@ -809,7 +801,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -809,7 +801,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
* the magic strings OK or SKIP or a list from array get * the magic strings OK or SKIP or a list from array get
************************************************************/ ************************************************************/
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "pltcl: SPI_finish() failed"); elog(ERROR, "SPI_finish() failed");
if (strcmp(interp->result, "OK") == 0) if (strcmp(interp->result, "OK") == 0)
return rettup; return rettup;
...@@ -822,15 +814,13 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -822,15 +814,13 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
************************************************************/ ************************************************************/
if (Tcl_SplitList(interp, interp->result, if (Tcl_SplitList(interp, interp->result,
&ret_numvals, &ret_values) != TCL_OK) &ret_numvals, &ret_values) != TCL_OK)
{ elog(ERROR, "could not split return value from trigger: %s",
elog(WARNING, "pltcl: cannot split return value from trigger"); interp->result);
elog(ERROR, "pltcl: %s", interp->result);
}
if (ret_numvals % 2 != 0) if (ret_numvals % 2 != 0)
{ {
ckfree((char *) ret_values); ckfree((char *) ret_values);
elog(ERROR, "pltcl: invalid return list from trigger - must have even # of elements"); elog(ERROR, "invalid return list from trigger - must have even # of elements");
} }
modattrs = (int *) palloc(tupdesc->natts * sizeof(int)); modattrs = (int *) palloc(tupdesc->natts * sizeof(int));
...@@ -881,9 +871,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -881,9 +871,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
************************************************************/ ************************************************************/
attnum = SPI_fnumber(tupdesc, ret_values[i++]); attnum = SPI_fnumber(tupdesc, ret_values[i++]);
if (attnum == SPI_ERROR_NOATTRIBUTE) if (attnum == SPI_ERROR_NOATTRIBUTE)
elog(ERROR, "pltcl: invalid attribute '%s'", ret_values[--i]); elog(ERROR, "invalid attribute \"%s\"",
ret_values[--i]);
if (attnum <= 0) if (attnum <= 0)
elog(ERROR, "pltcl: cannot set system attribute '%s'", ret_values[--i]); elog(ERROR, "cannot set system attribute \"%s\"",
ret_values[--i]);
/************************************************************ /************************************************************
* Lookup the attribute type in the syscache * Lookup the attribute type in the syscache
...@@ -893,11 +885,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -893,11 +885,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
ObjectIdGetDatum(tupdesc->attrs[attnum - 1]->atttypid), ObjectIdGetDatum(tupdesc->attrs[attnum - 1]->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
{ elog(ERROR, "cache lookup failed for type %u",
elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed",
ret_values[--i],
tupdesc->attrs[attnum - 1]->atttypid); tupdesc->attrs[attnum - 1]->atttypid);
}
typinput = ((Form_pg_type) GETSTRUCT(typeTup))->typinput; typinput = ((Form_pg_type) GETSTRUCT(typeTup))->typinput;
typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
ReleaseSysCache(typeTup); ReleaseSysCache(typeTup);
...@@ -924,7 +913,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -924,7 +913,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
pfree(modnulls); pfree(modnulls);
if (rettup == NULL) if (rettup == NULL)
elog(ERROR, "pltcl: SPI_modifytuple() failed - RC = %d\n", SPI_result); elog(ERROR, "SPI_modifytuple() failed - RC = %d", SPI_result);
ckfree((char *) ret_values); ckfree((char *) ret_values);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
...@@ -954,7 +943,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -954,7 +943,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
ObjectIdGetDatum(fn_oid), ObjectIdGetDatum(fn_oid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procTup)) if (!HeapTupleIsValid(procTup))
elog(ERROR, "pltcl: cache lookup for proc %u failed", fn_oid); elog(ERROR, "cache lookup failed for function %u", fn_oid);
procStruct = (Form_pg_proc) GETSTRUCT(procTup); procStruct = (Form_pg_proc) GETSTRUCT(procTup);
/************************************************************ /************************************************************
...@@ -1018,7 +1007,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1018,7 +1007,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
************************************************************/ ************************************************************/
prodesc = (pltcl_proc_desc *) malloc(sizeof(pltcl_proc_desc)); prodesc = (pltcl_proc_desc *) malloc(sizeof(pltcl_proc_desc));
if (prodesc == NULL) if (prodesc == NULL)
elog(ERROR, "pltcl: out of memory"); ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
MemSet(prodesc, 0, sizeof(pltcl_proc_desc)); MemSet(prodesc, 0, sizeof(pltcl_proc_desc));
prodesc->proname = strdup(internal_proname); prodesc->proname = strdup(internal_proname);
prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data); prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
...@@ -1034,7 +1025,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1034,7 +1025,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl: cache lookup for language %u failed", elog(ERROR, "cache lookup failed for language %u",
procStruct->prolang); procStruct->prolang);
} }
langStruct = (Form_pg_language) GETSTRUCT(langTup); langStruct = (Form_pg_language) GETSTRUCT(langTup);
...@@ -1059,7 +1050,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1059,7 +1050,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl: cache lookup for return type %u failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->prorettype); procStruct->prorettype);
} }
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
...@@ -1073,16 +1064,18 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1073,16 +1064,18 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl functions cannot return type %s" ereport(ERROR,
"\n\texcept when used as triggers", (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
format_type_be(procStruct->prorettype)); errmsg("trigger functions may only be called as triggers")));
} }
else else
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl functions cannot return type %s", ereport(ERROR,
format_type_be(procStruct->prorettype)); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("pltcl functions cannot return type %s",
format_type_be(procStruct->prorettype))));
} }
} }
...@@ -1090,7 +1083,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1090,7 +1083,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl: return types of tuples not supported yet"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("pltcl functions cannot return tuples yet")));
} }
perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func)); perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func));
...@@ -1116,7 +1111,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1116,7 +1111,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl: cache lookup for argument type %u failed", elog(ERROR, "cache lookup failed for type %u",
procStruct->proargtypes[i]); procStruct->proargtypes[i]);
} }
typeStruct = (Form_pg_type) GETSTRUCT(typeTup); typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
...@@ -1126,8 +1121,10 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1126,8 +1121,10 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl functions cannot take type %s", ereport(ERROR,
format_type_be(procStruct->proargtypes[i])); (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("pltcl functions cannot take type %s",
format_type_be(procStruct->proargtypes[i]))));
} }
if (typeStruct->typrelid != InvalidOid) if (typeStruct->typrelid != InvalidOid)
...@@ -1230,7 +1227,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ...@@ -1230,7 +1227,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{ {
free(prodesc->proname); free(prodesc->proname);
free(prodesc); free(prodesc);
elog(ERROR, "pltcl: cannot create internal procedure %s - %s", elog(ERROR, "could not create internal procedure \"%s\": %s",
internal_proname, interp->result); internal_proname, interp->result);
} }
...@@ -1802,45 +1799,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, ...@@ -1802,45 +1799,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
if (plan == NULL) if (plan == NULL)
{ {
char buf[128];
char *reason;
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
elog(ERROR, "SPI_prepare() failed");
switch (SPI_result)
{
case SPI_ERROR_ARGUMENT:
reason = "SPI_ERROR_ARGUMENT";
break;
case SPI_ERROR_UNCONNECTED:
reason = "SPI_ERROR_UNCONNECTED";
break;
case SPI_ERROR_COPY:
reason = "SPI_ERROR_COPY";
break;
case SPI_ERROR_CURSOR:
reason = "SPI_ERROR_CURSOR";
break;
case SPI_ERROR_TRANSACTION:
reason = "SPI_ERROR_TRANSACTION";
break;
case SPI_ERROR_OPUNKNOWN:
reason = "SPI_ERROR_OPUNKNOWN";
break;
default:
snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result);
reason = buf;
break;
}
elog(ERROR, "pltcl: SPI_prepare() failed - %s", reason);
} }
/************************************************************ /************************************************************
...@@ -1850,29 +1810,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, ...@@ -1850,29 +1810,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
qdesc->plan = SPI_saveplan(plan); qdesc->plan = SPI_saveplan(plan);
if (qdesc->plan == NULL) if (qdesc->plan == NULL)
{ {
char buf[128];
char *reason;
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
elog(ERROR, "SPI_saveplan() failed");
switch (SPI_result)
{
case SPI_ERROR_ARGUMENT:
reason = "SPI_ERROR_ARGUMENT";
break;
case SPI_ERROR_UNCONNECTED:
reason = "SPI_ERROR_UNCONNECTED";
break;
default:
snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result);
reason = buf;
break;
}
elog(ERROR, "pltcl: SPI_saveplan() failed - %s", reason);
} }
/* Release the procCxt copy to avoid within-function memory leak */ /* Release the procCxt copy to avoid within-function memory leak */
SPI_freeplan(plan); SPI_freeplan(plan);
...@@ -2359,10 +2298,8 @@ pltcl_set_tuple_values(Tcl_Interp *interp, CONST84 char *arrayname, ...@@ -2359,10 +2298,8 @@ pltcl_set_tuple_values(Tcl_Interp *interp, CONST84 char *arrayname,
ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), ObjectIdGetDatum(tupdesc->attrs[i]->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
{ elog(ERROR, "cache lookup failed for type %u",
elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed", tupdesc->attrs[i]->atttypid);
attname, tupdesc->attrs[i]->atttypid);
}
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
...@@ -2431,10 +2368,8 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc, ...@@ -2431,10 +2368,8 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), ObjectIdGetDatum(tupdesc->attrs[i]->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTup)) if (!HeapTupleIsValid(typeTup))
{ elog(ERROR, "cache lookup failed for type %u",
elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed", tupdesc->attrs[i]->atttypid);
attname, tupdesc->attrs[i]->atttypid);
}
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment