mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Convert contrib/intarray's bqarr_in() to report errors softly
Reviewed by Tom Lane and Amul Sul Discussion: https://postgr.es/m/49e598c2-cfe8-0928-b6fb-d0cc51aab626@dunslane.net
This commit is contained in:
parent
24b55cd949
commit
3b76622e04
@ -35,6 +35,7 @@ typedef struct
|
|||||||
char *buf;
|
char *buf;
|
||||||
int32 state;
|
int32 state;
|
||||||
int32 count;
|
int32 count;
|
||||||
|
struct Node *escontext;
|
||||||
/* reverse polish notation in list (for temporary usage) */
|
/* reverse polish notation in list (for temporary usage) */
|
||||||
NODE *str;
|
NODE *str;
|
||||||
/* number in str */
|
/* number in str */
|
||||||
@ -179,7 +180,7 @@ makepol(WORKSTATE *state)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (lenstack == STACKDEPTH)
|
if (lenstack == STACKDEPTH)
|
||||||
ereport(ERROR,
|
ereturn(state->escontext, ERR,
|
||||||
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
|
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
|
||||||
errmsg("statement too complex")));
|
errmsg("statement too complex")));
|
||||||
stack[lenstack] = val;
|
stack[lenstack] = val;
|
||||||
@ -206,10 +207,9 @@ makepol(WORKSTATE *state)
|
|||||||
break;
|
break;
|
||||||
case ERR:
|
case ERR:
|
||||||
default:
|
default:
|
||||||
ereport(ERROR,
|
ereturn(state->escontext, ERR,
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
errmsg("syntax error")));
|
errmsg("syntax error")));
|
||||||
return ERR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,6 +483,7 @@ bqarr_in(PG_FUNCTION_ARGS)
|
|||||||
ITEM *ptr;
|
ITEM *ptr;
|
||||||
NODE *tmp;
|
NODE *tmp;
|
||||||
int32 pos = 0;
|
int32 pos = 0;
|
||||||
|
struct Node *escontext = fcinfo->context;
|
||||||
|
|
||||||
#ifdef BS_DEBUG
|
#ifdef BS_DEBUG
|
||||||
StringInfoData pbuf;
|
StringInfoData pbuf;
|
||||||
@ -493,16 +494,18 @@ bqarr_in(PG_FUNCTION_ARGS)
|
|||||||
state.count = 0;
|
state.count = 0;
|
||||||
state.num = 0;
|
state.num = 0;
|
||||||
state.str = NULL;
|
state.str = NULL;
|
||||||
|
state.escontext = escontext;
|
||||||
|
|
||||||
/* make polish notation (postfix, but in reverse order) */
|
/* make polish notation (postfix, but in reverse order) */
|
||||||
makepol(&state);
|
if (makepol(&state) == ERR)
|
||||||
|
PG_RETURN_NULL();
|
||||||
if (!state.num)
|
if (!state.num)
|
||||||
ereport(ERROR,
|
ereturn(escontext, (Datum) 0,
|
||||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
errmsg("empty query")));
|
errmsg("empty query")));
|
||||||
|
|
||||||
if (state.num > QUERYTYPEMAXITEMS)
|
if (state.num > QUERYTYPEMAXITEMS)
|
||||||
ereport(ERROR,
|
ereturn(escontext, (Datum) 0,
|
||||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||||
errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
|
errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
|
||||||
state.num, (int) QUERYTYPEMAXITEMS)));
|
state.num, (int) QUERYTYPEMAXITEMS)));
|
||||||
|
@ -398,6 +398,21 @@ SELECT '1&(2&(4&(5|!6)))'::query_int;
|
|||||||
1 & 2 & 4 & ( 5 | !6 )
|
1 & 2 & 4 & ( 5 | !6 )
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- test non-error-throwing input
|
||||||
|
SELECT str as "query_int",
|
||||||
|
pg_input_is_valid(str,'query_int') as ok,
|
||||||
|
pg_input_error_message(str,'query_int') as errmsg
|
||||||
|
FROM (VALUES ('1&(2&(4&(5|6)))'),
|
||||||
|
('1#(2&(4&(5&6)))'),
|
||||||
|
('foo'))
|
||||||
|
AS a(str);
|
||||||
|
query_int | ok | errmsg
|
||||||
|
-----------------+----+--------------
|
||||||
|
1&(2&(4&(5|6))) | t |
|
||||||
|
1#(2&(4&(5&6))) | f | syntax error
|
||||||
|
foo | f | syntax error
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
CREATE TABLE test__int( a int[] );
|
CREATE TABLE test__int( a int[] );
|
||||||
\copy test__int from 'data/test__int.data'
|
\copy test__int from 'data/test__int.data'
|
||||||
ANALYZE test__int;
|
ANALYZE test__int;
|
||||||
|
@ -75,6 +75,17 @@ SELECT '1&2&4&5&6'::query_int;
|
|||||||
SELECT '1&(2&(4&(5|6)))'::query_int;
|
SELECT '1&(2&(4&(5|6)))'::query_int;
|
||||||
SELECT '1&(2&(4&(5|!6)))'::query_int;
|
SELECT '1&(2&(4&(5|!6)))'::query_int;
|
||||||
|
|
||||||
|
-- test non-error-throwing input
|
||||||
|
|
||||||
|
SELECT str as "query_int",
|
||||||
|
pg_input_is_valid(str,'query_int') as ok,
|
||||||
|
pg_input_error_message(str,'query_int') as errmsg
|
||||||
|
FROM (VALUES ('1&(2&(4&(5|6)))'),
|
||||||
|
('1#(2&(4&(5&6)))'),
|
||||||
|
('foo'))
|
||||||
|
AS a(str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE test__int( a int[] );
|
CREATE TABLE test__int( a int[] );
|
||||||
\copy test__int from 'data/test__int.data'
|
\copy test__int from 'data/test__int.data'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user