fix some parser bug

This commit is contained in:
wangt1xiuyi
2023-06-16 02:54:11 +00:00
committed by ob-robot
parent 1da48d991e
commit 9ce10fcef5
18 changed files with 133 additions and 29 deletions

View File

@ -1009,7 +1009,7 @@ int ObParser::parse(const ObString &query,
}
}
const ObString stmt(len, query.ptr());
ObString stmt(len, query.ptr());
memset(&parse_result, 0, sizeof(ParseResult));
parse_result.is_multi_values_parser_ = (INS_MULTI_VALUES == parse_mode);
parse_result.is_fp_ = (FP_MODE == parse_mode
@ -1057,7 +1057,7 @@ int ObParser::parse(const ObString &query,
}
}
if (parse_result.is_fp_ || parse_result.is_dynamic_sql_) {
if (OB_SUCC(ret) && (parse_result.is_fp_ || parse_result.is_dynamic_sql_)) {
int64_t new_length = parse_result.is_fp_ ? stmt.length() + 1 : stmt.length() * 2;
char *buf = (char *)parse_malloc(new_length, parse_result.malloc_pool_);
if (OB_UNLIKELY(NULL == buf)) {
@ -1068,6 +1068,18 @@ int ObParser::parse(const ObString &query,
parse_result.no_param_sql_buf_len_ = new_length;
}
}
//compatible mysql, mysql allow use the "--"
if (OB_SUCC(ret) && lib::is_mysql_mode() && stmt.case_compare("--") == 0) {
const char *line_str = "-- ";
char *buf = (char *)parse_malloc(strlen(line_str), parse_result.malloc_pool_);
if (OB_UNLIKELY(NULL == buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("no memory for parser");
} else {
MEMCPY(buf, line_str, strlen(line_str));
stmt.assign_ptr(buf, strlen(line_str));
}
}
if (OB_SUCC(ret) && OB_ISNULL(parse_result.charset_info_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("charset info is null", K(ret),
@ -1107,7 +1119,7 @@ int ObParser::parse(const ObString &query,
}
}
} else {
ObPLParser pl_parser(*(ObIAllocator*)(parse_result.malloc_pool_), connection_collation_);
ObPLParser pl_parser(*(ObIAllocator*)(parse_result.malloc_pool_), connection_collation_, sql_mode_);
if (OB_FAIL(pl_parser.parse(stmt, stmt, parse_result, is_pl_inner_parse))) {
LOG_WARN("failed to parse stmt as pl", K(stmt), K(ret));
// may create ddl func, try it.

View File

@ -299,8 +299,12 @@ int add_alias_name(ParseNode *node, ParseResult *result, int end)
if (OB_UNLIKELY(NULL == trans_buf)) {
ret = OB_PARSER_ERR_NO_MEMORY;
} else {
bool is_ansi_quotes = false;
IS_ANSI_QUOTES(result->sql_mode_, is_ansi_quotes);
for (; index1 < node->str_len_; index1++) {
if ('\"' == node->str_value_[index1] && !(index1 > 0 && '\\' == node->str_value_[index1 - 1])) {
if (is_ansi_quotes && '\"' == node->str_value_[index1]) {
//do nothing, in mysql ansi quotes sql mode: " <==> `, just skip
} else if ('\"' == node->str_value_[index1] && !(index1 > 0 && '\\' == node->str_value_[index1 - 1])) {
trans_buf[index2++] = '\\';
trans_buf[index2++] = '\"';
} else {

View File

@ -1049,4 +1049,20 @@ do {\
}\
} while(0);\
// bugfix:
// avoid '"' in the middle of a str in oracle mode
#define CHECK_ORACLE_IDENTIFIER_VALID(src_str, str_len) \
do { \
if (OB_UNLIKELY(src_str == NULL || str_len <= 0)) { \
} else { \
for (int64_t i = 0; i < str_len; i++) { \
if (OB_UNLIKELY(src_str[i] == '\"')) { \
((ParseResult *)yyextra)->extra_errno_ = OB_PARSER_ERR_UNSUPPORTED; \
yyerror(yylloc, yyextra, "identifier not support to have double quote");\
return ERROR; \
} \
} \
} \
} while(0); \
#endif /* OCEANBASE_SRC_SQL_PARSER_SQL_PARSER_BASE_H_ */

View File

@ -64,7 +64,7 @@ c_cmt_end \*+\/
comment ({sql_comment})
identifier (([A-Za-z0-9$_]|{UTF8_GB_CHAR})*)
system_variable (@@[A-Za-z_][A-Za-z0-9_]*)|(@@[`][`A-Za-z_][`A-Za-z_]*)
user_variable (@[A-Za-z0-9_\.$]*)|(@[`'\"][`'\"A-Za-z0-9_\.$/%]*)
user_variable (@[A-Za-z0-9_\.$]*)|(@[`'\"][`'\"A-Za-z0-9_\.$/%@#\-!,;&~\:\?\+\|\^\*\{\}\(\)\[\]]*)
version_num ([0-9]+\.+[0-9]*)
int_num [0-9]+
client_version \([0-9]+(\.[0-9]+)*\)