MXS-2508 Fix problem

DIV and MOD are now also accepted instead of / and % respectively.
MOD is a keyword but (in principle incorrectly) decays into an id
when used in some other context. That is so that it will be
parser by the general function rule ("id ( ... )"). If used
incorrectly, the server will later reject.
This commit is contained in:
Johan Wikman
2020-03-03 10:40:02 +02:00
parent be3be3bf99
commit ee8e43f26b
3 changed files with 16 additions and 2 deletions

View File

@ -929,9 +929,11 @@ public:
case TK_BITOR:
case TK_CASE:
case TK_CAST:
case TK_DIV:
case TK_IN:
case TK_ISNULL:
case TK_MINUS:
case TK_MOD:
case TK_NOTNULL:
case TK_PLUS:
case TK_SLASH:
@ -4011,6 +4013,9 @@ static const char* get_token_symbol(int token)
case TK_CAST:
return "cast";
case TK_DIV:
return "div";
case TK_IN:
return "in";
@ -4020,6 +4025,9 @@ static const char* get_token_symbol(int token)
case TK_MINUS:
return "-";
case TK_MOD:
return "mod";
case TK_NOTNULL:
return "isnotnull";

View File

@ -631,6 +631,10 @@ columnid(A) ::= nm(X). {
/*KEY*/
/*LIKE_KW*/
MASTER /*MATCH*/ MERGE
// TODO: MOD is a keyword that should not decay into an id. However, now that is does,
// TODO: also "mod(a, 2)" kind of usage will be accepted. Incorrect use will anyway be
// TODO: rejected by the server.
MOD
NAMES NEXT
NO
OF OFFSET OPEN
@ -670,7 +674,7 @@ columnid(A) ::= nm(X). {
%right ESCAPE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left DIV MOD STAR SLASH REM.
%left CONCAT.
%left COLLATE.
%right BITNOT.
@ -2165,7 +2169,7 @@ expr(A) ::= INTERVAL expr(X) id. {
A=X; // We simply ignore 'INTERVAL'
}
%endif
expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y).
expr(A) ::= expr(X) DIV|MOD|STAR|SLASH|REM(OP) expr(Y).
{spanBinaryExpr(&A,pParse,@OP,&X,&Y);}
expr(A) ::= expr(X) CONCAT(OP) expr(Y). {spanBinaryExpr(&A,pParse,@OP,&X,&Y);}
%type likeop {struct LikeOp}

View File

@ -242,6 +242,7 @@ static Keyword aKeywordTable[] = {
{ "DISTINCT", "TK_DISTINCT", ALWAYS },
#ifdef MAXSCALE
{ "DISTINCTROW", "TK_DISTINCT", ALWAYS },
{ "DIV", "TK_DIV", ALWAYS },
{ "DO", "TK_DO", ALWAYS },
#endif
{ "DROP", "TK_DROP", ALWAYS },
@ -349,6 +350,7 @@ static Keyword aKeywordTable[] = {
#ifdef MAXSCALE
{ "MASTER", "TK_MASTER", ALWAYS },
{ "MERGE", "TK_MERGE", ALWAYS },
{ "MOD", "TK_MOD", ALWAYS },
{ "NAMES", "TK_NAMES", ALWAYS },
#endif
{ "NATURAL", "TK_JOIN_KW", ALWAYS },