mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Convert a few more datatype input functions to report errors softly.
Convert bit_in, varbit_in, inet_in, cidr_in, macaddr_in, and macaddr8_in to the new style. Amul Sul, minor mods by me Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
This commit is contained in:
@@ -147,11 +147,11 @@ Datum
|
||||
bit_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *input_string = PG_GETARG_CSTRING(0);
|
||||
|
||||
#ifdef NOT_USED
|
||||
Oid typelem = PG_GETARG_OID(1);
|
||||
#endif
|
||||
int32 atttypmod = PG_GETARG_INT32(2);
|
||||
Node *escontext = fcinfo->context;
|
||||
VarBit *result; /* The resulting bit string */
|
||||
char *sp; /* pointer into the character string */
|
||||
bits8 *r; /* pointer into the result */
|
||||
@@ -193,7 +193,7 @@ bit_in(PG_FUNCTION_ARGS)
|
||||
else
|
||||
{
|
||||
if (slen > VARBITMAXLEN / 4)
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("bit string length exceeds the maximum allowed (%d)",
|
||||
VARBITMAXLEN)));
|
||||
@@ -207,7 +207,7 @@ bit_in(PG_FUNCTION_ARGS)
|
||||
if (atttypmod <= 0)
|
||||
atttypmod = bitlen;
|
||||
else if (bitlen != atttypmod)
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_STRING_DATA_LENGTH_MISMATCH),
|
||||
errmsg("bit string length %d does not match type bit(%d)",
|
||||
bitlen, atttypmod)));
|
||||
@@ -229,7 +229,7 @@ bit_in(PG_FUNCTION_ARGS)
|
||||
if (*sp == '1')
|
||||
*r |= x;
|
||||
else if (*sp != '0')
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||
errmsg("\"%.*s\" is not a valid binary digit",
|
||||
pg_mblen(sp), sp)));
|
||||
@@ -254,7 +254,7 @@ bit_in(PG_FUNCTION_ARGS)
|
||||
else if (*sp >= 'a' && *sp <= 'f')
|
||||
x = (bits8) (*sp - 'a') + 10;
|
||||
else
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||
errmsg("\"%.*s\" is not a valid hexadecimal digit",
|
||||
pg_mblen(sp), sp)));
|
||||
@@ -452,11 +452,11 @@ Datum
|
||||
varbit_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *input_string = PG_GETARG_CSTRING(0);
|
||||
|
||||
#ifdef NOT_USED
|
||||
Oid typelem = PG_GETARG_OID(1);
|
||||
#endif
|
||||
int32 atttypmod = PG_GETARG_INT32(2);
|
||||
Node *escontext = fcinfo->context;
|
||||
VarBit *result; /* The resulting bit string */
|
||||
char *sp; /* pointer into the character string */
|
||||
bits8 *r; /* pointer into the result */
|
||||
@@ -494,7 +494,7 @@ varbit_in(PG_FUNCTION_ARGS)
|
||||
else
|
||||
{
|
||||
if (slen > VARBITMAXLEN / 4)
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("bit string length exceeds the maximum allowed (%d)",
|
||||
VARBITMAXLEN)));
|
||||
@@ -508,7 +508,7 @@ varbit_in(PG_FUNCTION_ARGS)
|
||||
if (atttypmod <= 0)
|
||||
atttypmod = bitlen;
|
||||
else if (bitlen > atttypmod)
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
|
||||
errmsg("bit string too long for type bit varying(%d)",
|
||||
atttypmod)));
|
||||
@@ -530,7 +530,7 @@ varbit_in(PG_FUNCTION_ARGS)
|
||||
if (*sp == '1')
|
||||
*r |= x;
|
||||
else if (*sp != '0')
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||
errmsg("\"%.*s\" is not a valid binary digit",
|
||||
pg_mblen(sp), sp)));
|
||||
@@ -555,7 +555,7 @@ varbit_in(PG_FUNCTION_ARGS)
|
||||
else if (*sp >= 'a' && *sp <= 'f')
|
||||
x = (bits8) (*sp - 'a') + 10;
|
||||
else
|
||||
ereport(ERROR,
|
||||
ereturn(escontext, (Datum) 0,
|
||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||
errmsg("\"%.*s\" is not a valid hexadecimal digit",
|
||||
pg_mblen(sp), sp)));
|
||||
|
||||
Reference in New Issue
Block a user