25 #define LTPRS_WAITNAME 0
26 #define LTPRS_WAITDELIM 1
29 bool is_lquery,
int pos,
struct Node *escontext);
50 #define UNCHAR ereturn(escontext, NULL,\
51 errcode(ERRCODE_SYNTAX_ERROR), \
52 errmsg("ltree syntax error at character %d", \
66 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
67 errmsg(
"number of ltree labels (%d) exceeds the maximum allowed (%d)",
100 elog(
ERROR,
"internal error in ltree parser");
117 (
errcode(ERRCODE_SYNTAX_ERROR),
118 errmsg(
"ltree syntax error"),
126 while (lptr - list < result->numlevel)
161 memcpy(ptr, curlevel->
name, curlevel->
len);
162 ptr += curlevel->
len;
239 elog(
ERROR,
"unsupported ltree version number %d", version);
249 #define LQPRS_WAITLEVEL 0
250 #define LQPRS_WAITDELIM 1
251 #define LQPRS_WAITOPEN 2
252 #define LQPRS_WAITFNUM 3
253 #define LQPRS_WAITSNUM 4
254 #define LQPRS_WAITND 5
255 #define LQPRS_WAITCLOSE 6
256 #define LQPRS_WAITEND 7
257 #define LQPRS_WAITVAR 8
260 #define GETVAR(x) ( *((nodeitem**)LQL_FIRST(x)) )
261 #define ITEMSIZE MAXALIGN(LQL_HDRSIZE+sizeof(nodeitem*))
262 #define NEXTLEV(x) ( (lquery_level*)( ((char*)(x)) + ITEMSIZE) )
287 #define UNCHAR ereturn(escontext, NULL,\
288 errcode(ERRCODE_SYNTAX_ERROR), \
289 errmsg("lquery syntax error at character %d", \
299 else if (
t_iseq(ptr,
'|'))
308 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
309 errmsg(
"number of lquery items (%d) exceeds the maximum allowed (%d)",
327 else if (
t_iseq(ptr,
'!'))
330 lptr->
start = ptr + 1;
337 else if (
t_iseq(ptr,
'*'))
359 else if (
t_iseq(ptr,
'*'))
364 else if (
t_iseq(ptr,
'%'))
369 else if (
t_iseq(ptr,
'|'))
375 else if (
t_iseq(ptr,
'{'))
382 else if (
t_iseq(ptr,
'.'))
387 curqlevel =
NEXTLEV(curqlevel);
401 else if (
t_iseq(ptr,
'.'))
406 curqlevel =
NEXTLEV(curqlevel);
421 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
422 errmsg(
"lquery syntax error"),
423 errdetail(
"Low limit (%d) exceeds the maximum allowed (%d), at character %d.",
435 int high = atoi(ptr);
439 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
440 errmsg(
"lquery syntax error"),
441 errdetail(
"High limit (%d) exceeds the maximum allowed (%d), at character %d.",
443 else if (curqlevel->
low > high)
445 (
errcode(ERRCODE_SYNTAX_ERROR),
446 errmsg(
"lquery syntax error"),
447 errdetail(
"Low limit (%d) is greater than high limit (%d), at character %d.",
448 curqlevel->
low, high, pos)));
453 else if (
t_iseq(ptr,
'}'))
470 curqlevel->
high = curqlevel->
low;
473 else if (
t_iseq(ptr,
','))
482 curqlevel =
NEXTLEV(curqlevel);
488 elog(
ERROR,
"internal error in lquery parser");
506 (
errcode(ERRCODE_SYNTAX_ERROR),
507 errmsg(
"lquery syntax error"),
512 while ((
char *) curqlevel - (
char *) tmpql < num *
ITEMSIZE)
524 curqlevel =
NEXTLEV(curqlevel);
536 while ((
char *) curqlevel - (
char *) tmpql < num *
ITEMSIZE)
555 if (
cur->numvar > 1 ||
cur->flag != 0)
560 else if (wasbad ==
false)
571 curqlevel =
NEXTLEV(curqlevel);
587 struct Node *escontext)
595 while (ptr > lptr->
start && strchr(
"@*%", ptr[-1]) != NULL)
609 (
errcode(ERRCODE_SYNTAX_ERROR),
611 errmsg(
"lquery syntax error at character %d", pos) :
612 errmsg(
"ltree syntax error at character %d", pos),
613 errdetail(
"Empty labels are not allowed.")));
616 (
errcode(ERRCODE_NAME_TOO_LONG),
617 errmsg(
"label string is too long"),
618 errdetail(
"Label length is %d, must be at most %d, at character %d.",
646 totallen += 2 * 11 + 3;
649 totallen += 2 * 11 + 4;
677 memcpy(ptr, curtlevel->
name, curtlevel->
len);
678 ptr += curtlevel->
len;
705 if (curqlevel->
low == curqlevel->
high)
709 else if (curqlevel->
low == 0)
713 if (curqlevel->
numvar == 0)
730 ptr = strchr(ptr,
'\0');
809 elog(
ERROR,
"unsupported lquery version number %d", version);
unsigned int ltree_crc32_sz(const char *buf, int size)
static void PGresult * res
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_POINTER(x)
if(TABLE==NULL||TABLE_index==NULL)
#define PG_GETARG_LQUERY_P(n)
#define LQUERY_MAX_LEVELS
#define LTREE_LABEL_MAX_CHARS
#define PG_GETARG_LTREE_P(n)
static char * deparse_ltree(const ltree *in)
Datum ltree_recv(PG_FUNCTION_ARGS)
Datum lquery_out(PG_FUNCTION_ARGS)
static lquery * parse_lquery(const char *buf, struct Node *escontext)
Datum lquery_in(PG_FUNCTION_ARGS)
Datum ltree_in(PG_FUNCTION_ARGS)
static char * deparse_lquery(const lquery *in)
PG_FUNCTION_INFO_V1(ltree_in)
Datum ltree_send(PG_FUNCTION_ARGS)
Datum lquery_send(PG_FUNCTION_ARGS)
static ltree * parse_ltree(const char *buf, struct Node *escontext)
static bool finish_nodeitem(nodeitem *lptr, const char *ptr, bool is_lquery, int pos, struct Node *escontext)
Datum lquery_recv(PG_FUNCTION_ARGS)
Datum ltree_out(PG_FUNCTION_ARGS)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
void * palloc0(Size size)
StringInfoData * StringInfo
char name[FLEXIBLE_ARRAY_MEMBER]
char name[FLEXIBLE_ARRAY_MEMBER]
int t_isdigit(const char *ptr)
#define SET_VARSIZE(PTR, len)