Commit 4690f2fc authored by osku's avatar osku

Add support for bound ids in InnoDB's SQL parser.

parent 73330226
...@@ -531,6 +531,16 @@ pars_info_add_function( ...@@ -531,6 +531,16 @@ pars_info_add_function(
pars_user_func_cb_t func, /* in: function address */ pars_user_func_cb_t func, /* in: function address */
void* arg); /* in: user-supplied argument */ void* arg); /* in: user-supplied argument */
/********************************************************************
Add bound id. */
void
pars_info_add_id(
/*=============*/
pars_info_t* info, /* in: info struct */
const char* name, /* in: name */
const char* id); /* in: id */
/******************************************************************** /********************************************************************
Get user function with the given name.*/ Get user function with the given name.*/
...@@ -553,6 +563,17 @@ pars_info_get_bound_lit( ...@@ -553,6 +563,17 @@ pars_info_get_bound_lit(
pars_info_t* info, /* in: info struct */ pars_info_t* info, /* in: info struct */
const char* name); /* in: bound literal name to find */ const char* name); /* in: bound literal name to find */
/********************************************************************
Get bound id with the given name.*/
pars_bound_id_t*
pars_info_get_bound_id(
/*===================*/
/* out: bound id, or NULL if not
found */
pars_info_t* info, /* in: info struct */
const char* name); /* in: bound id name to find */
/* Extra information supplied for pars_sql(). */ /* Extra information supplied for pars_sql(). */
struct pars_info_struct { struct pars_info_struct {
...@@ -562,6 +583,8 @@ struct pars_info_struct { ...@@ -562,6 +583,8 @@ struct pars_info_struct {
(pars_user_func_t*) */ (pars_user_func_t*) */
ib_vector_t* bound_lits; /* bound literals, or NULL ib_vector_t* bound_lits; /* bound literals, or NULL
(pars_bound_lit_t*) */ (pars_bound_lit_t*) */
ib_vector_t* bound_ids; /* bound ids, or NULL
(pars_bound_id_t*) */
ibool graph_owns_us; /* if TRUE (which is the default), ibool graph_owns_us; /* if TRUE (which is the default),
que_graph_free() will free us */ que_graph_free() will free us */
...@@ -583,6 +606,12 @@ struct pars_bound_lit_struct { ...@@ -583,6 +606,12 @@ struct pars_bound_lit_struct {
ulint prtype; /* precise type, e.g. DATA_UNSIGNED */ ulint prtype; /* precise type, e.g. DATA_UNSIGNED */
}; };
/* Bound id. */
struct pars_bound_id_struct {
const char* name; /* name */
const char* id; /* id */
};
/* Struct used to denote a reserved word in a parsing tree */ /* Struct used to denote a reserved word in a parsing tree */
struct pars_res_word_struct{ struct pars_res_word_struct{
int code; /* the token code for the reserved word from int code; /* the token code for the reserved word from
......
...@@ -82,6 +82,16 @@ sym_tab_add_id( ...@@ -82,6 +82,16 @@ sym_tab_add_id(
byte* name, /* in: identifier name */ byte* name, /* in: identifier name */
ulint len); /* in: identifier length */ ulint len); /* in: identifier length */
/**********************************************************************
Add a bound identifier to a symbol table. */
sym_node_t*
sym_tab_add_bound_id(
/*===========*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name); /* in: name of bound id */
#define SYM_CLUST_FIELD_NO 0 #define SYM_CLUST_FIELD_NO 0
#define SYM_SEC_FIELD_NO 1 #define SYM_SEC_FIELD_NO 1
......
...@@ -12,6 +12,7 @@ Created 1/11/1998 Heikki Tuuri ...@@ -12,6 +12,7 @@ Created 1/11/1998 Heikki Tuuri
typedef struct pars_info_struct pars_info_t; typedef struct pars_info_struct pars_info_t;
typedef struct pars_user_func_struct pars_user_func_t; typedef struct pars_user_func_struct pars_user_func_t;
typedef struct pars_bound_lit_struct pars_bound_lit_t; typedef struct pars_bound_lit_struct pars_bound_lit_t;
typedef struct pars_bound_id_struct pars_bound_id_t;
typedef struct sym_node_struct sym_node_t; typedef struct sym_node_struct sym_node_t;
typedef struct sym_tab_struct sym_tab_t; typedef struct sym_tab_struct sym_tab_t;
typedef struct pars_res_word_struct pars_res_word_t; typedef struct pars_res_word_struct pars_res_word_t;
......
This diff is collapsed.
...@@ -84,6 +84,7 @@ string_append( ...@@ -84,6 +84,7 @@ string_append(
DIGIT [0-9] DIGIT [0-9]
ID [a-z_A-Z][a-z_A-Z0-9]* ID [a-z_A-Z][a-z_A-Z0-9]*
BOUND_LIT \:[a-z_A-Z0-9]+ BOUND_LIT \:[a-z_A-Z0-9]+
BOUND_ID \$[a-z_A-Z0-9]+
%x comment %x comment
%x quoted %x quoted
...@@ -111,6 +112,13 @@ BOUND_LIT \:[a-z_A-Z0-9]+ ...@@ -111,6 +112,13 @@ BOUND_LIT \:[a-z_A-Z0-9]+
return(type); return(type);
} }
{BOUND_ID} {
yylval = sym_tab_add_bound_id(pars_sym_tab_global,
yytext + 1);
return(PARS_ID_TOKEN);
}
"'" { "'" {
/* Quoted character string literals are handled in an explicit /* Quoted character string literals are handled in an explicit
start state 'quoted'. This state is entered and the buffer for start state 'quoted'. This state is entered and the buffer for
......
...@@ -1931,6 +1931,7 @@ pars_info_create(void) ...@@ -1931,6 +1931,7 @@ pars_info_create(void)
info->heap = heap; info->heap = heap;
info->funcs = NULL; info->funcs = NULL;
info->bound_lits = NULL; info->bound_lits = NULL;
info->bound_ids = NULL;
info->graph_owns_us = TRUE; info->graph_owns_us = TRUE;
return(info); return(info);
...@@ -2070,6 +2071,32 @@ pars_info_add_function( ...@@ -2070,6 +2071,32 @@ pars_info_add_function(
ib_vector_push(info->funcs, puf); ib_vector_push(info->funcs, puf);
} }
/********************************************************************
Add bound id. */
void
pars_info_add_id(
/*=============*/
pars_info_t* info, /* in: info struct */
const char* name, /* in: name */
const char* id) /* in: id */
{
pars_bound_id_t* bid;
ut_ad(!pars_info_get_bound_id(info, name));
bid = mem_heap_alloc(info->heap, sizeof(*bid));
bid->name = name;
bid->id = id;
if (!info->bound_ids) {
info->bound_ids = ib_vector_create(info->heap, 8);
}
ib_vector_push(info->bound_ids, bid);
}
/******************************************************************** /********************************************************************
Get user function with the given name.*/ Get user function with the given name.*/
...@@ -2131,3 +2158,34 @@ pars_info_get_bound_lit( ...@@ -2131,3 +2158,34 @@ pars_info_get_bound_lit(
return(NULL); return(NULL);
} }
/********************************************************************
Get bound id with the given name.*/
pars_bound_id_t*
pars_info_get_bound_id(
/*===================*/
/* out: bound id, or NULL if not
found */
pars_info_t* info, /* in: info struct */
const char* name) /* in: bound id name to find */
{
ulint i;
ib_vector_t* vec;
if (!info || !info->bound_ids) {
return(NULL);
}
vec = info->bound_ids;
for (i = 0; i < ib_vector_size(vec); i++) {
pars_bound_id_t* bid = ib_vector_get(vec, i);
if (strcmp(bid->name, name) == 0) {
return(bid);
}
}
return(NULL);
}
...@@ -304,3 +304,42 @@ sym_tab_add_id( ...@@ -304,3 +304,42 @@ sym_tab_add_id(
return(node); return(node);
} }
/**********************************************************************
Add a bound identifier to a symbol table. */
sym_node_t*
sym_tab_add_bound_id(
/*===========*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name) /* in: name of bound id */
{
sym_node_t* node;
pars_bound_id_t* bid;
bid = pars_info_get_bound_id(sym_tab->info, name);
ut_a(bid);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = FALSE;
node->indirection = NULL;
node->name = mem_heap_strdup(sym_tab->heap, bid->id);
node->name_len = strlen(node->name);
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
dfield_set_data(&(node->common.val), NULL, UNIV_SQL_NULL);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
node->sym_table = sym_tab;
return(node);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment