20 #define UNCHAR ereport(ERROR, \ 21 (errcode(ERRCODE_SYNTAX_ERROR), \ 22 errmsg("syntax error at position %d", \ 34 #define LTPRS_WAITNAME 0 35 #define LTPRS_WAITDELIM 1 56 if (charlen == 1 &&
t_iseq(ptr,
'.'))
63 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
64 errmsg(
"number of levels (%d) exceeds the maximum allowed (%d)",
85 if (charlen == 1 &&
t_iseq(ptr,
'.'))
90 (
errcode(ERRCODE_NAME_TOO_LONG),
91 errmsg(
"name of level is too long"),
93 "be < 256, in position %d.",
115 if (lptr->
wlen > 255)
117 (
errcode(ERRCODE_NAME_TOO_LONG),
118 errmsg(
"name of level is too long"),
120 "be < 256, in position %d.",
128 (
errcode(ERRCODE_SYNTAX_ERROR),
137 while (lptr - list < result->numlevel)
167 memcpy(ptr, curlevel->
name, curlevel->
len);
168 ptr += curlevel->
len;
178 #define LQPRS_WAITLEVEL 0 179 #define LQPRS_WAITDELIM 1 180 #define LQPRS_WAITOPEN 2 181 #define LQPRS_WAITFNUM 3 182 #define LQPRS_WAITSNUM 4 183 #define LQPRS_WAITND 5 184 #define LQPRS_WAITCLOSE 6 185 #define LQPRS_WAITEND 7 186 #define LQPRS_WAITVAR 8 189 #define GETVAR(x) ( *((nodeitem**)LQL_FIRST(x)) ) 190 #define ITEMSIZE MAXALIGN(LQL_HDRSIZE+sizeof(nodeitem*)) 191 #define NEXTLEV(x) ( (lquery_level*)( ((char*)(x)) + ITEMSIZE) ) 222 else if (
t_iseq(ptr,
'|'))
232 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
233 errmsg(
"number of levels (%d) exceeds the maximum allowed (%d)",
250 else if (charlen == 1 &&
t_iseq(ptr,
'!'))
253 lptr->
start = ptr + 1;
259 else if (charlen == 1 &&
t_iseq(ptr,
'*'))
278 if (charlen == 1 &&
t_iseq(ptr,
'@'))
280 if (lptr->
start == ptr)
285 else if (charlen == 1 &&
t_iseq(ptr,
'*'))
287 if (lptr->
start == ptr)
292 else if (charlen == 1 &&
t_iseq(ptr,
'%'))
294 if (lptr->
start == ptr)
299 else if (charlen == 1 &&
t_iseq(ptr,
'|'))
305 if (lptr->
wlen > 255)
307 (
errcode(ERRCODE_NAME_TOO_LONG),
308 errmsg(
"name of level is too long"),
310 "be < 256, in position %d.",
315 else if (charlen == 1 &&
t_iseq(ptr,
'.'))
321 if (lptr->
wlen > 255)
323 (
errcode(ERRCODE_NAME_TOO_LONG),
324 errmsg(
"name of level is too long"),
326 "be < 256, in position %d.",
330 curqlevel =
NEXTLEV(curqlevel);
342 if (charlen == 1 &&
t_iseq(ptr,
'{'))
344 else if (charlen == 1 &&
t_iseq(ptr,
'.'))
347 curqlevel->
high = 0xffff;
348 curqlevel =
NEXTLEV(curqlevel);
356 if (charlen == 1 &&
t_iseq(ptr,
','))
360 curqlevel->
low = atoi(ptr);
370 curqlevel->
high = atoi(ptr);
373 else if (charlen == 1 &&
t_iseq(ptr,
'}'))
375 curqlevel->
high = 0xffff;
383 if (charlen == 1 &&
t_iseq(ptr,
'}'))
390 if (charlen == 1 &&
t_iseq(ptr,
'}'))
392 curqlevel->
high = curqlevel->
low;
395 else if (charlen == 1 &&
t_iseq(ptr,
','))
402 if (charlen == 1 &&
t_iseq(ptr,
'.'))
405 curqlevel =
NEXTLEV(curqlevel);
422 if (lptr->
start == ptr)
424 (
errcode(ERRCODE_SYNTAX_ERROR),
434 (
errcode(ERRCODE_SYNTAX_ERROR),
438 if (lptr->
wlen > 255)
440 (
errcode(ERRCODE_NAME_TOO_LONG),
441 errmsg(
"name of level is too long"),
443 "be < 256, in position %d.",
447 curqlevel->
high = 0xffff;
450 (
errcode(ERRCODE_SYNTAX_ERROR),
456 while ((
char *) curqlevel - (
char *) tmpql < num *
ITEMSIZE)
468 else if (curqlevel->
low > curqlevel->
high)
470 (
errcode(ERRCODE_SYNTAX_ERROR),
472 errdetail(
"Low limit(%d) is greater than upper(%d).",
473 curqlevel->
low, curqlevel->
high)));
475 curqlevel =
NEXTLEV(curqlevel);
487 while ((
char *) curqlevel - (
char *) tmpql < num * ITEMSIZE)
508 else if (wasbad ==
false)
513 curqlevel =
NEXTLEV(curqlevel);
540 totallen += 2 * 11 + 4;
544 ptr = buf = (
char *)
palloc(totallen);
561 for (j = 0; j < curqlevel->
numvar; j++)
568 memcpy(ptr, curtlevel->
name, curtlevel->
len);
569 ptr += curtlevel->
len;
590 if (curqlevel->
low == curqlevel->
high)
594 else if (curqlevel->
low == 0)
596 if (curqlevel->
high == 0xffff)
604 else if (curqlevel->
high == 0xffff)
610 ptr = strchr(ptr,
'\0');
#define PG_RETURN_POINTER(x)
char name[FLEXIBLE_ARRAY_MEMBER]
Datum ltree_in(PG_FUNCTION_ARGS)
char name[FLEXIBLE_ARRAY_MEMBER]
PG_FUNCTION_INFO_V1(ltree_in)
int errcode(int sqlerrcode)
#define PG_GETARG_LTREE_P(n)
#define PG_GETARG_POINTER(n)
unsigned int ltree_crc32_sz(char *buf, int size)
#define PG_GETARG_LQUERY_P(n)
int t_isdigit(const char *ptr)
void pfree(void *pointer)
Datum ltree_out(PG_FUNCTION_ARGS)
int errdetail(const char *fmt,...)
Datum lquery_out(PG_FUNCTION_ARGS)
#define ereport(elevel, rest)
void * palloc0(Size size)
#define PG_FREE_IF_COPY(ptr, n)
int pg_mblen(const char *mbstr)
Datum lquery_in(PG_FUNCTION_ARGS)
int errmsg(const char *fmt,...)
#define SET_VARSIZE(PTR, len)