Commit b6a1d25b authored by Tom Lane's avatar Tom Lane

Error message editing in utils/adt. Again thanks to Joe Conway for doing

the bulk of the heavy lifting ...
parent 524cfad2
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.91 2003/06/27 00:33:25 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.92 2003/07/27 04:53:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -90,8 +90,12 @@ getid(const char *s, char *n)
else
{
if (len >= NAMEDATALEN-1)
elog(ERROR, "identifier must be less than %d characters",
NAMEDATALEN);
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("identifier too long"),
errdetail("Identifier must be less than %d characters.",
NAMEDATALEN)));
n[len++] = *s;
}
}
......@@ -157,26 +161,34 @@ aclparse(const char *s, AclItem *aip)
Assert(s && aip);
#ifdef ACLDEBUG
elog(LOG, "aclparse: input = '%s'", s);
elog(LOG, "aclparse: input = \"%s\"", s);
#endif
idtype = ACL_IDTYPE_UID;
s = getid(s, name);
if (*s != '=')
{
/* we just read a keyword, not a name */
if (strncmp(name, ACL_IDTYPE_GID_KEYWORD, sizeof(name)) == 0)
if (strcmp(name, ACL_IDTYPE_GID_KEYWORD) == 0)
idtype = ACL_IDTYPE_GID;
else if (strncmp(name, ACL_IDTYPE_UID_KEYWORD, sizeof(name)) != 0)
elog(ERROR, "aclparse: bad keyword, must be [group|user]");
else if (strcmp(name, ACL_IDTYPE_UID_KEYWORD) != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("unrecognized keyword: \"%s\"", name),
errhint("ACL keyword must be \"group\" or \"user\".")));
s = getid(s, name); /* move s to the name beyond the keyword */
if (name[0] == '\0')
elog(ERROR, "aclparse: a name must follow the [group|user] keyword");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing name"),
errhint("A name must follow the [group|user] keyword.")));
}
if (name[0] == '\0')
idtype = ACL_IDTYPE_WORLD;
if (*s != '=')
elog(ERROR, "aclparse: expecting \"=\" sign");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing \"=\" sign")));
privs = goption = ACL_NO_RIGHTS;
......@@ -221,8 +233,10 @@ aclparse(const char *s, AclItem *aip)
read = ACL_CREATE_TEMP;
break;
default:
elog(ERROR, "aclparse: mode flags must use \"%s\"",
ACL_ALL_RIGHTS_STR);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid mode character: must be one of \"%s\"",
ACL_ALL_RIGHTS_STR)));
}
privs |= read;
......@@ -247,14 +261,18 @@ aclparse(const char *s, AclItem *aip)
{
s = getid(s + 1, name2);
if (name2[0] == '\0')
elog(ERROR, "aclparse: a name must follow the \"/\" sign");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("a name must follow the \"/\" sign")));
aip->ai_grantor = get_usesysid(name2);
}
else
{
aip->ai_grantor = BOOTSTRAP_USESYSID;
elog(WARNING, "defaulting grantor to %u", BOOTSTRAP_USESYSID);
ereport(WARNING,
(errcode(ERRCODE_INVALID_GRANTOR),
errmsg("defaulting grantor to %u", BOOTSTRAP_USESYSID)));
}
ACLITEM_SET_PRIVS_IDTYPE(*aip, privs, goption, idtype);
......@@ -280,7 +298,7 @@ allocacl(int n)
Size size;
if (n < 0)
elog(ERROR, "allocacl: invalid size: %d", n);
elog(ERROR, "invalid size: %d", n);
size = ACL_N_SIZE(n);
new_acl = (Acl *) palloc0(size);
new_acl->size = size;
......@@ -311,7 +329,10 @@ aclitemin(PG_FUNCTION_ARGS)
while (isspace((unsigned char) *s))
++s;
if (*s)
elog(ERROR, "aclitemin: extra garbage at end of specification");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("extra garbage at the end of the ACL specification")));
PG_RETURN_ACLITEM_P(aip);
}
......@@ -373,8 +394,8 @@ aclitemout(PG_FUNCTION_ARGS)
case ACL_IDTYPE_WORLD:
break;
default:
elog(ERROR, "aclitemout: bad idtype: %d",
ACLITEM_GET_IDTYPE(*aip));
elog(ERROR, "unrecognized idtype: %d",
(int) ACLITEM_GET_IDTYPE(*aip));
break;
}
while (*p)
......@@ -482,7 +503,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
owner_default = ACL_ALL_RIGHTS_NAMESPACE;
break;
default:
elog(ERROR, "acldefault: bogus objtype %d", (int) objtype);
elog(ERROR, "unrecognized objtype: %d", (int) objtype);
world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
owner_default = ACL_NO_RIGHTS;
break;
......@@ -644,7 +665,10 @@ restart:
AclItem mod_acl;
if (behavior == DROP_RESTRICT)
elog(ERROR, "dependent privileges exist (use CASCADE to revoke them too)");
ereport(ERROR,
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
errmsg("dependent privileges exist"),
errhint("Use CASCADE to revoke them too.")));
mod_acl.ai_grantor = grantee;
mod_acl.ai_grantee = aip[i].ai_grantee;
......@@ -718,7 +742,9 @@ aclremove(PG_FUNCTION_ARGS)
new_aip = ACL_DAT(new_acl);
if (dst == 0)
{ /* start */
elog(ERROR, "aclremove: removal of the world ACL??");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot remove the world ACL")));
}
else if (dst == old_num - 1)
{ /* end */
......@@ -784,7 +810,9 @@ makeaclitem(PG_FUNCTION_ARGS)
}
else if (u_grantee != 0 && g_grantee != 0)
{
elog(ERROR, "cannot specify both user and group");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot specify both user and group")));
}
else if (u_grantee != 0)
{
......@@ -840,7 +868,9 @@ convert_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TEMPORARY") == 0)
return ACL_CREATE_TEMP;
elog(ERROR, "invalid privilege type %s", priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -1063,8 +1093,9 @@ convert_table_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_TRIGGER);
elog(ERROR, "has_table_privilege: invalid privilege type %s",
priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -1237,7 +1268,9 @@ convert_database_name(text *databasename)
oid = get_database_oid(dbname);
if (!OidIsValid(oid))
elog(ERROR, "database \"%s\" does not exist", dbname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", dbname)));
return oid;
}
......@@ -1272,8 +1305,9 @@ convert_database_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
elog(ERROR, "has_database_privilege: invalid privilege type %s",
priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -1448,7 +1482,9 @@ convert_function_name(text *functionname)
CStringGetDatum(funcname)));
if (!OidIsValid(oid))
elog(ERROR, "function \"%s\" does not exist", funcname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("function \"%s\" does not exist", funcname)));
return oid;
}
......@@ -1473,8 +1509,9 @@ convert_function_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_EXECUTE);
elog(ERROR, "has_function_privilege: invalid privilege type %s",
priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -1649,7 +1686,9 @@ convert_language_name(text *languagename)
CStringGetDatum(langname),
0, 0, 0);
if (!OidIsValid(oid))
elog(ERROR, "language \"%s\" does not exist", langname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", langname)));
return oid;
}
......@@ -1674,8 +1713,9 @@ convert_language_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
elog(ERROR, "has_language_privilege: invalid privilege type %s",
priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -1850,7 +1890,9 @@ convert_schema_name(text *schemaname)
CStringGetDatum(nspname),
0, 0, 0);
if (!OidIsValid(oid))
elog(ERROR, "schema \"%s\" does not exist", nspname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
return oid;
}
......@@ -1880,7 +1922,8 @@ convert_schema_priv_string(text *priv_type_text)
if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
elog(ERROR, "has_schema_privilege: invalid privilege type %s",
priv_type);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized privilege type: \"%s\"", priv_type)));
return ACL_NO_RIGHTS; /* keep compiler quiet */
}
......@@ -6,7 +6,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.5 2003/07/01 00:04:38 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.6 2003/07/27 04:53:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -15,6 +15,7 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
......@@ -44,7 +45,10 @@ array_push(PG_FUNCTION_ARGS)
ArrayMetaState *my_extra;
if (arg0_typeid == InvalidOid || arg1_typeid == InvalidOid)
elog(ERROR, "array_push: cannot determine input data types");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data types")));
arg0_elemid = get_element_type(arg0_typeid);
arg1_elemid = get_element_type(arg1_typeid);
......@@ -63,7 +67,9 @@ array_push(PG_FUNCTION_ARGS)
else
{
/* Shouldn't get here given proper type checking in parser */
elog(ERROR, "array_push: neither input type is an array");
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("neither input type is an array")));
PG_RETURN_NULL(); /* keep compiler quiet */
}
......@@ -87,8 +93,9 @@ array_push(PG_FUNCTION_ARGS)
else if (ARR_NDIM(v) == 0)
indx = 1;
else
elog(ERROR, "only empty and one-dimensional arrays are supported");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("input must be empty or one-dimensional array")));
/*
* We arrange to look up info about element type only once per series
......@@ -169,16 +176,25 @@ array_cat(PG_FUNCTION_ARGS)
/* the rest fall into combo 2, 3, or 4 */
if (ndims1 != ndims2 && ndims1 != ndims2 - 1 && ndims1 != ndims2 + 1)
elog(ERROR, "Cannot concatenate incompatible arrays of %d and "
"%d dimensions", ndims1, ndims2);
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays of %d and %d dimensions are not "
"compatible for concatenation.",
ndims1, ndims2)));
element_type1 = ARR_ELEMTYPE(v1);
element_type2 = ARR_ELEMTYPE(v2);
/* Do we have a matching element types */
if (element_type1 != element_type2)
elog(ERROR, "Cannot concatenate incompatible arrays with element "
"type %u and %u", element_type1, element_type2);
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with element types %s and %s are not "
"compatible for concatenation.",
format_type_be(element_type1),
format_type_be(element_type2))));
/* OK, use it */
element_type = element_type1;
......@@ -211,7 +227,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims1; i++)
{
if (dims1[i] != dims2[i] || lbs1[i] != lbs2[i])
elog(ERROR, "Cannot concatenate arrays with differing dimensions");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
dims[i + 1] = dims1[i];
lbs[i + 1] = lbs1[i];
......@@ -237,7 +257,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims1; i++)
{
if (dims1[i] != dims[i + 1] || lbs1[i] != lbs[i + 1])
elog(ERROR, "Cannot concatenate arrays with differing dimensions");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
}
}
else /* (ndims1 == ndims2 + 1) */
......@@ -260,7 +284,11 @@ array_cat(PG_FUNCTION_ARGS)
for (i = 0; i < ndims2; i++)
{
if (dims2[i] != dims[i + 1] || lbs2[i] != lbs[i + 1])
elog(ERROR, "Cannot concatenate arrays with differing dimensions");
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("cannot concatenate incompatible arrays"),
errdetail("Arrays with differing dimensions are not "
"compatible for concatenation.")));
}
}
......@@ -302,9 +330,18 @@ create_singleton_array(FunctionCallInfo fcinfo,
ArrayMetaState *my_extra;
if (element_type == 0)
elog(ERROR, "Invalid array element type: %u", element_type);
if (ndims < 1 || ndims > MAXDIM)
elog(ERROR, "Invalid number of dimensions %d", ndims);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid array element type: %u", element_type)));
if (ndims < 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid number of dimensions: %d", ndims)));
if (ndims > MAXDIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed, %d",
MAXDIM)));
dvalues[0] = element;
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
* Portions Copyright (c) 1999-2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.15 2003/07/14 16:41:38 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.16 2003/07/27 04:53:03 tgl Exp $
*
*-----------------------------------------------------------------------
*/
......@@ -63,8 +63,10 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *dest, int
}
else
{
elog(ERROR, "unsupported encoding conversion from %s to ASCII",
pg_encoding_to_char(enc));
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsupported encoding conversion from %s to ASCII",
pg_encoding_to_char(enc))));
return; /* keep compiler quiet */
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.27 2003/05/12 23:08:50 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.28 2003/07/27 04:53:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -75,7 +75,9 @@ boolin(PG_FUNCTION_ARGS)
break;
}
elog(ERROR, "Bad boolean external representation '%s'", b);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for boolean: \"%s\"", b)));
/* not reached */
PG_RETURN_BOOL(false);
......
......@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.58 2003/05/13 18:03:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.59 2003/07/27 04:53:03 tgl Exp $
*/
#include "postgres.h"
......@@ -193,7 +193,9 @@ cash_in(PG_FUNCTION_ARGS)
s++;
if (*s != '\0')
elog(ERROR, "Bad money external representation %s", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for money: \"%s\"", str)));
result = (value * sgn);
......@@ -290,7 +292,9 @@ cash_out(PG_FUNCTION_ARGS)
if (minus)
{
if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol))))
elog(ERROR, "Memory allocation failed, can't output cash");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* Position code of 0 means use parens */
if (convention == 0)
......@@ -303,7 +307,9 @@ cash_out(PG_FUNCTION_ARGS)
else
{
if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count)))
elog(ERROR, "Memory allocation failed, can't output cash");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
strcpy(result, buf + count);
}
......@@ -468,7 +474,9 @@ cash_div_flt8(PG_FUNCTION_ARGS)
Cash result;
if (f == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / f);
PG_RETURN_CASH(result);
......@@ -518,7 +526,9 @@ cash_div_flt4(PG_FUNCTION_ARGS)
Cash result;
if (f == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / f);
PG_RETURN_CASH(result);
......@@ -569,7 +579,9 @@ cash_div_int4(PG_FUNCTION_ARGS)
Cash result;
if (i == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / i);
......@@ -619,7 +631,9 @@ cash_div_int2(PG_FUNCTION_ARGS)
Cash result;
if (s == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = rint(c / s);
PG_RETURN_CASH(result);
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.35 2003/05/12 23:08:50 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.36 2003/07/27 04:53:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -181,7 +181,9 @@ chardiv(PG_FUNCTION_ARGS)
char arg2 = PG_GETARG_CHAR(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_CHAR((int8) arg1 / (int8) arg2);
}
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.106 2003/06/25 21:14:14 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.107 2003/07/27 04:53:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1251,7 +1251,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
switch (val)
{
case DTK_CURRENT:
elog(ERROR, "'CURRENT' is no longer supported");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"current\" is no longer supported")));
return -1;
break;
......@@ -1428,7 +1431,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1);
else
elog(ERROR, "Inconsistent use of year %04d and 'BC'", tm->tm_year);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("inconsistent use of year %04d and \"BC\"",
tm->tm_year)));
}
else if (is2digits)
{
......@@ -1965,7 +1971,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
switch (val)
{
case DTK_CURRENT:
elog(ERROR, "'CURRENT' is no longer supported");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"current\" is no longer supported")));
return -1;
break;
......@@ -2238,7 +2246,10 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm)
if (tm->tm_year > 0)
tm->tm_year = -(tm->tm_year - 1);
else
elog(ERROR, "Inconsistent use of year %04d and 'BC'", tm->tm_year);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("inconsistent use of year %04d and \"BC\"",
tm->tm_year)));
}
else if (is2digits)
{
......@@ -2554,7 +2565,7 @@ DecodeNumberField(int len, char *str, int fmask,
*
* Return 0 if okay (and set *tzp), nonzero if not okay.
*
* NB: this must *not* elog on failure; see commands/variable.c.
* NB: this must *not* ereport on failure; see commands/variable.c.
*
* Note: we allow timezone offsets up to 13:59. There are places that
* use +1300 summer time.
......@@ -2611,7 +2622,7 @@ DecodeTimezone(char *str, int *tzp)
*
* Return 0 if okay (and set *tzp), nonzero if not okay.
*
* NB: this must *not* elog on failure; see commands/variable.c.
* NB: this must *not* ereport on failure; see commands/variable.c.
*/
int
DecodePosixTimezone(char *str, int *tzp)
......@@ -2663,7 +2674,7 @@ DecodePosixTimezone(char *str, int *tzp)
* Implement a cache lookup since it is likely that dates
* will be related in format.
*
* NB: this must *not* elog on failure;
* NB: this must *not* ereport on failure;
* see commands/variable.c.
*/
int
......@@ -3715,7 +3726,7 @@ CheckDateTokenTable(const char *tablename, datetkn *base, unsigned int nel)
{
if (strncmp(base[i-1].token, base[i].token, TOKMAXLEN) >= 0)
{
elog(LOG, "Ordering error in %s table: \"%.*s\" >= \"%.*s\"",
elog(LOG, "ordering error in %s table: \"%.*s\" >= \"%.*s\"",
tablename,
TOKMAXLEN, base[i-1].token,
TOKMAXLEN, base[i].token);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.25 2002/09/04 20:31:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.26 2003/07/27 04:53:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -75,7 +75,10 @@ datumGetSize(Datum value, bool typByVal, int typLen)
struct varlena *s = (struct varlena *) DatumGetPointer(value);
if (!PointerIsValid(s))
elog(ERROR, "datumGetSize: Invalid Datum Pointer");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) VARATT_SIZE(s);
}
else if (typLen == -2)
......@@ -84,12 +87,15 @@ datumGetSize(Datum value, bool typByVal, int typLen)
char *s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s))
elog(ERROR, "datumGetSize: Invalid Datum Pointer");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) (strlen(s) + 1);
}
else
{
elog(ERROR, "datumGetSize: Invalid typLen %d", typLen);
elog(ERROR, "invalid typLen: %d", typLen);
size = 0; /* keep compiler quiet */
}
}
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.6 2001/11/05 17:46:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/encode.c,v 1.7 2003/07/27 04:53:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -50,7 +50,9 @@ binary_encode(PG_FUNCTION_ARGS)
enc = pg_find_encoding(namebuf);
if (enc == NULL)
elog(ERROR, "No such encoding as '%s'", namebuf);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized encoding: \"%s\"", namebuf)));
resultlen = enc->encode_len(VARDATA(data), datalen);
result = palloc(VARHDRSZ + resultlen);
......@@ -59,7 +61,7 @@ binary_encode(PG_FUNCTION_ARGS)
/* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen)
elog(FATAL, "Overflow - encode estimate too small");
elog(FATAL, "overflow - encode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res;
......@@ -84,7 +86,9 @@ binary_decode(PG_FUNCTION_ARGS)
enc = pg_find_encoding(namebuf);
if (enc == NULL)
elog(ERROR, "No such encoding as '%s'", namebuf);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unrecognized encoding: \"%s\"", namebuf)));
resultlen = enc->decode_len(VARDATA(data), datalen);
result = palloc(VARHDRSZ + resultlen);
......@@ -93,7 +97,7 @@ binary_decode(PG_FUNCTION_ARGS)
/* Make this FATAL 'cause we've trodden on memory ... */
if (res > resultlen)
elog(FATAL, "Overflow - decode estimate too small");
elog(FATAL, "overflow - decode estimate too small");
VARATT_SIZEP(result) = VARHDRSZ + res;
......@@ -141,7 +145,9 @@ get_hex(unsigned c)
res = hexlookup[c];
if (res < 0)
elog(ERROR, "Bad hex code: '%c'", c);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid hex digit: \"%c\"", c)));
return (uint8) res;
}
......@@ -167,7 +173,10 @@ hex_decode(const uint8 *src, unsigned len, uint8 *dst)
}
v1 = get_hex(*s++) << 4;
if (s >= srcend)
elog(ERROR, "hex_decode: invalid data");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid hex data: odd number of digits")));
v2 = get_hex(*s++);
*p++ = v1 | v2;
}
......@@ -281,7 +290,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
else if (pos == 3)
end = 2;
else
elog(ERROR, "base64: unexpected '='");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unexpected \"=\"")));
}
b = 0;
}
......@@ -291,7 +302,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
if (c > 0 && c < 127)
b = b64lookup[c];
if (b < 0)
elog(ERROR, "base64: Invalid symbol");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid symbol")));
}
/* add it to buffer */
buf = (buf << 6) + b;
......@@ -309,7 +322,9 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
}
if (pos != 0)
elog(ERROR, "base64: invalid end sequence");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid end sequence")));
return p - dst;
}
......@@ -416,7 +431,9 @@ esc_decode(const uint8 *src, unsigned srclen, uint8 *dst)
* One backslash, not followed by ### valid octal. Should
* never get here, since esc_dec_len does same check.
*/
elog(ERROR, "decode: Bad input string for type bytea");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
}
len++;
......@@ -479,7 +496,9 @@ esc_dec_len(const uint8 *src, unsigned srclen)
/*
* one backslash, not followed by ### valid octal
*/
elog(ERROR, "decode: Bad input string for type bytea");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for bytea")));
}
len++;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.89 2003/05/26 00:55:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.90 2003/07/27 04:53:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -115,7 +115,7 @@ static void CheckFloat8Val(double val);
* check to see if a float4 val is outside of
* the FLOAT4_MIN, FLOAT4_MAX bounds.
*
* raise an elog warning if it is
* raise an ereport warning if it is
*/
static void
CheckFloat4Val(double val)
......@@ -128,9 +128,14 @@ CheckFloat4Val(double val)
return;
#else
if (fabs(val) > FLOAT4_MAX)
elog(ERROR, "Bad float4 input format -- overflow");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float4 value out of range: overflow")));
if (val != 0.0 && fabs(val) < FLOAT4_MIN)
elog(ERROR, "Bad float4 input format -- underflow");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float4 value out of range: underflow")));
return;
#endif /* UNSAFE_FLOATS */
}
......@@ -139,7 +144,7 @@ CheckFloat4Val(double val)
* check to see if a float8 val is outside of
* the FLOAT8_MIN, FLOAT8_MAX bounds.
*
* raise an elog error if it is
* raise an ereport error if it is
*/
static void
CheckFloat8Val(double val)
......@@ -152,9 +157,13 @@ CheckFloat8Val(double val)
return;
#else
if (fabs(val) > FLOAT8_MAX)
elog(ERROR, "Bad float8 input format -- overflow");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float8 value out of range: overflow")));
if (val != 0.0 && fabs(val) < FLOAT8_MIN)
elog(ERROR, "Bad float8 input format -- underflow");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("float8 value out of range: underflow")));
#endif /* UNSAFE_FLOATS */
}
......@@ -184,12 +193,17 @@ float4in(PG_FUNCTION_ARGS)
if (strcasecmp(num, "NaN") == 0)
val = NAN;
else
elog(ERROR, "Bad float4 input format '%s'", num);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float4: \"%s\"",
num)));
}
else
{
if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float4", num);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for float4", num)));
}
/*
......@@ -280,12 +294,17 @@ float8in(PG_FUNCTION_ARGS)
else if (strcasecmp(num, "-Infinity") == 0)
val = -HUGE_VAL;
else
elog(ERROR, "Bad float8 input format '%s'", num);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for float8: \"%s\"",
num)));
}
else
{
if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float8", num);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"%s\" is out of range for float8", num)));
}
CheckFloat8Val(val);
......@@ -535,7 +554,9 @@ float4div(PG_FUNCTION_ARGS)
double result;
if (arg2 == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* Do division in float8, then check for overflow */
result = (float8) arg1 / (float8) arg2;
......@@ -597,7 +618,9 @@ float8div(PG_FUNCTION_ARGS)
float8 result;
if (arg2 == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2;
......@@ -847,7 +870,9 @@ dtoi4(PG_FUNCTION_ARGS)
int32 result;
if ((num < INT_MIN) || (num > INT_MAX))
elog(ERROR, "dtoi4: integer out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int32) rint(num);
PG_RETURN_INT32(result);
......@@ -864,7 +889,9 @@ dtoi2(PG_FUNCTION_ARGS)
int16 result;
if ((num < SHRT_MIN) || (num > SHRT_MAX))
elog(ERROR, "dtoi2: integer out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int16) rint(num);
PG_RETURN_INT16(result);
......@@ -909,7 +936,9 @@ ftoi4(PG_FUNCTION_ARGS)
int32 result;
if ((num < INT_MIN) || (num > INT_MAX))
elog(ERROR, "ftoi4: integer out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int32) rint(num);
PG_RETURN_INT32(result);
......@@ -926,7 +955,9 @@ ftoi2(PG_FUNCTION_ARGS)
int16 result;
if ((num < SHRT_MIN) || (num > SHRT_MAX))
elog(ERROR, "ftoi2: integer out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
result = (int16) rint(num);
PG_RETURN_INT16(result);
......@@ -1160,7 +1191,9 @@ dsqrt(PG_FUNCTION_ARGS)
float8 result;
if (arg1 < 0)
elog(ERROR, "can't take sqrt of a negative number");
ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take square root of a negative number")));
result = sqrt(arg1);
......@@ -1204,7 +1237,9 @@ dpow(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "pow() result is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("result is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1232,7 +1267,9 @@ dexp(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "exp() result is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("result is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1250,9 +1287,14 @@ dlog1(PG_FUNCTION_ARGS)
float8 result;
if (arg1 == 0.0)
elog(ERROR, "can't take log of zero");
ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of zero")));
if (arg1 < 0)
elog(ERROR, "can't take log of a negative number");
ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of a negative number")));
result = log(arg1);
......@@ -1271,9 +1313,14 @@ dlog10(PG_FUNCTION_ARGS)
float8 result;
if (arg1 == 0.0)
elog(ERROR, "can't take log of zero");
ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of zero")));
if (arg1 < 0)
elog(ERROR, "can't take log of a negative number");
ereport(ERROR,
(errcode(ERRCODE_FLOATING_POINT_EXCEPTION),
errmsg("cannot take log of a negative number")));
result = log10(arg1);
......@@ -1298,7 +1345,9 @@ dacos(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "acos(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1321,7 +1370,9 @@ dasin(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "asin(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1344,7 +1395,9 @@ datan(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "atan(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1368,7 +1421,9 @@ datan2(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "atan2(%f,%f) input is out of range", arg1, arg2);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1391,7 +1446,9 @@ dcos(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "cos(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1414,7 +1471,9 @@ dcot(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "cot(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
result = 1.0 / result;
CheckFloat8Val(result);
......@@ -1438,7 +1497,9 @@ dsin(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "sin(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1461,7 +1522,9 @@ dtan(PG_FUNCTION_ARGS)
|| !finite(result)
#endif
)
elog(ERROR, "tan(%f) input is out of range", arg1);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("input is out of range")));
CheckFloat8Val(result);
PG_RETURN_FLOAT8(result);
......@@ -1777,7 +1840,9 @@ float48div(PG_FUNCTION_ARGS)
float8 result;
if (arg2 == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2;
CheckFloat8Val(result);
......@@ -1837,7 +1902,9 @@ float84div(PG_FUNCTION_ARGS)
float8 result;
if (arg2 == 0.0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = arg1 / arg2;
......
......@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.34 2002/09/04 20:31:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.35 2003/07/27 04:53:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -133,8 +133,7 @@ format_type_internal(Oid type_oid, int32 typemod,
if (allow_invalid)
return pstrdup("???");
else
elog(ERROR, "could not locate data type with oid %u in catalog",
type_oid);
elog(ERROR, "cache lookup failed for type %u", type_oid);
}
typeform = (Form_pg_type) GETSTRUCT(tuple);
......@@ -159,8 +158,7 @@ format_type_internal(Oid type_oid, int32 typemod,
if (allow_invalid)
return pstrdup("???[]");
else
elog(ERROR, "could not locate data type with oid %u in catalog",
type_oid);
elog(ERROR, "cache lookup failed for type %u", type_oid);
}
typeform = (Form_pg_type) GETSTRUCT(tuple);
type_oid = array_base_type;
......@@ -312,7 +310,7 @@ format_type_internal(Oid type_oid, int32 typemod,
fieldstr = "";
break;
default:
elog(LOG, "Invalid INTERVAL typmod 0x%x", typemod);
elog(ERROR, "invalid INTERVAL typmod: 0x%x", typemod);
fieldstr = "";
break;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.54 2003/05/09 15:44:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.55 2003/07/27 04:53:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -121,7 +121,10 @@ int2vectorin(PG_FUNCTION_ARGS)
while (*intString && isspace((unsigned char) *intString))
intString++;
if (*intString)
elog(ERROR, "int2vector value has too many values");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("int2vector has too many elements")));
while (slot < INDEX_MAX_KEYS)
result[slot++] = 0;
......@@ -281,10 +284,10 @@ i4toi2(PG_FUNCTION_ARGS)
{
int32 arg1 = PG_GETARG_INT32(0);
if (arg1 < SHRT_MIN)
elog(ERROR, "i4toi2: '%d' causes int2 underflow", arg1);
if (arg1 > SHRT_MAX)
elog(ERROR, "i4toi2: '%d' causes int2 overflow", arg1);
if (arg1 < SHRT_MIN || arg1 > SHRT_MAX)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT16((int16) arg1);
}
......@@ -640,7 +643,9 @@ int4div(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
......@@ -703,7 +708,9 @@ int2div(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT16(arg1 / arg2);
}
......@@ -742,7 +749,9 @@ int24div(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
......@@ -781,7 +790,9 @@ int42div(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 / arg2);
}
......@@ -793,7 +804,9 @@ int4mod(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
......@@ -805,7 +818,9 @@ int2mod(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT16(arg1 % arg2);
}
......@@ -817,7 +832,9 @@ int24mod(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
......@@ -829,7 +846,9 @@ int42mod(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT32(arg1 % arg2);
}
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.44 2003/05/09 15:44:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.45 2003/07/27 04:53:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -36,7 +36,7 @@
/*
* scanint8 --- try to parse a string into an int8.
*
* If errorOK is false, elog a useful error message if the string is bad.
* If errorOK is false, ereport a useful error message if the string is bad.
* If errorOK is true, just return "false" for bad input.
*/
bool
......@@ -83,7 +83,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK)
return false;
else
elog(ERROR, "Bad int8 external representation \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for int8: \"%s\"", str)));
}
/* process digits */
......@@ -96,7 +98,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK)
return false;
else
elog(ERROR, "int8 value out of range: \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
}
tmp = newtmp;
}
......@@ -107,7 +111,9 @@ scanint8(const char *str, bool errorOK, int64 *result)
if (errorOK)
return false;
else
elog(ERROR, "Bad int8 external representation \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for int8: \"%s\"", str)));
}
*result = (sign < 0) ? -tmp : tmp;
......@@ -139,7 +145,7 @@ int8out(PG_FUNCTION_ARGS)
char buf[MAXINT8LEN + 1];
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0)
elog(ERROR, "Unable to format int8");
elog(ERROR, "could not format int8");
result = pstrdup(buf);
PG_RETURN_CSTRING(result);
......@@ -515,7 +521,9 @@ int8div(PG_FUNCTION_ARGS)
int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
......@@ -542,7 +550,9 @@ int8mod(PG_FUNCTION_ARGS)
int64 result;
if (val2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
result = val1 / val2;
result *= val2;
......@@ -638,7 +648,9 @@ int84div(PG_FUNCTION_ARGS)
int32 val2 = PG_GETARG_INT32(1);
if (val2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
......@@ -677,7 +689,9 @@ int48div(PG_FUNCTION_ARGS)
int64 val2 = PG_GETARG_INT64(1);
if (val2 == 0)
elog(ERROR, "division by zero");
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
PG_RETURN_INT64(val1 / val2);
}
......@@ -767,7 +781,9 @@ int84(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */
if ((int64) result != val)
elog(ERROR, "int8 conversion to int4 is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
......@@ -790,7 +806,9 @@ int82(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */
if ((int64) result != val)
elog(ERROR, "int8 conversion to int2 is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT16(result);
}
......@@ -826,7 +844,9 @@ dtoi8(PG_FUNCTION_ARGS)
result = (int64) val;
if ((float8) result != val)
elog(ERROR, "Floating point conversion to int8 is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT64(result);
}
......@@ -863,7 +883,9 @@ ftoi8(PG_FUNCTION_ARGS)
result = (int64) dval;
if ((float8) result != dval)
elog(ERROR, "Floating point conversion to int8 is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT64(result);
}
......@@ -878,7 +900,9 @@ i8tooid(PG_FUNCTION_ARGS)
/* Test for overflow by reverse-conversion. */
if ((int64) result != val)
elog(ERROR, "int8 conversion to OID is out of range");
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("OID out of range")));
PG_RETURN_OID(result);
}
......
......@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.53 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.54 2003/07/27 04:53:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -448,7 +448,11 @@ like_escape_bytea(PG_FUNCTION_ARGS)
*/
BYTEA_NextChar(e, elen);
if (elen != 0)
elog(ERROR, "ESCAPE string must be empty or one character");
ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
e = VARDATA(esc);
/*
......
......@@ -19,7 +19,7 @@
* Copyright (c) 1996-2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like_match.c,v 1.4 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like_match.c,v 1.5 2003/07/27 04:53:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -286,7 +286,11 @@ do_like_escape(text *pat, text *esc)
*/
NextChar(e, elen);
if (elen != 0)
elog(ERROR, "ESCAPE string must be empty or one character");
ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
e = VARDATA(esc);
/*
......
/*
* PostgreSQL type definitions for MAC addresses.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.28 2003/05/13 18:03:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.29 2003/07/27 04:53:06 tgl Exp $
*/
#include "postgres.h"
......@@ -60,12 +60,16 @@ macaddr_in(PG_FUNCTION_ARGS)
count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
&a, &b, &c, &d, &e, &f, junk);
if (count != 6)
elog(ERROR, "macaddr_in: error in parsing \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for macaddr: \"%s\"", str)));
if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
(c < 0) || (c > 255) || (d < 0) || (d > 255) ||
(e < 0) || (e > 255) || (f < 0) || (f > 255))
elog(ERROR, "macaddr_in: illegal address \"%s\"", str);
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("invalid octet value in macaddr: \"%s\"", str)));
result = (macaddr *) palloc(sizeof(macaddr));
......@@ -181,7 +185,9 @@ text_macaddr(PG_FUNCTION_ARGS)
len = (VARSIZE(addr) - VARHDRSZ);
if (len >= sizeof(str))
elog(ERROR, "Text is too long to convert to MAC address");
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("text too long to convert to MAC address")));
memcpy(str, VARDATA(addr), len);
*(str + len) = '\0';
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.109 2003/07/17 00:55:37 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.110 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -239,8 +239,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/
StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
if (strlen(tm->tm_zone) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'",
tm->tm_zone);
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid timezone name: \"%s\"",
tm->tm_zone)));
}
}
}
......@@ -273,8 +275,10 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
*/
StrNCpy(*tzn, tzname[tm->tm_isdst], MAXTZLEN + 1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
elog(WARNING, "Invalid timezone \'%s\'",
tzname[tm->tm_isdst]);
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid timezone name: \"%s\"",
tzname[tm->tm_isdst])));
}
}
}
......@@ -367,11 +371,15 @@ abstimein(PG_FUNCTION_ARGS)
ftype[MAXDATEFIELDS];
if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad abstime external representation (too long) '%s'", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for abstime: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad abstime external representation '%s'", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for abstime: \"%s\"", str)));
switch (dtype)
{
......@@ -401,7 +409,8 @@ abstimein(PG_FUNCTION_ARGS)
break;
default:
elog(ERROR, "Bad abstime (internal coding error) '%s'", str);
elog(ERROR, "unexpected dtype %d while parsing abstime \"%s\"",
dtype, str);
result = INVALID_ABSTIME;
break;
};
......@@ -513,7 +522,7 @@ abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
return -1; /* non-INVALID < INVALID */
#if 0
/* CURRENT is no longer stored internally... */
/* CURRENT is no longer stored internally... */
/* XXX this is broken, should go away: */
if (a == CURRENT_ABSTIME)
a = GetCurrentTransactionStartTime();
......@@ -617,7 +626,9 @@ timestamp_abstime(PG_FUNCTION_ARGS)
}
else
{
elog(ERROR, "Unable to convert timestamp to abstime");
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = INVALID_ABSTIME;
}
......@@ -641,7 +652,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
switch (abstime)
{
case INVALID_ABSTIME:
elog(ERROR, "Unable to convert abstime 'invalid' to timestamp");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" abstime to timestamp")));
TIMESTAMP_NOBEGIN(result);
break;
......@@ -656,8 +669,9 @@ abstime_timestamp(PG_FUNCTION_ARGS)
default:
abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, NULL, &result) != 0)
elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP"
"\n\tabstime_timestamp() internal error");
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
break;
};
......@@ -685,7 +699,9 @@ timestamptz_abstime(PG_FUNCTION_ARGS)
result = tm2abstime(tm, 0);
else
{
elog(ERROR, "Unable to convert timestamp to abstime");
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
result = INVALID_ABSTIME;
}
......@@ -709,7 +725,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
switch (abstime)
{
case INVALID_ABSTIME:
elog(ERROR, "Unable to convert abstime 'invalid' to timestamptz");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" abstime to timestamptz")));
TIMESTAMP_NOBEGIN(result);
break;
......@@ -724,8 +742,9 @@ abstime_timestamptz(PG_FUNCTION_ARGS)
default:
abstime2tm(abstime, &tz, tm, &tzn);
if (tm2timestamp(tm, 0, &tz, &result) != 0)
elog(ERROR, "Unable to convert ABSTIME to TIMESTAMP WITH TIME ZONE"
"\n\tabstime_timestamptz() internal error");
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("timestamp out of range")));
break;
};
......@@ -755,11 +774,15 @@ reltimein(PG_FUNCTION_ARGS)
char lowstr[MAXDATELEN + 1];
if (strlen(str) >= sizeof(lowstr))
elog(ERROR, "Bad reltime external representation (too long) '%s'", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for reltime: \"%s\"", str)));
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad reltime external representation '%s'", str);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for reltime: \"%s\"", str)));
switch (dtype)
{
......@@ -769,7 +792,8 @@ reltimein(PG_FUNCTION_ARGS)
break;
default:
elog(ERROR, "Bad reltime (internal coding error) '%s'", str);
elog(ERROR, "unexpected dtype %d while parsing reltime \"%s\"",
dtype, str);
result = INVALID_RELTIME;
break;
}
......@@ -851,7 +875,10 @@ tintervalin(PG_FUNCTION_ARGS)
interval = (TimeInterval) palloc(sizeof(TimeIntervalData));
if (istinterval(intervalstr, &t1, &t2) == 0)
elog(ERROR, "Unable to decode tinterval '%s'", intervalstr);
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("invalid input syntax for tinterval: \"%s\"",
intervalstr)));
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
interval->status = T_INTERVAL_INVAL; /* undefined */
......@@ -911,7 +938,10 @@ tintervalrecv(PG_FUNCTION_ARGS)
interval->status = pq_getmsgint(buf, sizeof(interval->status));
if (!(interval->status == T_INTERVAL_INVAL ||
interval->status == T_INTERVAL_VALID))
elog(ERROR, "Invalid status in external tinterval");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid status in external tinterval")));
interval->data[0] = pq_getmsgint(buf, sizeof(interval->data[0]));
interval->data[1] = pq_getmsgint(buf, sizeof(interval->data[1]));
......@@ -1000,7 +1030,9 @@ reltime_interval(PG_FUNCTION_ARGS)
switch (reltime)
{
case INVALID_RELTIME:
elog(ERROR, "Unable to convert reltime 'invalid' to interval");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert \"invalid\" reltime to interval")));
result->time = 0;
result->month = 0;
break;
......
......@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.46 2003/05/15 15:50:18 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.47 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -48,12 +48,10 @@ namein(PG_FUNCTION_ARGS)
char *s = PG_GETARG_CSTRING(0);
NameData *result;
int len;
char *ermsg;
/* verify encoding */
len = strlen(s);
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
pg_verifymbstr(s, len, false);
len = pg_mbcliplen(s, len, NAMEDATALEN - 1);
......@@ -87,7 +85,11 @@ namerecv(PG_FUNCTION_ARGS)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
if (nbytes >= NAMEDATALEN)
elog(ERROR, "namerecv: input name too long");
ereport(ERROR,
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("identifier too long"),
errdetail("Identifier must be less than %d characters.",
NAMEDATALEN)));
result = (NameData *) palloc0(NAMEDATALEN);
memcpy(result, str, nbytes);
pfree(str);
......
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.42 2003/06/24 22:21:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.43 2003/07/27 04:53:07 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
......@@ -85,17 +85,23 @@ network_in(char *src, int type)
bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
type ? ip_addrsize(dst) : -1);
if ((bits < 0) || (bits > ip_maxbits(dst)))
elog(ERROR, "invalid %s value '%s'",
type ? "CIDR" : "INET", src);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
/* translator: first %s is inet or cidr */
errmsg("invalid input syntax for %s: \"%s\"",
type ? "cidr" : "inet", src)));
/*
/*
* Error check: CIDR values must not have any bits set beyond
* the masklen.
*/
if (type)
*/
if (type)
{
if (!addressOK(ip_addr(dst), bits, ip_family(dst)))
elog(ERROR, "invalid CIDR value '%s': has bits set to right of mask", src);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid cidr value: \"%s\"", src),
errdetail("Value has bits set to right of mask.")));
}
VARATT_SIZEP(dst) = VARHDRSZ
......@@ -139,7 +145,10 @@ inet_out(PG_FUNCTION_ARGS)
dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
tmp, sizeof(tmp));
if (dst == NULL)
elog(ERROR, "unable to print address (%s)", strerror(errno));
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* For CIDR, add /n if not present */
if (ip_type(src) && strchr(tmp, '/') == NULL)
{
......@@ -180,18 +189,25 @@ inet_recv(PG_FUNCTION_ARGS)
ip_family(addr) = pq_getmsgbyte(buf);
if (ip_family(addr) != AF_INET)
elog(ERROR, "Invalid family in external inet");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid family in external inet")));
bits = pq_getmsgbyte(buf);
if (bits < 0 || bits > ip_maxbits(addr))
elog(ERROR, "Invalid bits in external inet");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid bits in external inet")));
ip_bits(addr) = bits;
ip_type(addr) = pq_getmsgbyte(buf);
if (ip_type(addr) != 0 && ip_type(addr) != 1)
elog(ERROR, "Invalid type in external inet");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid type in external inet")));
nb = pq_getmsgbyte(buf);
if (nb != ip_addrsize(addr))
elog(ERROR, "Invalid length in external inet");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid length in external inet")));
VARATT_SIZEP(addr) = VARHDRSZ
+ ((char *)ip_addr(addr) - (char *) VARDATA(addr))
+ ip_addrsize(addr);
......@@ -207,7 +223,10 @@ inet_recv(PG_FUNCTION_ARGS)
if (ip_type(addr))
{
if (!addressOK(ip_addr(addr), bits, ip_family(addr)))
elog(ERROR, "invalid external CIDR value: has bits set to right of mask");
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid external CIDR value"),
errdetail("Value has bits set to right of mask.")));
}
PG_RETURN_INET_P(addr);
......@@ -291,7 +310,9 @@ inet_set_masklen(PG_FUNCTION_ARGS)
bits = ip_maxbits(src);
if ((bits < 0) || (bits > ip_maxbits(src)))
elog(ERROR, "set_masklen - invalid value '%d'", bits);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid mask length: %d", bits)));
/* clone the original data */
dst = (inet *) palloc(VARHDRSZ + sizeof(inet_struct));
......@@ -477,7 +498,9 @@ network_host(PG_FUNCTION_ARGS)
/* force display of max bits, regardless of masklen... */
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
tmp, sizeof(tmp)) == NULL)
elog(ERROR, "unable to print host (%s)", strerror(errno));
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Suppress /n if present (shouldn't happen now) */
if ((ptr = strchr(tmp, '/')) != NULL)
......@@ -501,7 +524,10 @@ network_show(PG_FUNCTION_ARGS)
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
tmp, sizeof(tmp)) == NULL)
elog(ERROR, "unable to print host (%s)", strerror(errno));
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Add /n if not present (which it won't be) */
if (strchr(tmp, '/') == NULL)
{
......@@ -534,8 +560,9 @@ network_abbrev(PG_FUNCTION_ARGS)
ip_bits(ip), tmp, sizeof(tmp));
if (dst == NULL)
elog(ERROR, "unable to print address (%s)",
strerror(errno));
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("could not format inet value: %m")));
/* Return string as a text datum */
len = strlen(tmp);
......@@ -818,7 +845,7 @@ convert_network_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one network and one non-network operand.
*/
elog(ERROR, "convert_network_to_scalar: unsupported type %u", typid);
elog(ERROR, "unsupported type: %u", typid);
return 0;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.32 2002/09/04 20:31:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.33 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -59,7 +59,10 @@ int4notin(PG_FUNCTION_ARGS)
names = textToQualifiedNameList(relation_and_attr, "int4notin");
nnames = length(names);
if (nnames < 2)
elog(ERROR, "int4notin: must provide relationname.attributename");
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax"),
errhint("Must provide \"relationname.attributename\".")));
attribute = strVal(nth(nnames - 1, names));
names = ltruncate(nnames - 1, names);
relrv = makeRangeVarFromNameList(names);
......
This diff is collapsed.
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.54 2002/09/04 20:31:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.55 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -51,82 +51,73 @@
* c, if not 0, is the terminator character that may appear after the
* integer. If 0, the string must end after the integer.
*
* Unlike plain atoi(), this will throw elog() upon bad input format or
* Unlike plain atoi(), this will throw ereport() upon bad input format or
* overflow.
*/
int32
pg_atoi(char *s, int size, int c)
{
long l = 0;
long l;
char *badp = NULL;
errno = 0;
/*
* Some versions of strtol treat the empty string as an error, but
* some seem not to. Make an explicit test to be sure we catch it.
*/
if (s == (char *) NULL)
elog(ERROR, "pg_atoi: NULL pointer");
else if (*s == 0)
elog(ERROR, "pg_atoi: zero-length string");
else
l = strtol(s, &badp, 10);
elog(ERROR, "NULL pointer");
if (*s == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
errno = 0;
l = strtol(s, &badp, 10);
/*
* strtol() normally only sets ERANGE. On some systems it also may
* set EINVAL, which simply means it couldn't parse the input string.
* This is handled by the second "if" consistent across platforms.
*/
if (errno && errno != EINVAL)
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
if (errno && errno != ERANGE && errno != EINVAL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
if (badp && *badp && *badp != c)
elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
s)));
switch (size)
{
case sizeof(int32):
if (errno == ERANGE
#if defined(HAVE_LONG_INT_64)
/* won't get ERANGE on these with 64-bit longs... */
if (l < INT_MIN)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
if (l > INT_MAX)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
#endif /* HAVE_LONG_INT_64 */
/* won't get ERANGE on these with 64-bit longs... */
|| l < INT_MIN || l > INT_MAX
#endif
)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for int4", s)));
break;
case sizeof(int16):
if (l < SHRT_MIN)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
if (l > SHRT_MAX)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for int2", s)));
break;
case sizeof(int8):
if (l < SCHAR_MIN)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
if (l > SCHAR_MAX)
{
errno = ERANGE;
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
}
if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for int1", s)));
break;
default:
elog(ERROR, "pg_atoi: invalid result size: %d", size);
elog(ERROR, "unsupported result size: %d", size);
}
return (int32) l;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.48 2003/05/09 15:44:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.49 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -34,7 +34,6 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
Oid result;
errno = 0;
cvt = strtoul(s, &endptr, 10);
/*
......@@ -44,12 +43,21 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
* Note that for historical reasons we accept an empty string as
* meaning 0.
*/
if (errno && errno != EINVAL)
elog(ERROR, "%s: error reading \"%s\": %m",
funcname, s);
if (errno && errno != ERANGE && errno != EINVAL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
if (endptr == s && *endptr)
elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"",
funcname, s, endptr);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
if (errno == ERANGE)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for OID", s)));
if (endloc)
{
......@@ -62,8 +70,10 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
while (*endptr && isspace((unsigned char) *endptr))
endptr++;
if (*endptr)
elog(ERROR, "%s: error in \"%s\": can't parse \"%s\"",
funcname, s, endptr);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for OID: \"%s\"",
s)));
}
result = (Oid) cvt;
......@@ -83,8 +93,9 @@ oidin_subr(const char *funcname, const char *s, char **endloc)
#if OID_MAX != ULONG_MAX
if (cvt != (unsigned long) result &&
cvt != (unsigned long) ((int) result))
elog(ERROR, "%s: error reading \"%s\": %s",
funcname, s, strerror(ERANGE));
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("%s is out of range for OID", s)));
#endif
return result;
......@@ -160,7 +171,9 @@ oidvectorin(PG_FUNCTION_ARGS)
while (*oidString && isspace((unsigned char) *oidString))
oidString++;
if (*oidString)
elog(ERROR, "oidvector value has too many values");
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("oidvector has too many elements")));
while (slot < INDEX_MAX_KEYS)
result[slot++] = InvalidOid;
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.45 2003/07/27 03:16:20 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.46 2003/07/27 04:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -201,7 +201,9 @@ lpad(PG_FUNCTION_ARGS)
/* check for integer overflow */
if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
elog(ERROR, "Requested length too large");
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
ret = (text *) palloc(VARHDRSZ + bytelen);
......@@ -296,7 +298,9 @@ rpad(PG_FUNCTION_ARGS)
/* Check for integer overflow */
if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
elog(ERROR, "Requested length too large");
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
ret = (text *) palloc(VARHDRSZ + bytelen);
m = len - s1len;
......@@ -917,7 +921,9 @@ repeat(PG_FUNCTION_ARGS)
int check2 = check + VARHDRSZ;
if ((check / slen) != count || check2 <= check)
elog(ERROR, "Requested buffer is too large.");
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested length too large")));
}
result = (text *) palloc(tlen);
......
......@@ -4,7 +4,7 @@
*
* Portions Copyright (c) 2002, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.20 2002/10/18 20:44:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.21 2003/07/27 04:53:07 tgl Exp $
*
*-----------------------------------------------------------------------
*/
......@@ -157,7 +157,7 @@ lc_collate_is_c(void)
return (bool) result;
localeptr = setlocale(LC_COLLATE, NULL);
if (!localeptr)
elog(PANIC, "Invalid LC_COLLATE setting");
elog(ERROR, "invalid LC_COLLATE setting");
if (strcmp(localeptr, "C") == 0)
result = true;
......
......@@ -186,12 +186,16 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
if (fcinfo->resultinfo == NULL ||
!IsA(fcinfo->resultinfo, ReturnSetInfo))
elog(ERROR, "pg_stat_get_backend_idset: called in context that does not accept a set result");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that "
"cannot accept a set")));
if (fmgr_info->fn_extra == NULL)
{
if (fmgr_info->fn_mcxt == NULL)
elog(ERROR, "No function memory context in set-function");
elog(ERROR, "no function memory context in set-function");
fmgr_info->fn_extra = MemoryContextAlloc(fmgr_info->fn_mcxt,
2 * sizeof(int));
((int *) (fmgr_info->fn_extra))[0] = 0;
......
......@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.7 2003/05/13 18:03:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.8 2003/07/27 04:53:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -33,7 +33,9 @@
Datum
record_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "RECORD");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -44,7 +46,9 @@ record_in(PG_FUNCTION_ARGS)
Datum
record_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "RECORD");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -55,7 +59,9 @@ record_out(PG_FUNCTION_ARGS)
Datum
record_recv(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a value of type %s", "RECORD");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -66,7 +72,9 @@ record_recv(PG_FUNCTION_ARGS)
Datum
record_send(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "RECORD");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type record")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -134,7 +142,9 @@ cstring_send(PG_FUNCTION_ARGS)
Datum
any_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "ANY");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type any")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -145,7 +155,9 @@ any_in(PG_FUNCTION_ARGS)
Datum
any_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "ANY");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type any")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -157,7 +169,9 @@ any_out(PG_FUNCTION_ARGS)
Datum
anyarray_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "ANYARRAY");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type anyarray")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -183,7 +197,9 @@ anyarray_out(PG_FUNCTION_ARGS)
Datum
anyarray_recv(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a value of type %s", "ANYARRAY");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a value of type anyarray")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -231,7 +247,9 @@ void_out(PG_FUNCTION_ARGS)
Datum
trigger_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "TRIGGER");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type trigger")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -242,7 +260,9 @@ trigger_in(PG_FUNCTION_ARGS)
Datum
trigger_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "TRIGGER");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type trigger")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -254,7 +274,9 @@ trigger_out(PG_FUNCTION_ARGS)
Datum
language_handler_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "LANGUAGE_HANDLER");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type language_handler")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -265,7 +287,9 @@ language_handler_in(PG_FUNCTION_ARGS)
Datum
language_handler_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "LANGUAGE_HANDLER");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type language_handler")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -277,7 +301,9 @@ language_handler_out(PG_FUNCTION_ARGS)
Datum
internal_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "INTERNAL");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type internal")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -288,7 +314,9 @@ internal_in(PG_FUNCTION_ARGS)
Datum
internal_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "INTERNAL");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type internal")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -300,7 +328,9 @@ internal_out(PG_FUNCTION_ARGS)
Datum
opaque_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "OPAQUE");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type opaque")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -311,7 +341,9 @@ opaque_in(PG_FUNCTION_ARGS)
Datum
opaque_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "OPAQUE");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type opaque")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -323,7 +355,9 @@ opaque_out(PG_FUNCTION_ARGS)
Datum
anyelement_in(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot accept a constant of type %s", "ANYELEMENT");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot accept a constant of type anyelement")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -334,7 +368,9 @@ anyelement_in(PG_FUNCTION_ARGS)
Datum
anyelement_out(PG_FUNCTION_ARGS)
{
elog(ERROR, "Cannot display a value of type %s", "ANYELEMENT");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot display a value of type anyelement")));
PG_RETURN_VOID(); /* keep compiler quiet */
}
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.45 2003/02/06 20:25:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.46 2003/07/27 04:53:08 tgl Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
......@@ -171,7 +171,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
/* XXX should we pg_regfree here? */
elog(ERROR, "Invalid regular expression: %s", errMsg);
ereport(ERROR,
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
errmsg("invalid regular expression: %s", errMsg)));
}
/*
......@@ -182,7 +184,9 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
if (re_temp.cre_pat == NULL)
{
pg_regfree(&re_temp.cre_re);
elog(ERROR, "Out of memory");
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
memcpy(re_temp.cre_pat, text_re, text_re_len);
re_temp.cre_flags = cflags;
......@@ -450,7 +454,10 @@ similar_escape(PG_FUNCTION_ARGS)
if (elen == 0)
e = NULL; /* no escape character */
else if (elen != 1)
elog(ERROR, "ESCAPE string must be empty or one character");
ereport(ERROR,
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
errmsg("invalid escape string"),
errhint("Escape string must be empty or one character.")));
}
/* We need room for ^, $, and up to 2 output bytes per input byte */
......
......@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.77 2003/05/12 23:08:50 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.78 2003/07/27 04:53:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -112,10 +112,16 @@ regprocin(PG_FUNCTION_ARGS)
heap_close(hdesc, AccessShareLock);
if (matches == 0)
elog(ERROR, "No procedure with name %s", pro_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
else if (matches > 1)
elog(ERROR, "There is more than one procedure named %s",
pro_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one procedure named %s",
pro_name_or_oid)));
PG_RETURN_OID(result);
}
......@@ -127,10 +133,14 @@ regprocin(PG_FUNCTION_ARGS)
clist = FuncnameGetCandidates(names, -1);
if (clist == NULL)
elog(ERROR, "No procedure with name %s", pro_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
else if (clist->next != NULL)
elog(ERROR, "There is more than one procedure named %s",
pro_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one procedure named %s",
pro_name_or_oid)));
result = clist->oid;
......@@ -275,7 +285,9 @@ regprocedurein(PG_FUNCTION_ARGS)
}
if (clist == NULL)
elog(ERROR, "No procedure with name %s", pro_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no procedure with name %s", pro_name_or_oid)));
result = clist->oid;
......@@ -450,10 +462,15 @@ regoperin(PG_FUNCTION_ARGS)
heap_close(hdesc, AccessShareLock);
if (matches == 0)
elog(ERROR, "No operator with name %s", opr_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
else if (matches > 1)
elog(ERROR, "There is more than one operator named %s",
opr_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one operator named %s",
opr_name_or_oid)));
PG_RETURN_OID(result);
}
......@@ -465,10 +482,14 @@ regoperin(PG_FUNCTION_ARGS)
clist = OpernameGetCandidates(names, '\0');
if (clist == NULL)
elog(ERROR, "No operator with name %s", opr_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
else if (clist->next != NULL)
elog(ERROR, "There is more than one operator named %s",
opr_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
errmsg("more than one operator named %s",
opr_name_or_oid)));
result = clist->oid;
......@@ -613,9 +634,15 @@ regoperatorin(PG_FUNCTION_ARGS)
parseNameAndArgTypes(opr_name_or_oid, "regoperatorin", true,
&names, &nargs, argtypes);
if (nargs == 1)
elog(ERROR, "regoperatorin: use NONE to denote the missing argument of a unary operator");
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_PARAMETER),
errmsg("missing argument"),
errhint("Use NONE to denote the missing argument of a unary operator.")));
if (nargs != 2)
elog(ERROR, "regoperatorin: provide two argument types for operator");
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many arguments"),
errhint("Provide two argument types for operator.")));
if (argtypes[0] == InvalidOid)
oprkind = 'l';
......@@ -633,7 +660,9 @@ regoperatorin(PG_FUNCTION_ARGS)
}
if (clist == NULL)
elog(ERROR, "No operator with name %s", opr_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("no operator with name %s", opr_name_or_oid)));
result = clist->oid;
......@@ -803,7 +832,9 @@ regclassin(PG_FUNCTION_ARGS)
if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple);
else
elog(ERROR, "No class with name %s", class_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("no class with name %s", class_name_or_oid)));
/* We assume there can be only one match */
......@@ -967,7 +998,9 @@ regtypein(PG_FUNCTION_ARGS)
if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))
result = HeapTupleGetOid(tuple);
else
elog(ERROR, "No type with name %s", typ_name_or_oid);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("no type with name %s", typ_name_or_oid)));
/* We assume there can be only one match */
......@@ -1072,10 +1105,14 @@ stringToQualifiedNameList(const char *string, const char *caller)
rawname = pstrdup(string);
if (!SplitIdentifierString(rawname, '.', &namelist))
elog(ERROR, "%s: invalid name syntax", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
if (namelist == NIL)
elog(ERROR, "%s: invalid name syntax", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid name syntax")));
foreach(l, namelist)
{
......@@ -1132,7 +1169,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
break;
}
if (*ptr == '\0')
elog(ERROR, "%s: expected a left parenthesis", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a left parenthesis")));
/* Separate the name and parse it into a list */
*ptr++ = '\0';
......@@ -1146,7 +1185,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
break;
}
if (*ptr2 != ')')
elog(ERROR, "%s: expected a right parenthesis", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a right parenthesis")));
*ptr2 = '\0';
/* Separate the remaining string into comma-separated type names */
......@@ -1162,7 +1204,9 @@ parseNameAndArgTypes(const char *string, const char *caller,
{
/* End of string. Okay unless we had a comma before. */
if (had_comma)
elog(ERROR, "%s: expected a type name", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("expected a type name")));
break;
}
typename = ptr;
......@@ -1192,7 +1236,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
}
}
if (in_quote || paren_count != 0)
elog(ERROR, "%s: improper type name", caller);
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("improper type name")));
ptr2 = ptr;
if (*ptr == ',')
{
......@@ -1224,7 +1271,10 @@ parseNameAndArgTypes(const char *string, const char *caller,
parseTypeString(typename, &typeid, &typmod);
}
if (*nargs >= FUNC_MAX_ARGS)
elog(ERROR, "%s: too many argument datatypes", caller);
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("too many argument datatypes")));
argtypes[*nargs] = typeid;
(*nargs)++;
}
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.141 2003/07/17 22:20:14 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.142 2003/07/27 04:53:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -939,7 +939,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
prefix->constvalue));
break;
default:
elog(ERROR, "patternsel: unexpected consttype %u",
elog(ERROR, "unrecognized consttype: %u",
prefix->consttype);
return DEFAULT_MATCH_SEL;
}
......@@ -956,7 +956,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
List *eqargs;
if (eqopr == InvalidOid)
elog(ERROR, "patternsel: no = operator for opclass %u", opclass);
elog(ERROR, "no = operator for opclass %u", opclass);
eqargs = makeList2(var, prefix);
result = DatumGetFloat8(DirectFunctionCall4(eqsel,
PointerGetDatum(root),
......@@ -1136,7 +1136,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
varRelid, jointype);
break;
default:
elog(ERROR, "booltestsel: unexpected booltesttype %d",
elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
......@@ -1213,7 +1213,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = 1.0 - freq_false;
break;
default:
elog(ERROR, "booltestsel: unexpected booltesttype %d",
elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
......@@ -1254,7 +1254,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = (1.0 - freq_null) / 2.0;
break;
default:
elog(ERROR, "booltestsel: unexpected booltesttype %d",
elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
......@@ -1284,7 +1284,7 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
selec = DEFAULT_BOOL_SEL;
break;
default:
elog(ERROR, "booltestsel: unexpected booltesttype %d",
elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
selec = 0.0; /* Keep compiler quiet */
break;
......@@ -1319,7 +1319,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
defselec = DEFAULT_NOT_UNK_SEL;
break;
default:
elog(ERROR, "nulltestsel: unexpected nulltesttype %d",
elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */
}
......@@ -1373,7 +1373,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
selec = 1.0 - freq_null;
break;
default:
elog(ERROR, "nulltestsel: unexpected nulltesttype %d",
elog(ERROR, "unrecognized nulltesttype: %d",
(int) nulltesttype);
return (Selectivity) 0; /* keep compiler quiet */
}
......@@ -2500,7 +2500,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one numeric and one non-numeric operand.
*/
elog(ERROR, "convert_numeric_to_scalar: unsupported type %u", typid);
elog(ERROR, "unsupported type: %u", typid);
return 0;
}
......@@ -2684,7 +2684,7 @@ convert_string_datum(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel on
* an operator with one string and one non-string operand.
*/
elog(ERROR, "convert_string_datum: unsupported type %u", typid);
elog(ERROR, "unsupported type: %u", typid);
return NULL;
}
......@@ -2882,7 +2882,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one timevalue and one non-timevalue operand.
*/
elog(ERROR, "convert_timevalue_to_scalar: unsupported type %u", typid);
elog(ERROR, "unsupported type: %u", typid);
return 0;
}
......@@ -3111,7 +3111,9 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive,
Assert(typeid == BYTEAOID || typeid == TEXTOID);
if (typeid == BYTEAOID && case_insensitive)
elog(ERROR, "Cannot perform case insensitive matching on type BYTEA");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("case insensitive matching not supported on type bytea")));
if (typeid != BYTEAOID)
{
......@@ -3194,7 +3196,9 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
* been made safe for binary (possibly NULL containing) strings.
*/
if (typeid == BYTEAOID)
elog(ERROR, "Regex matching not supported on type BYTEA");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("regex matching not supported on type bytea")));
/* the right-hand const is type text for all of these */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
......@@ -3337,7 +3341,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype,
result = regex_fixed_prefix(patt, true, prefix, rest);
break;
default:
elog(ERROR, "pattern_fixed_prefix: bogus ptype");
elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = Pattern_Prefix_None; /* keep compiler quiet */
break;
}
......@@ -3368,8 +3372,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
cmpopr = get_opclass_member(opclass, BTGreaterEqualStrategyNumber);
if (cmpopr == InvalidOid)
elog(ERROR, "prefix_selectivity: no >= operator for opclass %u",
opclass);
elog(ERROR, "no >= operator for opclass %u", opclass);
cmpargs = makeList2(var, prefixcon);
/* Assume scalargtsel is appropriate for all supported types */
prefixsel = DatumGetFloat8(DirectFunctionCall4(scalargtsel,
......@@ -3390,8 +3393,7 @@ prefix_selectivity(Query *root, Var *var, Oid opclass, Const *prefixcon)
cmpopr = get_opclass_member(opclass, BTLessStrategyNumber);
if (cmpopr == InvalidOid)
elog(ERROR, "prefix_selectivity: no < operator for opclass %u",
opclass);
elog(ERROR, "no < operator for opclass %u", opclass);
cmpargs = makeList2(var, greaterstrcon);
/* Assume scalarltsel is appropriate for all supported types */
topsel = DatumGetFloat8(DirectFunctionCall4(scalarltsel,
......@@ -3472,7 +3474,9 @@ like_selectivity(Const *patt_const, bool case_insensitive)
Assert(typeid == BYTEAOID || typeid == TEXTOID);
if (typeid == BYTEAOID && case_insensitive)
elog(ERROR, "Cannot perform case insensitive matching on type BYTEA");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("case insensitive matching not supported on type bytea")));
if (typeid != BYTEAOID)
{
......@@ -3618,7 +3622,9 @@ regex_selectivity(Const *patt_const, bool case_insensitive)
* been made safe for binary (possibly NULL containing) strings.
*/
if (typeid == BYTEAOID)
elog(ERROR, "Regex matching not supported on type BYTEA");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("regex matching not supported on type bytea")));
/* the right-hand const is type text for all of these */
patt = DatumGetCString(DirectFunctionCall1(textout, patt_const->constvalue));
......@@ -3662,7 +3668,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
result = regex_selectivity(patt, true);
break;
default:
elog(ERROR, "pattern_selectivity: bogus ptype");
elog(ERROR, "unrecognized ptype: %d", (int) ptype);
result = 1.0; /* keep compiler quiet */
break;
}
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.55 2002/12/13 19:45:56 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.56 2003/07/27 04:53:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -83,7 +83,7 @@ SetDefine(char *querystr, Oid elemType)
ObjectIdGetDatum(setoid),
0, 0, 0);
if (!HeapTupleIsValid(tup))
elog(ERROR, "SetDefine: unable to define set %s", querystr);
elog(ERROR, "cache lookup failed for function %u", setoid);
/*
* We can tell whether the set was already defined by checking the
......@@ -201,7 +201,10 @@ seteval(PG_FUNCTION_ARGS)
if (rsi && IsA(rsi, ReturnSetInfo))
rsi->isDone = isDone;
else
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")));
}
PG_RETURN_DATUM(result);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* $Id: pg_wchar.h,v 1.46 2003/06/02 18:59:25 momjian Exp $ */
/* $Id: pg_wchar.h,v 1.47 2003/07/27 04:53:11 tgl Exp $ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
......@@ -323,7 +323,7 @@ extern void LocalToUtf(unsigned char *iso, unsigned char *utf,
extern void UtfToLocal(unsigned char *utf, unsigned char *iso,
pg_utf_to_local *map, int size, int len);
extern char *pg_verifymbstr(const unsigned char *mbstr, int len);
extern bool pg_verifymbstr(const unsigned char *mbstr, int len, bool noError);
extern void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len);
extern void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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