Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b76622

Browse files
committed
Convert contrib/intarray's bqarr_in() to report errors softly
Reviewed by Tom Lane and Amul SulDiscussion:https://postgr.es/m/49e598c2-cfe8-0928-b6fb-d0cc51aab626@dunslane.net
1 parent24b55cd commit3b76622

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

‎contrib/intarray/_int_bool.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef struct
3535
char*buf;
3636
int32state;
3737
int32count;
38+
structNode*escontext;
3839
/* reverse polish notation in list (for temporary usage) */
3940
NODE*str;
4041
/* number in str */
@@ -179,7 +180,7 @@ makepol(WORKSTATE *state)
179180
else
180181
{
181182
if (lenstack==STACKDEPTH)
182-
ereport(ERROR,
183+
ereturn(state->escontext,ERR,
183184
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
184185
errmsg("statement too complex")));
185186
stack[lenstack]=val;
@@ -206,10 +207,9 @@ makepol(WORKSTATE *state)
206207
break;
207208
caseERR:
208209
default:
209-
ereport(ERROR,
210+
ereturn(state->escontext,ERR,
210211
(errcode(ERRCODE_SYNTAX_ERROR),
211212
errmsg("syntax error")));
212-
returnERR;
213213
}
214214
}
215215

@@ -483,6 +483,7 @@ bqarr_in(PG_FUNCTION_ARGS)
483483
ITEM*ptr;
484484
NODE*tmp;
485485
int32pos=0;
486+
structNode*escontext=fcinfo->context;
486487

487488
#ifdefBS_DEBUG
488489
StringInfoDatapbuf;
@@ -493,16 +494,18 @@ bqarr_in(PG_FUNCTION_ARGS)
493494
state.count=0;
494495
state.num=0;
495496
state.str=NULL;
497+
state.escontext=escontext;
496498

497499
/* make polish notation (postfix, but in reverse order) */
498-
makepol(&state);
500+
if (makepol(&state)==ERR)
501+
PG_RETURN_NULL();
499502
if (!state.num)
500-
ereport(ERROR,
503+
ereturn(escontext, (Datum)0,
501504
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
502505
errmsg("empty query")));
503506

504507
if (state.num>QUERYTYPEMAXITEMS)
505-
ereport(ERROR,
508+
ereturn(escontext, (Datum)0,
506509
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
507510
errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
508511
state.num, (int)QUERYTYPEMAXITEMS)));

‎contrib/intarray/expected/_int.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ SELECT '1&(2&(4&(5|!6)))'::query_int;
398398
1 & 2 & 4 & ( 5 | !6 )
399399
(1 row)
400400

401+
-- test non-error-throwing input
402+
SELECT str as "query_int",
403+
pg_input_is_valid(str,'query_int') as ok,
404+
pg_input_error_message(str,'query_int') as errmsg
405+
FROM (VALUES ('1&(2&(4&(5|6)))'),
406+
('1#(2&(4&(5&6)))'),
407+
('foo'))
408+
AS a(str);
409+
query_int | ok | errmsg
410+
-----------------+----+--------------
411+
1&(2&(4&(5|6))) | t |
412+
1#(2&(4&(5&6))) | f | syntax error
413+
foo | f | syntax error
414+
(3 rows)
415+
401416
CREATE TABLE test__int( a int[] );
402417
\copy test__int from 'data/test__int.data'
403418
ANALYZE test__int;

‎contrib/intarray/sql/_int.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ SELECT '1&2&4&5&6'::query_int;
7575
SELECT'1&(2&(4&(5|6)))'::query_int;
7676
SELECT'1&(2&(4&(5|!6)))'::query_int;
7777

78+
-- test non-error-throwing input
79+
80+
SELECT stras"query_int",
81+
pg_input_is_valid(str,'query_int')as ok,
82+
pg_input_error_message(str,'query_int')as errmsg
83+
FROM (VALUES ('1&(2&(4&(5|6)))'),
84+
('1#(2&(4&(5&6)))'),
85+
('foo'))
86+
AS a(str);
87+
88+
7889

7990
CREATETABLEtest__int( aint[] );
8091
\copy test__intfrom'data/test__int.data'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp