@@ -17,12 +17,6 @@ PG_FUNCTION_INFO_V1(lquery_in);
17
17
PG_FUNCTION_INFO_V1 (lquery_out );
18
18
19
19
20
- #define UNCHAR ereport(ERROR, \
21
- (errcode(ERRCODE_SYNTAX_ERROR), \
22
- errmsg("syntax error at position %d", \
23
- pos)));
24
-
25
-
26
20
typedef struct
27
21
{
28
22
char * start ;
@@ -47,7 +41,12 @@ ltree_in(PG_FUNCTION_ARGS)
47
41
ltree * result ;
48
42
ltree_level * curlevel ;
49
43
int charlen ;
50
- int pos = 0 ;
44
+ int pos = 1 ; /* character position for error messages */
45
+
46
+ #define UNCHAR ereport(ERROR, \
47
+ errcode(ERRCODE_SYNTAX_ERROR), \
48
+ errmsg("ltree syntax error at character %d", \
49
+ pos))
51
50
52
51
ptr = buf ;
53
52
while (* ptr )
@@ -61,7 +60,7 @@ ltree_in(PG_FUNCTION_ARGS)
61
60
if (num + 1 > LTREE_MAX_LEVELS )
62
61
ereport (ERROR ,
63
62
(errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
64
- errmsg ("number of ltree levels (%d) exceeds the maximum allowed (%d)" ,
63
+ errmsg ("number of ltree labels (%d) exceeds the maximum allowed (%d)" ,
65
64
num + 1 , LTREE_MAX_LEVELS )));
66
65
list = lptr = (nodeitem * ) palloc (sizeof (nodeitem ) * (num + 1 ));
67
66
ptr = buf ;
@@ -88,10 +87,10 @@ ltree_in(PG_FUNCTION_ARGS)
88
87
if (lptr -> wlen > LTREE_LABEL_MAX_CHARS )
89
88
ereport (ERROR ,
90
89
(errcode (ERRCODE_NAME_TOO_LONG ),
91
- errmsg ("name of level is too long" ),
92
- errdetail ("Name length is %d, must "
93
- "be < 256, in position %d." ,
94
- lptr -> wlen , pos )));
90
+ errmsg ("label string is too long" ),
91
+ errdetail ("Label length is %d, must be at most %d, at character %d." ,
92
+ lptr -> wlen , LTREE_LABEL_MAX_CHARS ,
93
+ pos )));
95
94
96
95
totallen += MAXALIGN (lptr -> len + LEVEL_HDRSIZE );
97
96
lptr ++ ;
@@ -115,19 +114,18 @@ ltree_in(PG_FUNCTION_ARGS)
115
114
if (lptr -> wlen > LTREE_LABEL_MAX_CHARS )
116
115
ereport (ERROR ,
117
116
(errcode (ERRCODE_NAME_TOO_LONG ),
118
- errmsg ("name of level is too long" ),
119
- errdetail ("Name length is %d, must "
120
- "be < 256, in position %d." ,
121
- lptr -> wlen , pos )));
117
+ errmsg ("label string is too long" ),
118
+ errdetail ("Label length is %d, must be at most %d, at character %d." ,
119
+ lptr -> wlen , LTREE_LABEL_MAX_CHARS , pos )));
122
120
123
121
totallen += MAXALIGN (lptr -> len + LEVEL_HDRSIZE );
124
122
lptr ++ ;
125
123
}
126
124
else if (!(state == LTPRS_WAITNAME && lptr == list ))
127
125
ereport (ERROR ,
128
126
(errcode (ERRCODE_SYNTAX_ERROR ),
129
- errmsg ("syntax error" ),
130
- errdetail ("Unexpected end of line ." )));
127
+ errmsg ("ltree syntax error" ),
128
+ errdetail ("Unexpected end of input ." )));
131
129
132
130
result = (ltree * ) palloc0 (LTREE_HDRSIZE + totallen );
133
131
SET_VARSIZE (result , LTREE_HDRSIZE + totallen );
@@ -144,6 +142,8 @@ ltree_in(PG_FUNCTION_ARGS)
144
142
145
143
pfree (list );
146
144
PG_RETURN_POINTER (result );
145
+
146
+ #undef UNCHAR
147
147
}
148
148
149
149
Datum
@@ -208,7 +208,12 @@ lquery_in(PG_FUNCTION_ARGS)
208
208
bool hasnot = false;
209
209
bool wasbad = false;
210
210
int charlen ;
211
- int pos = 0 ;
211
+ int pos = 1 ; /* character position for error messages */
212
+
213
+ #define UNCHAR ereport(ERROR, \
214
+ errcode(ERRCODE_SYNTAX_ERROR), \
215
+ errmsg("lquery syntax error at character %d", \
216
+ pos))
212
217
213
218
ptr = buf ;
214
219
while (* ptr )
@@ -230,7 +235,7 @@ lquery_in(PG_FUNCTION_ARGS)
230
235
if (num > LQUERY_MAX_LEVELS )
231
236
ereport (ERROR ,
232
237
(errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
233
- errmsg ("number of lquery levels (%d) exceeds the maximum allowed (%d)" ,
238
+ errmsg ("number of lquery items (%d) exceeds the maximum allowed (%d)" ,
234
239
num , LQUERY_MAX_LEVELS )));
235
240
curqlevel = tmpql = (lquery_level * ) palloc0 (ITEMSIZE * num );
236
241
ptr = buf ;
@@ -305,10 +310,10 @@ lquery_in(PG_FUNCTION_ARGS)
305
310
if (lptr -> wlen > LTREE_LABEL_MAX_CHARS )
306
311
ereport (ERROR ,
307
312
(errcode (ERRCODE_NAME_TOO_LONG ),
308
- errmsg ("name of level is too long" ),
309
- errdetail ("Name length is %d, must "
310
- "be < 256, in position %d." ,
311
- lptr -> wlen , pos )));
313
+ errmsg ("label string is too long" ),
314
+ errdetail ("Label length is %d, must be at most %d, at character %d." ,
315
+ lptr -> wlen , LTREE_LABEL_MAX_CHARS ,
316
+ pos )));
312
317
313
318
state = LQPRS_WAITVAR ;
314
319
}
@@ -321,10 +326,10 @@ lquery_in(PG_FUNCTION_ARGS)
321
326
if (lptr -> wlen > LTREE_LABEL_MAX_CHARS )
322
327
ereport (ERROR ,
323
328
(errcode (ERRCODE_NAME_TOO_LONG ),
324
- errmsg ("name of level is too long" ),
325
- errdetail ("Name length is %d, must "
326
- "be < 256, in position %d." ,
327
- lptr -> wlen , pos )));
329
+ errmsg ("label string is too long" ),
330
+ errdetail ("Label length is %d, must be at most %d, at character %d." ,
331
+ lptr -> wlen , LTREE_LABEL_MAX_CHARS ,
332
+ pos )));
328
333
329
334
state = LQPRS_WAITLEVEL ;
330
335
curqlevel = NEXTLEV (curqlevel );
@@ -361,10 +366,10 @@ lquery_in(PG_FUNCTION_ARGS)
361
366
362
367
if (low < 0 || low > LTREE_MAX_LEVELS )
363
368
ereport (ERROR ,
364
- (errcode (ERRCODE_SYNTAX_ERROR ),
369
+ (errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
365
370
errmsg ("lquery syntax error" ),
366
- errdetail ("Low limit (%d) exceeds the maximum allowed (%d)." ,
367
- low , LTREE_MAX_LEVELS )));
371
+ errdetail ("Low limit (%d) exceeds the maximum allowed (%d), at character %d ." ,
372
+ low , LTREE_MAX_LEVELS , pos )));
368
373
369
374
curqlevel -> low = (uint16 ) low ;
370
375
state = LQPRS_WAITND ;
@@ -379,11 +384,17 @@ lquery_in(PG_FUNCTION_ARGS)
379
384
int high = atoi (ptr );
380
385
381
386
if (high < 0 || high > LTREE_MAX_LEVELS )
387
+ ereport (ERROR ,
388
+ (errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
389
+ errmsg ("lquery syntax error" ),
390
+ errdetail ("High limit (%d) exceeds the maximum allowed (%d), at character %d." ,
391
+ high , LTREE_MAX_LEVELS , pos )));
392
+ else if (curqlevel -> low > high )
382
393
ereport (ERROR ,
383
394
(errcode (ERRCODE_SYNTAX_ERROR ),
384
395
errmsg ("lquery syntax error" ),
385
- errdetail ("High limit (%d) exceeds the maximum allowed (%d)." ,
386
- high , LTREE_MAX_LEVELS )));
396
+ errdetail ("Low limit (%d) is greater than high limit (%d), at character %d ." ,
397
+ curqlevel -> low , high , pos )));
387
398
388
399
curqlevel -> high = (uint16 ) high ;
389
400
state = LQPRS_WAITCLOSE ;
@@ -441,7 +452,7 @@ lquery_in(PG_FUNCTION_ARGS)
441
452
ereport (ERROR ,
442
453
(errcode (ERRCODE_SYNTAX_ERROR ),
443
454
errmsg ("lquery syntax error" ),
444
- errdetail ("Unexpected end of line ." )));
455
+ errdetail ("Unexpected end of input ." )));
445
456
446
457
lptr -> len = ptr - lptr -> start -
447
458
((lptr -> flag & LVAR_SUBLEXEME ) ? 1 : 0 ) -
@@ -451,23 +462,22 @@ lquery_in(PG_FUNCTION_ARGS)
451
462
ereport (ERROR ,
452
463
(errcode (ERRCODE_SYNTAX_ERROR ),
453
464
errmsg ("lquery syntax error" ),
454
- errdetail ("Unexpected end of line ." )));
465
+ errdetail ("Unexpected end of input ." )));
455
466
456
467
if (lptr -> wlen > LTREE_LABEL_MAX_CHARS )
457
468
ereport (ERROR ,
458
469
(errcode (ERRCODE_NAME_TOO_LONG ),
459
- errmsg ("name of level is too long" ),
460
- errdetail ("Name length is %d, must "
461
- "be < 256, in position %d." ,
462
- lptr -> wlen , pos )));
470
+ errmsg ("label string is too long" ),
471
+ errdetail ("Label length is %d, must be at most %d, at character %d." ,
472
+ lptr -> wlen , LTREE_LABEL_MAX_CHARS , pos )));
463
473
}
464
474
else if (state == LQPRS_WAITOPEN )
465
475
curqlevel -> high = LTREE_MAX_LEVELS ;
466
476
else if (state != LQPRS_WAITEND )
467
477
ereport (ERROR ,
468
478
(errcode (ERRCODE_SYNTAX_ERROR ),
469
479
errmsg ("lquery syntax error" ),
470
- errdetail ("Unexpected end of line ." )));
480
+ errdetail ("Unexpected end of input ." )));
471
481
472
482
curqlevel = tmpql ;
473
483
totallen = LQUERY_HDRSIZE ;
@@ -483,13 +493,6 @@ lquery_in(PG_FUNCTION_ARGS)
483
493
lptr ++ ;
484
494
}
485
495
}
486
- else if (curqlevel -> low > curqlevel -> high )
487
- ereport (ERROR ,
488
- (errcode (ERRCODE_SYNTAX_ERROR ),
489
- errmsg ("lquery syntax error" ),
490
- errdetail ("Low limit (%d) is greater than upper (%d)." ,
491
- curqlevel -> low , curqlevel -> high )));
492
-
493
496
curqlevel = NEXTLEV (curqlevel );
494
497
}
495
498
@@ -543,6 +546,8 @@ lquery_in(PG_FUNCTION_ARGS)
543
546
544
547
pfree (tmpql );
545
548
PG_RETURN_POINTER (result );
549
+
550
+ #undef UNCHAR
546
551
}
547
552
548
553
Datum
0 commit comments