32 #include "pars0pars.ic"
54 UNIV_INTERN ibool pars_print_lexed = FALSE;
59 UNIV_INTERN
sym_tab_t* pars_sym_tab_global;
65 UNIV_INTERN
pars_res_word_t pars_to_number_token = {PARS_TO_NUMBER_TOKEN};
66 UNIV_INTERN
pars_res_word_t pars_to_binary_token = {PARS_TO_BINARY_TOKEN};
67 UNIV_INTERN
pars_res_word_t pars_binary_to_number_token = {PARS_BINARY_TO_NUMBER_TOKEN};
80 UNIV_INTERN
pars_res_word_t pars_distinct_token = {PARS_DISTINCT_TOKEN};
94 UNIV_INTERN
pars_res_word_t pars_clustered_token = {PARS_CLUSTERED_TOKEN};
103 pars_info_lookup_user_func(
110 if (info && info->
funcs) {
114 for (i = 0; i < ib_vector_size(vec); i++) {
120 if (strcmp(puf->
name, name) == 0) {
133 pars_info_lookup_bound_id(
144 for (i = 0; i < ib_vector_size(vec); i++) {
150 if (strcmp(bid->
name, name) == 0) {
163 pars_info_lookup_bound_lit(
174 for (i = 0; i < ib_vector_size(vec); i++) {
180 if (strcmp(pbl->
name, name) == 0) {
199 case '+':
case '-':
case '*':
case '/':
202 case '=':
case '<':
case '>':
203 case PARS_GE_TOKEN:
case PARS_LE_TOKEN:
case PARS_NE_TOKEN:
206 case PARS_AND_TOKEN:
case PARS_OR_TOKEN:
case PARS_NOT_TOKEN:
209 case PARS_COUNT_TOKEN:
case PARS_SUM_TOKEN:
212 case PARS_TO_CHAR_TOKEN:
213 case PARS_TO_NUMBER_TOKEN:
214 case PARS_TO_BINARY_TOKEN:
215 case PARS_BINARY_TO_NUMBER_TOKEN:
216 case PARS_SUBSTR_TOKEN:
217 case PARS_CONCAT_TOKEN:
218 case PARS_LENGTH_TOKEN:
219 case PARS_INSTR_TOKEN:
220 case PARS_SYSDATE_TOKEN:
221 case PARS_NOTFOUND_TOKEN:
222 case PARS_PRINTF_TOKEN:
223 case PARS_ASSERT_TOKEN:
225 case PARS_RND_STR_TOKEN:
226 case PARS_REPLSTR_TOKEN:
251 node->
common.val_buf_size = 0;
255 node->
fclass = pars_func_get_class(func);
271 que_node_t* res_word,
294 ib_like_t op = IB_LIKE_EXACT;
295 int func = PARS_LIKE_TOKEN_EXACT;
298 if (ptr[ptr_len - 1] ==
'%') {
304 op = (op == IB_LIKE_PREFIX) ? IB_LIKE_SUBSTR : IB_LIKE_SUFFIX;
307 if (node->like_node == NULL) {
313 node->like_node = like_node;
317 like_node = node->like_node;
322 que_node_list_get_last(like_node));
326 ut_a(str_node != like_node);
334 dtype = dfield_get_type(dfield);
337 op_check =
static_cast<ib_like_t
>(
364 dtype = dfield_get_type(dfield);
372 func = PARS_LIKE_TOKEN_PREFIX;
378 dtype = dfield_get_type(dfield);
386 func = PARS_LIKE_TOKEN_SUFFIX;
393 dtype = dfield_get_type(dfield);
401 func = PARS_LIKE_TOKEN_SUBSTR;
408 dtype = dfield_get_type(dfield);
433 int func = PARS_LIKE_TOKEN_EXACT;
435 dtype_t* dtype = dfield_get_type(dfield);
440 ptr =
static_cast<char*
>(dfield_get_data(dfield));
441 ptr_len = strlen(ptr);
445 func = pars_like_rebind(
446 static_cast<sym_node_t*>(arg), (byte*) ptr, ptr_len);
471 if (func == PARS_LIKE_TOKEN) {
475 func = pars_like_op(arg2);
477 ut_a(func == PARS_LIKE_TOKEN_EXACT
478 || func == PARS_LIKE_TOKEN_PREFIX
479 || func == PARS_LIKE_TOKEN_SUFFIX
480 || func == PARS_LIKE_TOKEN_SUBSTR);
483 return(pars_func_low(func, arg1));
506 if (asc == &pars_asc_token) {
509 ut_a(asc == &pars_desc_token);
527 case DATA_VARCHAR:
case DATA_CHAR:
528 case DATA_FIXBINARY:
case DATA_BINARY:
540 pars_resolve_func_data_type(
550 switch (node->
func) {
552 case '+':
case '-':
case '*':
case '/':
563 case PARS_COUNT_TOKEN:
568 case PARS_TO_CHAR_TOKEN:
569 case PARS_RND_STR_TOKEN:
575 case PARS_TO_BINARY_TOKEN:
585 case PARS_TO_NUMBER_TOKEN:
586 case PARS_BINARY_TO_NUMBER_TOKEN:
587 case PARS_LENGTH_TOKEN:
588 case PARS_INSTR_TOKEN:
593 case PARS_SYSDATE_TOKEN:
598 case PARS_SUBSTR_TOKEN:
599 case PARS_CONCAT_TOKEN:
605 case '>':
case '<':
case '=':
612 case PARS_NOTFOUND_TOKEN:
623 case PARS_LIKE_TOKEN_EXACT:
624 case PARS_LIKE_TOKEN_PREFIX:
625 case PARS_LIKE_TOKEN_SUFFIX:
626 case PARS_LIKE_TOKEN_SUBSTR:
641 pars_resolve_exp_variables_and_types(
647 que_node_t* exp_node)
659 arg = func_node->
args;
662 pars_resolve_exp_variables_and_types(select_node, arg);
667 pars_resolve_func_data_type(func_node);
674 sym_node =
static_cast<sym_node_t*
>(exp_node);
706 fprintf(stderr,
"PARSER ERROR: Unresolved identifier %s\n",
714 sym_node->
alias = node;
732 pars_resolve_exp_list_variables_and_types(
735 que_node_t* exp_node)
739 pars_resolve_exp_variables_and_types(select_node, exp_node);
749 pars_resolve_exp_columns(
752 que_node_t* exp_node)
767 arg = func_node->
args;
770 pars_resolve_exp_columns(table_node, arg);
780 sym_node =
static_cast<sym_node_t*
>(exp_node);
793 table = t_node->
table;
797 for (i = 0; i < n_cols; i++) {
799 = dict_table_get_nth_col(table, i);
815 dfield_get_type(&sym_node
830 pars_resolve_exp_list_columns(
833 que_node_t* exp_node)
837 pars_resolve_exp_columns(table_node, exp_node);
847 pars_retrieve_table_def(
874 pars_retrieve_table_list_defs(
880 if (sym_node == NULL) {
886 pars_retrieve_table_def(sym_node);
901 pars_select_all_columns(
916 table = table_node->
table;
943 que_node_t* select_list,
953 pars_resolve_exp_list_variables_and_types(NULL, into_list);
963 pars_check_aggregate(
968 que_node_t* exp_node;
971 ulint n_aggregate_nodes = 0;
992 if (n_aggregate_nodes > 0) {
993 ut_a(n_nodes == n_aggregate_nodes);
1011 que_node_t* search_cond,
1019 select_node->
n_tables = pars_retrieve_table_list_defs(table_list);
1024 pars_select_all_columns(select_node);
1034 pars_resolve_exp_list_columns(table_list, select_node->
select_list);
1035 pars_resolve_exp_list_variables_and_types(select_node,
1037 pars_check_aggregate(select_node);
1042 pars_resolve_exp_columns(table_list, search_cond);
1043 pars_resolve_exp_variables_and_types(select_node, search_cond);
1054 }
else if (lock_shared){
1070 pars_resolve_exp_columns(table_list, order_by->
column);
1081 return(select_node);
1119 ut_a(pars_info_lookup_user_func(
1120 pars_sym_tab_global->
info, sym_node->
name));
1141 node->is_delete = is_delete;
1143 node->table_sym = table_sym;
1144 node->col_assign_list = col_assign_list;
1176 pars_process_assign_list(
1186 ulint changes_ord_field;
1187 ulint changes_field_size;
1191 table_sym = node->table_sym;
1193 node->col_assign_list);
1194 clust_index = dict_table_get_first_index(node->
table);
1196 assign_node = col_assign_list;
1199 while (assign_node) {
1200 pars_resolve_exp_columns(table_sym, assign_node->
col);
1201 pars_resolve_exp_columns(table_sym, assign_node->
val);
1202 pars_resolve_exp_variables_and_types(NULL, assign_node->
val);
1209 assign_node->
val))));
1225 assign_node = col_assign_list;
1227 changes_field_size = UPD_NODE_NO_SIZE_CHANGE;
1229 for (i = 0; i < n_assigns; i++) {
1230 upd_field = upd_get_nth_field(node->
update, i);
1232 col_sym = assign_node->
col;
1235 clust_index, col_sym->
col_no),
1237 upd_field->
exp = assign_node->
val;
1243 changes_field_size = 0;
1252 changes_ord_field = UPD_NODE_NO_ORD_CHANGE;
1256 changes_ord_field = 0;
1259 node->cmpl_info = changes_ord_field | changes_field_size;
1272 que_node_t* search_cond)
1278 table_sym = node->table_sym;
1280 pars_retrieve_table_def(table_sym);
1290 pars_resolve_exp_variables_and_types(NULL, cursor_sym);
1294 node->searched_update = FALSE;
1299 &pars_share_token, NULL);
1300 node->searched_update = TRUE;
1306 ut_a(!node->is_delete || (node->col_assign_list == NULL));
1307 ut_a(node->is_delete || (node->col_assign_list != NULL));
1309 if (node->is_delete) {
1310 node->cmpl_info = 0;
1312 pars_process_assign_list(node);
1315 if (node->searched_update) {
1316 node->has_clust_rec_x_lock = TRUE;
1320 node->has_clust_rec_x_lock = sel_node->
set_x_locks;
1330 node->
state = UPD_NODE_UPDATE_CLUSTERED;
1356 que_node_t* values_list,
1363 ut_a(values_list || select);
1364 ut_a(!values_list || !select);
1367 ins_type = INS_VALUES;
1369 ins_type = INS_SEARCHED;
1372 pars_retrieve_table_def(table_sym);
1375 pars_sym_tab_global->
heap);
1393 node->values_list = values_list;
1395 if (node->values_list) {
1396 pars_resolve_exp_list_variables_and_types(NULL, values_list);
1409 pars_set_dfield_type(
1423 flags |= DATA_NOT_NULL;
1427 flags |= DATA_UNSIGNED;
1430 if (type == &pars_bigint_token) {
1433 dtype_set(dfield_get_type(dfield), DATA_INT, flags, 8);
1434 }
else if (type == &pars_int_token) {
1437 dtype_set(dfield_get_type(dfield), DATA_INT, flags, 4);
1439 }
else if (type == &pars_char_token) {
1442 dtype_set(dfield_get_type(dfield), DATA_VARCHAR,
1443 DATA_ENGLISH | flags, len);
1444 }
else if (type == &pars_binary_token) {
1447 dtype_set(dfield_get_type(dfield), DATA_FIXBINARY,
1448 DATA_BINARY_TYPE | flags, len);
1449 }
else if (type == &pars_blob_token) {
1452 dtype_set(dfield_get_type(dfield), DATA_BLOB,
1453 DATA_BINARY_TYPE | flags, 0);
1493 ut_a((param_type == PARS_INPUT) || (param_type == PARS_OUTPUT));
1506 pars_set_parent_in_list(
1508 que_node_t* node_list,
1531 que_node_t* stat_list)
1543 pars_resolve_exp_variables_and_types(NULL, cond);
1558 que_node_t* stat_list,
1559 que_node_t* else_part)
1573 pars_resolve_exp_variables_and_types(NULL, cond);
1586 while (elsif_node) {
1587 pars_set_parent_in_list(elsif_node->
stat_list, node);
1596 pars_set_parent_in_list(else_part, node);
1599 pars_set_parent_in_list(stat_list, node);
1612 que_node_t* stat_list)
1624 pars_resolve_exp_variables_and_types(NULL, cond);
1628 pars_set_parent_in_list(stat_list, node);
1641 que_node_t* loop_start_limit,
1642 que_node_t* loop_end_limit,
1643 que_node_t* stat_list)
1652 pars_resolve_exp_variables_and_types(NULL, loop_var);
1653 pars_resolve_exp_variables_and_types(NULL, loop_start_limit);
1654 pars_resolve_exp_variables_and_types(NULL, loop_end_limit);
1665 pars_set_parent_in_list(stat_list, node);
1725 pars_resolve_exp_variables_and_types(NULL, var);
1726 pars_resolve_exp_variables_and_types(NULL, val);
1741 que_node_t* res_word,
1748 pars_resolve_exp_list_variables_and_types(NULL, args);
1769 ut_a(!into_list != !user_func);
1777 pars_resolve_exp_variables_and_types(NULL, cursor);
1780 pars_resolve_exp_list_variables_and_types(NULL, into_list);
1784 pars_resolve_exp_variables_and_types(NULL, user_func);
1786 node->
func = pars_info_lookup_user_func(
1787 pars_sym_tab_global->
info, user_func->
name);
1794 cursor_decl = cursor->
alias;
1828 pars_resolve_exp_variables_and_types(NULL, cursor);
1830 cursor_decl = cursor->
alias;
1911 is_unsigned != NULL, is_not_null != NULL);
1928 void* not_fit_in_memory __attribute__((unused)))
1948 if (compact != NULL) {
1965 if (block_size != NULL) {
1973 dfield_get_data(dfield)));
1980 case 1:
case 2:
case 4:
case 8:
case 16:
1994 table_sym->
name, 0, n_cols, flags, flags2);
1997 if (not_fit_in_memory != NULL) {
1998 table->does_not_fit_in_memory = TRUE;
2001 column = column_defs;
2052 if (clustered_def) {
2057 ind_type, n_fields);
2058 column = column_list;
2090 que_node_t* stat_list)
2097 heap = pars_sym_tab_global->
heap;
2117 pars_set_parent_in_list(stat_list, node);
2119 node->
sym_tab = pars_sym_tab_global;
2138 sym_node_t* sym_node __attribute__((unused)))
2166 if (len > max_size) {
2170 #ifdef UNIV_SQL_DEBUG
2171 if (pars_print_lexed) {
2197 const char* s __attribute__((unused)))
2202 fputs(
"PARSER ERROR: Syntax error in SQL string\n", stderr);
2230 pars_sym_tab_global->
string_len = strlen(str);
2231 pars_sym_tab_global->
sql_string =
static_cast<char*
>(
2234 pars_sym_tab_global->
info = info;
2248 graph->
sym_tab = pars_sym_tab_global;
2251 pars_sym_tab_global = NULL;
2334 const void* address,
2357 heap_alloc = ib_heap_allocator_create(info->
heap);
2359 info->
bound_lits = ib_vector_create(heap_alloc,
sizeof(*pbl), 8);
2377 DATA_VARCHAR, DATA_ENGLISH);
2385 pars_info_bind_literal(
2389 const void* address,
2396 pbl = pars_info_lookup_bound_lit(info, name);
2400 info, name, address, length, type, prtype);
2405 sym_tab_rebind_lit(pbl->
node, address, length);
2423 pbl = pars_info_lookup_bound_lit(info, name);
2427 info, name, str, str_len, DATA_VARCHAR, DATA_ENGLISH);
2433 sym_tab_rebind_lit(pbl->
node, str, str_len);
2469 const ib_uint32_t* val)
2473 pbl = pars_info_lookup_bound_lit(info, name);
2480 pbl->
length =
sizeof(*val);
2482 sym_tab_rebind_lit(pbl->
node, val,
sizeof(*val));
2495 const ib_uint64_t* val)
2499 pbl = pars_info_lookup_bound_lit(info, name);
2503 info, name, val,
sizeof(*val), DATA_INT, 0);
2507 pbl->
length =
sizeof(*val);
2509 sym_tab_rebind_lit(pbl->
node, val,
sizeof(*val));
2546 const ib_uint64_t* val)
2550 pbl = pars_info_lookup_bound_lit(info, name);
2554 info, name, val,
sizeof(*val), DATA_FIXBINARY, 0);
2558 pbl->
length =
sizeof(*val);
2560 sym_tab_rebind_lit(pbl->
node, val,
sizeof(*val));
2577 puf = pars_info_lookup_user_func(info, name);
2583 heap_alloc = ib_heap_allocator_create(info->
heap);
2585 info->
funcs = ib_vector_create(
2586 heap_alloc,
sizeof(*puf), 8);
2591 ib_vector_push(info->
funcs, NULL));
2612 bid = pars_info_lookup_bound_id(info, name);
2619 heap_alloc = ib_heap_allocator_create(info->
heap);
2622 heap_alloc,
sizeof(*bid), 8);
2629 bid->
name = (copy_name)
2647 return(pars_info_lookup_bound_id(info, name));
2660 return(pars_info_lookup_bound_lit(info, name));