Commit 25de125c authored by osku's avatar osku

Add support for bound literals in the SQL parser.

parent c520e39b
This diff is collapsed.
...@@ -450,14 +450,26 @@ pars_info_get_user_func( ...@@ -450,14 +450,26 @@ pars_info_get_user_func(
pars_info_t* info, /* in: info struct */ pars_info_t* info, /* in: info struct */
const char* name); /* in: function name to find*/ const char* name); /* in: function name to find*/
/********************************************************************
Get bound literal with the given name.*/
pars_bound_lit_t*
pars_info_get_bound_lit(
/*====================*/
/* out: bound literal, or NULL if
not found */
pars_info_t* info, /* in: info struct */
const char* name); /* in: bound literal name to find */
/* Extra information (possibly) supplied for pars_sql(). */
/* Extra information supplied for pars_sql(). All data is owned by the user
who's responsible for freeing them as necessary.*/
struct pars_info_struct { struct pars_info_struct {
pars_user_func_t* funcs; /* User functions, owned by pars_user_func_t* funcs; /* user functions */
the user, who's responsible
for freeing them as
necessary. */
ulint n_funcs; /* number of user functions */ ulint n_funcs; /* number of user functions */
pars_bound_lit_t* bound_lits; /* bound literals */
ulint n_bound_lits; /* number of bound literals */
}; };
/* Type of the user functions. The first argument is always InnoDB-supplied /* Type of the user functions. The first argument is always InnoDB-supplied
...@@ -473,6 +485,15 @@ struct pars_user_func_struct { ...@@ -473,6 +485,15 @@ struct pars_user_func_struct {
void* arg; /* user-supplied argument */ void* arg; /* user-supplied argument */
}; };
/* Bound literal. */
struct pars_bound_lit_struct {
const char* name; /* name */
void* address; /* address */
ulint length; /* length of data */
ulint type; /* type, e.g. DATA_FIXBINARY */
ulint prtype; /* precise type, e.g. DATA_UNSIGNED */
};
/* 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
......
...@@ -54,6 +54,16 @@ sym_tab_add_str_lit( ...@@ -54,6 +54,16 @@ sym_tab_add_str_lit(
it */ it */
ulint len); /* in: string length */ ulint len); /* in: string length */
/********************************************************************** /**********************************************************************
Add a bound literal to a symbol table. */
sym_node_t*
sym_tab_add_bound_lit(
/*==================*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name, /* in: name of bound literal */
ulint* lit_type); /* out: type of literal (PARS_*_LIT) */
/**********************************************************************
Adds an SQL null literal to a symbol table. */ Adds an SQL null literal to a symbol table. */
sym_node_t* sym_node_t*
......
...@@ -11,6 +11,7 @@ Created 1/11/1998 Heikki Tuuri ...@@ -11,6 +11,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 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.
This diff is collapsed.
This diff is collapsed.
...@@ -33,6 +33,8 @@ yylex(void); ...@@ -33,6 +33,8 @@ yylex(void);
%token PARS_INT_LIT %token PARS_INT_LIT
%token PARS_FLOAT_LIT %token PARS_FLOAT_LIT
%token PARS_STR_LIT %token PARS_STR_LIT
%token PARS_FIXBINARY_LIT
%token PARS_BLOB_LIT
%token PARS_NULL_LIT %token PARS_NULL_LIT
%token PARS_ID_TOKEN %token PARS_ID_TOKEN
%token PARS_AND_TOKEN %token PARS_AND_TOKEN
...@@ -169,6 +171,8 @@ exp: ...@@ -169,6 +171,8 @@ exp:
| PARS_INT_LIT { $$ = $1;} | PARS_INT_LIT { $$ = $1;}
| PARS_FLOAT_LIT { $$ = $1;} | PARS_FLOAT_LIT { $$ = $1;}
| PARS_STR_LIT { $$ = $1;} | PARS_STR_LIT { $$ = $1;}
| PARS_FIXBINARY_LIT { $$ = $1;}
| PARS_BLOB_LIT { $$ = $1;}
| PARS_NULL_LIT { $$ = $1;} | PARS_NULL_LIT { $$ = $1;}
| PARS_SQL_TOKEN { $$ = $1;} | PARS_SQL_TOKEN { $$ = $1;}
| exp '+' exp { $$ = pars_op('+', $1, $3); } | exp '+' exp { $$ = pars_op('+', $1, $3); }
......
...@@ -83,6 +83,8 @@ string_append( ...@@ -83,6 +83,8 @@ 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]+
%x comment %x comment
%x quoted %x quoted
%x id %x id
...@@ -100,6 +102,15 @@ ID [a-z_A-Z][a-z_A-Z0-9]* ...@@ -100,6 +102,15 @@ ID [a-z_A-Z][a-z_A-Z0-9]*
return(PARS_FLOAT_LIT); return(PARS_FLOAT_LIT);
} }
{BOUND_LIT} {
ulint type;
yylval = sym_tab_add_bound_lit(pars_sym_tab_global,
yytext + 1, &type);
return(type);
}
"'" { "'" {
/* 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
......
...@@ -1937,3 +1937,29 @@ pars_info_get_user_func( ...@@ -1937,3 +1937,29 @@ pars_info_get_user_func(
return(NULL); return(NULL);
} }
/********************************************************************
Get bound literal with the given name.*/
pars_bound_lit_t*
pars_info_get_bound_lit(
/*====================*/
/* out: bound literal, or NULL if
not found */
pars_info_t* info, /* in: info struct */
const char* name) /* in: bound literal name to find */
{
ulint i;
if (!info) {
return(NULL);
}
for (i = 0; i < info->n_bound_lits; i++) {
if (strcmp(info->bound_lits[i].name, name) == 0) {
return(&info->bound_lits[i]);
}
}
return(NULL);
}
...@@ -15,6 +15,7 @@ Created 12/15/1997 Heikki Tuuri ...@@ -15,6 +15,7 @@ Created 12/15/1997 Heikki Tuuri
#include "mem0mem.h" #include "mem0mem.h"
#include "data0type.h" #include "data0type.h"
#include "data0data.h" #include "data0data.h"
#include "pars0grm.h"
#include "pars0pars.h" #include "pars0pars.h"
#include "que0que.h" #include "que0que.h"
#include "eval0eval.h" #include "eval0eval.h"
...@@ -165,6 +166,71 @@ sym_tab_add_str_lit( ...@@ -165,6 +166,71 @@ sym_tab_add_str_lit(
return(node); return(node);
} }
/**********************************************************************
Add a bound literal to a symbol table. */
sym_node_t*
sym_tab_add_bound_lit(
/*==================*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name, /* in: name of bound literal */
ulint* lit_type) /* out: type of literal (PARS_*_LIT) */
{
sym_node_t* node;
pars_bound_lit_t* blit;
ulint len;
blit = pars_info_get_bound_lit(sym_tab->info, name);
ut_a(blit);
ut_a(blit->length > 0);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
node->indirection = NULL;
switch (blit->type) {
case DATA_FIXBINARY:
len = blit->length;
*lit_type = PARS_FIXBINARY_LIT;
break;
case DATA_BLOB:
len = 0;
*lit_type = PARS_BLOB_LIT;
break;
case DATA_INT:
ut_a(blit->length <= 8);
len = blit->length;
*lit_type = PARS_INT_LIT;
break;
default:
ut_error;
}
dtype_set(&(node->common.val.type), blit->type, blit->prtype, len, 0);
dfield_set_data(&(node->common.val), blit->address, blit->length);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->sym_table = sym_tab;
return(node);
}
/********************************************************************** /**********************************************************************
Adds an SQL null literal to a symbol table. */ Adds an SQL null literal to a symbol table. */
......
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