24 #define LTPRS_WAITNAME 0
25 #define LTPRS_WAITDELIM 1
28 bool is_lquery,
int pos,
struct Node *escontext);
49 #define UNCHAR ereturn(escontext, NULL,\
50 errcode(ERRCODE_SYNTAX_ERROR), \
51 errmsg("ltree syntax error at character %d", \
65 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
66 errmsg(
"number of ltree labels (%d) exceeds the maximum allowed (%d)",
99 elog(
ERROR,
"internal error in ltree parser");
116 (
errcode(ERRCODE_SYNTAX_ERROR),
117 errmsg(
"ltree syntax error"),
125 while (lptr - list < result->numlevel)
160 memcpy(ptr, curlevel->
name, curlevel->
len);
161 ptr += curlevel->
len;
238 elog(
ERROR,
"unsupported ltree version number %d", version);
248 #define LQPRS_WAITLEVEL 0
249 #define LQPRS_WAITDELIM 1
250 #define LQPRS_WAITOPEN 2
251 #define LQPRS_WAITFNUM 3
252 #define LQPRS_WAITSNUM 4
253 #define LQPRS_WAITND 5
254 #define LQPRS_WAITCLOSE 6
255 #define LQPRS_WAITEND 7
256 #define LQPRS_WAITVAR 8
259 #define GETVAR(x) ( *((nodeitem**)LQL_FIRST(x)) )
260 #define ITEMSIZE MAXALIGN(LQL_HDRSIZE+sizeof(nodeitem*))
261 #define NEXTLEV(x) ( (lquery_level*)( ((char*)(x)) + ITEMSIZE) )
286 #define UNCHAR ereturn(escontext, NULL,\
287 errcode(ERRCODE_SYNTAX_ERROR), \
288 errmsg("lquery syntax error at character %d", \
298 else if (
t_iseq(ptr,
'|'))
307 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
308 errmsg(
"number of lquery items (%d) exceeds the maximum allowed (%d)",
326 else if (
t_iseq(ptr,
'!'))
329 lptr->
start = ptr + 1;
336 else if (
t_iseq(ptr,
'*'))
358 else if (
t_iseq(ptr,
'*'))
363 else if (
t_iseq(ptr,
'%'))
368 else if (
t_iseq(ptr,
'|'))
374 else if (
t_iseq(ptr,
'{'))
381 else if (
t_iseq(ptr,
'.'))
386 curqlevel =
NEXTLEV(curqlevel);
400 else if (
t_iseq(ptr,
'.'))
405 curqlevel =
NEXTLEV(curqlevel);
420 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
421 errmsg(
"lquery syntax error"),
422 errdetail(
"Low limit (%d) exceeds the maximum allowed (%d), at character %d.",
434 int high = atoi(ptr);
438 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
439 errmsg(
"lquery syntax error"),
440 errdetail(
"High limit (%d) exceeds the maximum allowed (%d), at character %d.",
442 else if (curqlevel->
low > high)
444 (
errcode(ERRCODE_SYNTAX_ERROR),
445 errmsg(
"lquery syntax error"),
446 errdetail(
"Low limit (%d) is greater than high limit (%d), at character %d.",
447 curqlevel->
low, high, pos)));
452 else if (
t_iseq(ptr,
'}'))
469 curqlevel->
high = curqlevel->
low;
472 else if (
t_iseq(ptr,
','))
481 curqlevel =
NEXTLEV(curqlevel);
487 elog(
ERROR,
"internal error in lquery parser");
505 (
errcode(ERRCODE_SYNTAX_ERROR),
506 errmsg(
"lquery syntax error"),
511 while ((
char *) curqlevel - (
char *) tmpql < num *
ITEMSIZE)
523 curqlevel =
NEXTLEV(curqlevel);
535 while ((
char *) curqlevel - (
char *) tmpql < num *
ITEMSIZE)
554 if (
cur->numvar > 1 ||
cur->flag != 0)
559 else if (wasbad ==
false)
570 curqlevel =
NEXTLEV(curqlevel);
586 struct Node *escontext)
594 while (ptr > lptr->
start && strchr(
"@*%", ptr[-1]) != NULL)
608 (
errcode(ERRCODE_SYNTAX_ERROR),
610 errmsg(
"lquery syntax error at character %d", pos) :
611 errmsg(
"ltree syntax error at character %d", pos),
612 errdetail(
"Empty labels are not allowed.")));
615 (
errcode(ERRCODE_NAME_TOO_LONG),
616 errmsg(
"label string is too long"),
617 errdetail(
"Label length is %d, must be at most %d, at character %d.",
645 totallen += 2 * 11 + 3;
648 totallen += 2 * 11 + 4;
676 memcpy(ptr, curtlevel->
name, curtlevel->
len);
677 ptr += curtlevel->
len;
704 if (curqlevel->
low == curqlevel->
high)
708 else if (curqlevel->
low == 0)
712 if (curqlevel->
numvar == 0)
729 ptr = strchr(ptr,
'\0');
808 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)