📄 eval0eval.c
字号:
arg1 = func_node->args; arg2 = que_node_get_next(arg1); ut_ad(func_node->func == PARS_SUBSTR_TOKEN); arg3 = que_node_get_next(arg2); str1 = dfield_get_data(que_node_get_val(arg1)); len1 = (ulint)eval_node_get_int_val(arg2); len2 = (ulint)eval_node_get_int_val(arg3); dfield = que_node_get_val(func_node); dfield_set_data(dfield, str1 + len1, len2);}/*********************************************************************Evaluates a replstr-procedure node. */staticvoideval_replstr(/*=========*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg1; que_node_t* arg2; que_node_t* arg3; que_node_t* arg4; byte* str1; byte* str2; ulint len1; ulint len2; arg1 = func_node->args; arg2 = que_node_get_next(arg1); ut_ad(que_node_get_type(arg1) == QUE_NODE_SYMBOL); arg3 = que_node_get_next(arg2); arg4 = que_node_get_next(arg3); str1 = dfield_get_data(que_node_get_val(arg1)); str2 = dfield_get_data(que_node_get_val(arg2)); len1 = (ulint)eval_node_get_int_val(arg3); len2 = (ulint)eval_node_get_int_val(arg4); if ((dfield_get_len(que_node_get_val(arg1)) < len1 + len2) || (dfield_get_len(que_node_get_val(arg2)) < len2)) { ut_error; } ut_memcpy(str1 + len1, str2, len2);} /*********************************************************************Evaluates an instr-function node. */staticvoideval_instr(/*=======*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg1; que_node_t* arg2; dfield_t* dfield1; dfield_t* dfield2; lint int_val; byte* str1; byte* str2; byte match_char; ulint len1; ulint len2; ulint i; ulint j; arg1 = func_node->args; arg2 = que_node_get_next(arg1); dfield1 = que_node_get_val(arg1); dfield2 = que_node_get_val(arg2); str1 = dfield_get_data(dfield1); str2 = dfield_get_data(dfield2); len1 = dfield_get_len(dfield1); len2 = dfield_get_len(dfield2); if (len2 == 0) { ut_error; } match_char = str2[0]; for (i = 0; i < len1; i++) { /* In this outer loop, the number of matched characters is 0 */ if (str1[i] == match_char) { if (i + len2 > len1) { break; } for (j = 1;; j++) { /* We have already matched j characters */ if (j == len2) { int_val = i + 1; goto match_found; } if (str1[i + j] != str2[j]) { break; } } } } int_val = 0;match_found: eval_node_set_int_val(func_node, int_val);}/*********************************************************************Evaluates a predefined function node. */UNIV_INLINEvoideval_binary_to_number(/*==================*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg1; dfield_t* dfield; byte* str1; byte* str2; ulint len1; ulint int_val; arg1 = func_node->args; dfield = que_node_get_val(arg1); str1 = dfield_get_data(dfield); len1 = dfield_get_len(dfield); if (len1 > 4) { ut_error; } if (len1 == 4) { str2 = str1; } else { int_val = 0; str2 = (byte*)&int_val; ut_memcpy(str2 + (4 - len1), str1, len1); } eval_node_copy_and_alloc_val(func_node, str2, 4);} /*********************************************************************Evaluates a predefined function node. */staticvoideval_concat(/*========*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg; dfield_t* dfield; byte* data; ulint len; ulint len1; arg = func_node->args; len = 0; while (arg) { len1 = dfield_get_len(que_node_get_val(arg)); len += len1; arg = que_node_get_next(arg); } data = eval_node_ensure_val_buf(func_node, len); arg = func_node->args; len = 0; while (arg) { dfield = que_node_get_val(arg); len1 = dfield_get_len(dfield); ut_memcpy(data + len, dfield_get_data(dfield), len1); len += len1; arg = que_node_get_next(arg); }}/*********************************************************************Evaluates a predefined function node. If the first argument is an integer,this function looks at the second argument which is the integer length inbytes, and converts the integer to a VARCHAR.If the first argument is of some other type, this function converts it toBINARY. */UNIV_INLINEvoideval_to_binary(/*===========*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg1; que_node_t* arg2; dfield_t* dfield; byte* str1; ulint len; ulint len1; arg1 = func_node->args; str1 = dfield_get_data(que_node_get_val(arg1)); if (dtype_get_mtype(que_node_get_data_type(arg1)) != DATA_INT) { len = dfield_get_len(que_node_get_val(arg1)); dfield = que_node_get_val(func_node); dfield_set_data(dfield, str1, len); return; } arg2 = que_node_get_next(arg1); len1 = (ulint)eval_node_get_int_val(arg2); if (len1 > 4) { ut_error; } dfield = que_node_get_val(func_node); dfield_set_data(dfield, str1 + (4 - len1), len1);}/*********************************************************************Evaluates a predefined function node. */UNIV_INLINEvoideval_predefined(/*============*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg1; lint int_val; byte* data; int func; func = func_node->func; arg1 = func_node->args; if (func == PARS_LENGTH_TOKEN) { int_val = (lint)dfield_get_len(que_node_get_val(arg1)); } else if (func == PARS_TO_CHAR_TOKEN) { /* Convert number to character string as a signed decimal integer. */ ulint uint_val; int int_len; int_val = eval_node_get_int_val(arg1); /* Determine the length of the string. */ if (int_val == 0) { int_len = 1; /* the number 0 occupies 1 byte */ } else { int_len = 0; if (int_val < 0) { uint_val = ((ulint) -int_val - 1) + 1; int_len++; /* reserve space for minus sign */ } else { uint_val = (ulint) int_val; } for (; uint_val > 0; int_len++) { uint_val /= 10; } } /* allocate the string */ data = eval_node_ensure_val_buf(func_node, int_len + 1); /* add terminating NUL character */ data[int_len] = 0; /* convert the number */ if (int_val == 0) { data[0] = '0'; } else { int tmp; if (int_val < 0) { data[0] = '-'; /* preceding minus sign */ uint_val = ((ulint) -int_val - 1) + 1; } else { uint_val = (ulint) int_val; } for (tmp = int_len; uint_val > 0; uint_val /= 10) { data[--tmp] = (byte) ('0' + (byte)(uint_val % 10)); } } dfield_set_len((dfield_t*) que_node_get_val(func_node), int_len); return; } else if (func == PARS_TO_NUMBER_TOKEN) { int_val = atoi((char*) dfield_get_data(que_node_get_val(arg1))); } else if (func == PARS_SYSDATE_TOKEN) { int_val = (lint)ut_time(); } else { eval_predefined_2(func_node); return; } eval_node_set_int_val(func_node, int_val); }/*********************************************************************Evaluates a function node. */voideval_func(/*======*/ func_node_t* func_node) /* in: function node */{ que_node_t* arg; ulint class; ulint func; ut_ad(que_node_get_type(func_node) == QUE_NODE_FUNC); class = func_node->class; func = func_node->func; arg = func_node->args; /* Evaluate first the argument list */ while (arg) { eval_exp(arg); /* The functions are not defined for SQL null argument values, except for eval_cmp and notfound */ if ((dfield_get_len(que_node_get_val(arg)) == UNIV_SQL_NULL) && (class != PARS_FUNC_CMP) && (func != PARS_NOTFOUND_TOKEN) && (func != PARS_PRINTF_TOKEN)) { ut_error; } arg = que_node_get_next(arg); } if (class == PARS_FUNC_CMP) { eval_cmp(func_node); } else if (class == PARS_FUNC_ARITH) { eval_arith(func_node); } else if (class == PARS_FUNC_AGGREGATE) { eval_aggregate(func_node); } else if (class == PARS_FUNC_PREDEFINED) { if (func == PARS_NOTFOUND_TOKEN) { eval_notfound(func_node); } else if (func == PARS_SUBSTR_TOKEN) { eval_substr(func_node); } else if (func == PARS_REPLSTR_TOKEN) { eval_replstr(func_node); } else if (func == PARS_INSTR_TOKEN) { eval_instr(func_node); } else if (func == PARS_BINARY_TO_NUMBER_TOKEN) { eval_binary_to_number(func_node); } else if (func == PARS_CONCAT_TOKEN) { eval_concat(func_node); } else if (func == PARS_TO_BINARY_TOKEN) { eval_to_binary(func_node); } else { eval_predefined(func_node); } } else { ut_ad(class == PARS_FUNC_LOGICAL); eval_logical(func_node); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -