Fix some compatibility issues of illegal SQL in MySQL
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -2297,6 +2297,7 @@ DEFINE_ERROR(OB_ERR_MALFORMED_PS_PACKET, -9747, -1, "HY000", "malformed ps packe
|
|||||||
DEFINE_ERROR(OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK, -9748, 1351, "HY000", "View's SELECT contains a variable or parameter");
|
DEFINE_ERROR(OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK, -9748, 1351, "HY000", "View's SELECT contains a variable or parameter");
|
||||||
DEFINE_ORACLE_ERROR(OB_ERR_OBJECT_NOT_EXIST, -9749, -1, "HY000", "object does not exist", 6564, "object does not exist", "object %.*s does not exist");
|
DEFINE_ORACLE_ERROR(OB_ERR_OBJECT_NOT_EXIST, -9749, -1, "HY000", "object does not exist", 6564, "object does not exist", "object %.*s does not exist");
|
||||||
DEFINE_ORACLE_ERROR(OB_ERR_TABLE_OUT_OF_RANGE, -9750, -1, "HY000", "PL/SQL: index for PL/SQL table out of range for host language array", 6513, "PL/SQL: index for PL/SQL table out of range for host language array");
|
DEFINE_ORACLE_ERROR(OB_ERR_TABLE_OUT_OF_RANGE, -9750, -1, "HY000", "PL/SQL: index for PL/SQL table out of range for host language array", 6513, "PL/SQL: index for PL/SQL table out of range for host language array");
|
||||||
|
DEFINE_ERROR_EXT(OB_ERR_WRONG_USAGE, -9751, ER_WRONG_USAGE, "HY000", "Incorrect usage", "Incorrect usage of %s", 600, "Incorrect usage", "Incorrect usage of %s");
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// !!! text/blob || clob/blob erro code
|
// !!! text/blob || clob/blob erro code
|
||||||
|
|||||||
@ -1755,6 +1755,7 @@ constexpr int OB_ERR_MALFORMED_PS_PACKET = -9747;
|
|||||||
constexpr int OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK = -9748;
|
constexpr int OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK = -9748;
|
||||||
constexpr int OB_ERR_OBJECT_NOT_EXIST = -9749;
|
constexpr int OB_ERR_OBJECT_NOT_EXIST = -9749;
|
||||||
constexpr int OB_ERR_TABLE_OUT_OF_RANGE = -9750;
|
constexpr int OB_ERR_TABLE_OUT_OF_RANGE = -9750;
|
||||||
|
constexpr int OB_ERR_WRONG_USAGE = -9751;
|
||||||
constexpr int OB_SP_RAISE_APPLICATION_ERROR = -20000;
|
constexpr int OB_SP_RAISE_APPLICATION_ERROR = -20000;
|
||||||
constexpr int OB_SP_RAISE_APPLICATION_ERROR_NUM = -21000;
|
constexpr int OB_SP_RAISE_APPLICATION_ERROR_NUM = -21000;
|
||||||
constexpr int OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN = -22998;
|
constexpr int OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN = -22998;
|
||||||
@ -3858,6 +3859,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
|||||||
#define OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK__USER_ERROR_MSG "View's SELECT contains a variable or parameter"
|
#define OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK__USER_ERROR_MSG "View's SELECT contains a variable or parameter"
|
||||||
#define OB_ERR_OBJECT_NOT_EXIST__USER_ERROR_MSG "object does not exist"
|
#define OB_ERR_OBJECT_NOT_EXIST__USER_ERROR_MSG "object does not exist"
|
||||||
#define OB_ERR_TABLE_OUT_OF_RANGE__USER_ERROR_MSG "PL/SQL: index for PL/SQL table out of range for host language array"
|
#define OB_ERR_TABLE_OUT_OF_RANGE__USER_ERROR_MSG "PL/SQL: index for PL/SQL table out of range for host language array"
|
||||||
|
#define OB_ERR_WRONG_USAGE__USER_ERROR_MSG "Incorrect usage of %s"
|
||||||
#define OB_SP_RAISE_APPLICATION_ERROR__USER_ERROR_MSG "%.*s"
|
#define OB_SP_RAISE_APPLICATION_ERROR__USER_ERROR_MSG "%.*s"
|
||||||
#define OB_SP_RAISE_APPLICATION_ERROR_NUM__USER_ERROR_MSG "error number argument to raise_application_error of '%d' is out of range"
|
#define OB_SP_RAISE_APPLICATION_ERROR_NUM__USER_ERROR_MSG "error number argument to raise_application_error of '%d' is out of range"
|
||||||
#define OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN__USER_ERROR_MSG "CLOB or NCLOB in multibyte character set not supported"
|
#define OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN__USER_ERROR_MSG "CLOB or NCLOB in multibyte character set not supported"
|
||||||
@ -5961,6 +5963,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
|||||||
#define OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -9748, View's SELECT contains a variable or parameter"
|
#define OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -9748, View's SELECT contains a variable or parameter"
|
||||||
#define OB_ERR_OBJECT_NOT_EXIST__ORA_USER_ERROR_MSG "ORA-06564: object does not exist"
|
#define OB_ERR_OBJECT_NOT_EXIST__ORA_USER_ERROR_MSG "ORA-06564: object does not exist"
|
||||||
#define OB_ERR_TABLE_OUT_OF_RANGE__ORA_USER_ERROR_MSG "ORA-06513: PL/SQL: index for PL/SQL table out of range for host language array"
|
#define OB_ERR_TABLE_OUT_OF_RANGE__ORA_USER_ERROR_MSG "ORA-06513: PL/SQL: index for PL/SQL table out of range for host language array"
|
||||||
|
#define OB_ERR_WRONG_USAGE__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -9751, Incorrect usage of %s"
|
||||||
#define OB_SP_RAISE_APPLICATION_ERROR__ORA_USER_ERROR_MSG "ORA%06ld: %.*s"
|
#define OB_SP_RAISE_APPLICATION_ERROR__ORA_USER_ERROR_MSG "ORA%06ld: %.*s"
|
||||||
#define OB_SP_RAISE_APPLICATION_ERROR_NUM__ORA_USER_ERROR_MSG "ORA-21000: error number argument to raise_application_error of '%d' is out of range"
|
#define OB_SP_RAISE_APPLICATION_ERROR_NUM__ORA_USER_ERROR_MSG "ORA-21000: error number argument to raise_application_error of '%d' is out of range"
|
||||||
#define OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN__ORA_USER_ERROR_MSG "ORA-22998: CLOB or NCLOB in multibyte character set not supported"
|
#define OB_CLOB_ONLY_SUPPORT_WITH_MULTIBYTE_FUN__ORA_USER_ERROR_MSG "ORA-22998: CLOB or NCLOB in multibyte character set not supported"
|
||||||
@ -5971,7 +5974,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
|||||||
#define OB_ERR_DATA_TOO_LONG_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-12899: value too large for column %.*s (actual: %ld, maximum: %ld)"
|
#define OB_ERR_DATA_TOO_LONG_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-12899: value too large for column %.*s (actual: %ld, maximum: %ld)"
|
||||||
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-01861: Incorrect datetime value for column '%.*s' at row %ld"
|
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-01861: Incorrect datetime value for column '%.*s' at row %ld"
|
||||||
|
|
||||||
extern int g_all_ob_errnos[2099];
|
extern int g_all_ob_errnos[2100];
|
||||||
|
|
||||||
const char *ob_error_name(const int oberr);
|
const char *ob_error_name(const int oberr);
|
||||||
const char* ob_error_cause(const int oberr);
|
const char* ob_error_cause(const int oberr);
|
||||||
|
|||||||
@ -1046,9 +1046,15 @@ int ObFastParserBase::process_hex_number(bool is_quote)
|
|||||||
* Values written using X'val' notation must contain an even number of digits or a syntax error occurs. To correct the problem, pad the value with a leading zero.
|
* Values written using X'val' notation must contain an even number of digits or a syntax error occurs. To correct the problem, pad the value with a leading zero.
|
||||||
* Values written using 0xval notation that contain an odd number of digits are treated as having an extra leading 0. For example, 0xaaa is interpreted as 0x0aaa.
|
* Values written using 0xval notation that contain an odd number of digits are treated as having an extra leading 0. For example, 0xaaa is interpreted as 0x0aaa.
|
||||||
*/
|
*/
|
||||||
return OB_ERR_PARSER_SYNTAX;
|
|
||||||
LOG_WARN("parser syntax error",
|
LOG_WARN("parser syntax error",
|
||||||
K(ret), K(str_len), K(raw_sql_.to_string()), K_(raw_sql_.cur_pos));
|
K(ret), K(str_len), K(raw_sql_.to_string()), K_(raw_sql_.cur_pos));
|
||||||
|
return OB_ERR_PARSER_SYNTAX;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Values written using 0xval notation NOTE: 0Xval (use upper case 'X') notation is illegal in MySQL
|
||||||
|
if (!is_oracle_mode_ && raw_sql_.char_at(cur_token_begin_pos_ + 1) == 'X') {
|
||||||
|
LOG_WARN("parser syntax error", K(ret));
|
||||||
|
return OB_ERR_PARSER_SYNTAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str_len > 0) {
|
if (str_len > 0) {
|
||||||
@ -1126,6 +1132,12 @@ int ObFastParserBase::process_binary(bool is_quote)
|
|||||||
int64_t dst_str_len = 0;
|
int64_t dst_str_len = 0;
|
||||||
if ('\'' == raw_sql_.char_at(raw_sql_.cur_pos_ - 1)) {
|
if ('\'' == raw_sql_.char_at(raw_sql_.cur_pos_ - 1)) {
|
||||||
--str_len;
|
--str_len;
|
||||||
|
} else {
|
||||||
|
// Values written using 0bval notation NOTE: 0Bval (use upper case 'B') notation is illegal in MySQL
|
||||||
|
if (!is_oracle_mode_ && raw_sql_.char_at(cur_token_begin_pos_ + 1) == 'B') {
|
||||||
|
LOG_WARN("parser syntax error", K(ret));
|
||||||
|
return OB_ERR_PARSER_SYNTAX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (str_len > 0) {
|
if (str_len > 0) {
|
||||||
dst_str_len = ob_parse_bit_string_len(str_len);
|
dst_str_len = ob_parse_bit_string_len(str_len);
|
||||||
|
|||||||
@ -702,6 +702,12 @@ X'([0-9A-F])*'|0X([0-9A-F])+ {
|
|||||||
yyerror(yylloc, yyextra, "hex string contain an even number of digits\n");
|
yyerror(yylloc, yyextra, "hex string contain an even number of digits\n");
|
||||||
return PARSER_SYNTAX_ERROR;
|
return PARSER_SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Values written using 0xval notation NOTE: 0Xval (use upper case 'X') notation is illegal in MySQL
|
||||||
|
if (yytext[1] == 'X') {
|
||||||
|
yyerror(yylloc, yyextra, "hex string with leading '0X' (use upper case 'X') is illegal\n");
|
||||||
|
return PARSER_SYNTAX_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ParseNode *node = NULL;
|
ParseNode *node = NULL;
|
||||||
ParseResult *p = (ParseResult *)yyextra;
|
ParseResult *p = (ParseResult *)yyextra;
|
||||||
@ -738,6 +744,12 @@ B'([01])*'|0B([01])+ {
|
|||||||
if(src[len - 1] == '\'')
|
if(src[len - 1] == '\'')
|
||||||
{
|
{
|
||||||
--len;
|
--len;
|
||||||
|
} else {
|
||||||
|
// Values written using 0bval notation NOTE: 0Bval (use upper case 'B') notation is illegal in MySQL
|
||||||
|
if (yytext[1] == 'B') {
|
||||||
|
yyerror(yylloc, yyextra, "bit string with leading '0B' (use upper case 'B') is illegal\n");
|
||||||
|
return PARSER_SYNTAX_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ParseNode *node = NULL;
|
ParseNode *node = NULL;
|
||||||
ParseResult *p = (ParseResult *)yyextra;
|
ParseResult *p = (ParseResult *)yyextra;
|
||||||
|
|||||||
@ -1283,6 +1283,7 @@ int ObSelectResolver::resolve_query_options(const ParseNode *node)
|
|||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
bool is_set_distinct = false;
|
bool is_set_distinct = false;
|
||||||
|
bool is_set_all = false;
|
||||||
ObSelectStmt *select_stmt = get_select_stmt();
|
ObSelectStmt *select_stmt = get_select_stmt();
|
||||||
if (OB_ISNULL(select_stmt)) {
|
if (OB_ISNULL(select_stmt)) {
|
||||||
ret = OB_NOT_INIT;
|
ret = OB_NOT_INIT;
|
||||||
@ -1298,6 +1299,8 @@ int ObSelectResolver::resolve_query_options(const ParseNode *node)
|
|||||||
option_node = node->children_[i];
|
option_node = node->children_[i];
|
||||||
if (option_node->type_ == T_DISTINCT) {
|
if (option_node->type_ == T_DISTINCT) {
|
||||||
is_set_distinct = true;
|
is_set_distinct = true;
|
||||||
|
} else if (option_node->type_ == T_ALL) {
|
||||||
|
is_set_all = true;
|
||||||
} else if (option_node->type_ == T_FOUND_ROWS) {
|
} else if (option_node->type_ == T_FOUND_ROWS) {
|
||||||
if (has_calc_found_rows_) {
|
if (has_calc_found_rows_) {
|
||||||
has_calc_found_rows_ = false;
|
has_calc_found_rows_ = false;
|
||||||
@ -1311,7 +1314,10 @@ int ObSelectResolver::resolve_query_options(const ParseNode *node)
|
|||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret)) {
|
||||||
//默认为all
|
//默认为all
|
||||||
if (is_set_distinct) {
|
if (is_set_all && is_set_distinct) {
|
||||||
|
ret = OB_ERR_WRONG_USAGE;
|
||||||
|
LOG_USER_ERROR(OB_ERR_WRONG_USAGE, "ALL and DISTINCT");
|
||||||
|
} else if (is_set_distinct) {
|
||||||
select_stmt->assign_distinct();
|
select_stmt->assign_distinct();
|
||||||
} else {
|
} else {
|
||||||
select_stmt->assign_all();
|
select_stmt->assign_all();
|
||||||
|
|||||||
Reference in New Issue
Block a user