상속: VariableExpression
예제 #1
0
 public virtual void Visit(UsrDefVarPrimary node)
 {
 }
예제 #2
0
        /// <exception cref="System.SqlSyntaxErrorException" />
        private object VarAssign()
        {
            VariableExpression var;
            IExpression expr;
            var scope = VariableScope.Session;
            switch (lexer.Token())
            {
                case MySqlToken.Identifier:
                {
                    var explictScope = false;
                    var si = specialIdentifiers.GetValue(lexer.GetStringValueUppercase());
                    if (si != SpecialIdentifier.None)
                    {
                        switch (si)
                        {
                            case SpecialIdentifier.Transaction:
                            {
                                return SetMTSSetTransactionStatement(VariableScope.None);
                            }

                            case SpecialIdentifier.Global:
                            {
                                scope = VariableScope.Global;
                                goto case SpecialIdentifier.Session;
                            }

                            case SpecialIdentifier.Session:
                            case SpecialIdentifier.Local:
                            {
                                explictScope = true;
                                lexer.NextToken();
                                goto default;
                            }

                            default:
                            {
                                break;
                            }
                        }
                    }
                    if (explictScope
                        && specialIdentifiers.GetValue(lexer.GetStringValueUppercase()) == SpecialIdentifier.Transaction)
                    {
                        return SetMTSSetTransactionStatement(scope);
                    }
                    var = new SysVarPrimary(scope, lexer.GetStringValue(), lexer.GetStringValueUppercase());
                    Match(MySqlToken.Identifier);
                    break;
                }

                case MySqlToken.SysVar:
                {
                    var = SystemVariale();
                    break;
                }

                case MySqlToken.UsrVar:
                {
                    var = new UsrDefVarPrimary(lexer.GetStringValue());
                    lexer.NextToken();
                    break;
                }

                default:
                {
                    throw Err("unexpected token for SET statement");
                }
            }
            Match(MySqlToken.OpEquals, MySqlToken.OpAssign);
            expr = exprParser.Expression();
            return new Pair<VariableExpression, IExpression>(var, expr);
        }
예제 #3
0
        /// <exception cref="System.SqlSyntaxErrorException" />
        private IExpression PrimaryExpression(string consumed
                                              , string consumedUp)
        {
            if (consumed != null)
            {
                return StartedFromIdentifier(consumed, consumedUp);
            }
            string tempStr;
            string tempStrUp;
            StringBuilder tempSb;
            Number tempNum;
            IExpression tempExpr;
            IExpression tempExpr2;
            IList<IExpression> tempExprList;
            switch (lexer.Token())
            {
                case MySqlToken.PlaceHolder:
                {
                    tempStr = lexer.GetStringValue();
                    tempStrUp = lexer.GetStringValueUppercase();
                    lexer.NextToken();
                    return CreatePlaceHolder(tempStr, tempStrUp);
                }

                case MySqlToken.LiteralBit:
                {
                    tempStr = lexer.GetStringValue();
                    lexer.NextToken();
                    return new LiteralBitField(null, tempStr).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralHex:
                {
                    var hex = new LiteralHexadecimal(null, lexer.Sql, lexer.OffsetCache, lexer.SizeCache, charset);
                    lexer.NextToken();
                    return hex.SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralBoolFalse:
                {
                    lexer.NextToken();
                    return new LiteralBoolean(false).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralBoolTrue:
                {
                    lexer.NextToken();
                    return new LiteralBoolean(true).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralNull:
                {
                    lexer.NextToken();
                    return new LiteralNull().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralNchars:
                {
                    tempSb = new StringBuilder();
                    do
                    {
                        lexer.AppendStringContent(tempSb);
                    } while (lexer.NextToken() == MySqlToken.LiteralChars);
                    return new LiteralString(null, tempSb.ToString(), true).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralChars:
                {
                    tempSb = new StringBuilder();
                    do
                    {
                        lexer.AppendStringContent(tempSb);
                    } while (lexer.NextToken() == MySqlToken.LiteralChars);
                    return new LiteralString(null, tempSb.ToString(), false).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralNumPureDigit:
                {
                    tempNum = lexer.GetIntegerValue();
                    lexer.NextToken();
                    return new LiteralNumber(tempNum).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.LiteralNumMixDigit:
                {
                    tempNum = lexer.GetDecimalValue();
                    lexer.NextToken();
                    return new LiteralNumber(tempNum).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.QuestionMark:
                {
                    var index = lexer.ParamIndex;
                    lexer.NextToken();
                    return CreateParam(index);
                }

                case MySqlToken.KwCase:
                {
                    lexer.NextToken();
                    return CaseWhenExpression();
                }

                case MySqlToken.KwInterval:
                {
                    lexer.NextToken();
                    return IntervalExpression();
                }

                case MySqlToken.KwExists:
                {
                    lexer.NextToken();
                    Match(MySqlToken.PuncLeftParen);
                    tempExpr = SubQuery();
                    Match(MySqlToken.PuncRightParen);
                    return new ExistsPrimary((IQueryExpression)tempExpr).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.UsrVar:
                {
                    tempStr = lexer.GetStringValue();
                    tempExpr = new UsrDefVarPrimary(tempStr).SetCacheEvalRst(cacheEvalRst);
                    if (lexer.NextToken() == MySqlToken.OpAssign)
                    {
                        lexer.NextToken();
                        tempExpr2 = Expression();
                        return new AssignmentExpression(tempExpr, tempExpr2);
                    }
                    return tempExpr;
                }

                case MySqlToken.SysVar:
                {
                    return SystemVariale();
                }

                case MySqlToken.KwMatch:
                {
                    lexer.NextToken();
                    return MatchExpression();
                }

                case MySqlToken.PuncLeftParen:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.KwSelect)
                    {
                        tempExpr = SubQuery();
                        Match(MySqlToken.PuncRightParen);
                        return tempExpr;
                    }
                    tempExpr = Expression();
                    switch (lexer.Token())
                    {
                        case MySqlToken.PuncRightParen:
                        {
                            lexer.NextToken();
                            return tempExpr;
                        }

                        case MySqlToken.PuncComma:
                        {
                            lexer.NextToken();
                            tempExprList = new List<IExpression>();
                            tempExprList.Add(tempExpr);
                            tempExprList = ExpressionList(tempExprList);
                            return new RowExpression(tempExprList).SetCacheEvalRst(cacheEvalRst);
                        }

                        default:
                        {
                            throw Err("unexpected token: " + lexer.Token());
                        }
                    }
                    //goto case MySqlToken.KwUtcDate;
                }

                case MySqlToken.KwUtcDate:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new UtcDate(null).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwUtcTime:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new UtcTime(null).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwUtcTimestamp:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new UtcTimestamp(null).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwCurrentDate:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new Curdate().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwCurrentTime:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new Curtime().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwCurrentTimestamp:
                case MySqlToken.KwLocaltime:
                case MySqlToken.KwLocaltimestamp:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new Now().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwCurrentUser:
                {
                    lexer.NextToken();
                    if (lexer.Token() == MySqlToken.PuncLeftParen)
                    {
                        lexer.NextToken();
                        Match(MySqlToken.PuncRightParen);
                    }
                    return new CurrentUser().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwDefault:
                {
                    if (lexer.NextToken() == MySqlToken.PuncLeftParen)
                    {
                        return OrdinaryFunction(lexer.GetStringValue(), lexer.GetStringValueUppercase());
                    }
                    return new DefaultValue().SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwDatabase:
                case MySqlToken.KwIf:
                case MySqlToken.KwInsert:
                case MySqlToken.KwLeft:
                case MySqlToken.KwRepeat:
                case MySqlToken.KwReplace:
                case MySqlToken.KwRight:
                case MySqlToken.KwSchema:
                case MySqlToken.KwValues:
                {
                    tempStr = lexer.GetStringValue();
                    tempStrUp = lexer.GetStringValueUppercase();
                    var tempStrUp2 = lexer.Token().KeyWordToString();
                    if (!tempStrUp2.Equals(tempStrUp))
                    {
                        tempStrUp = tempStr = tempStrUp2;
                    }
                    if (lexer.NextToken() == MySqlToken.PuncLeftParen)
                    {
                        return OrdinaryFunction(tempStr, tempStrUp);
                    }
                    throw Err("keyword not followed by '(' is not expression: " + tempStr);
                }

                case MySqlToken.KwMod:
                {
                    lexer.NextToken();
                    Match(MySqlToken.PuncLeftParen);
                    tempExpr = Expression();
                    Match(MySqlToken.PuncComma);
                    tempExpr2 = Expression();
                    Match(MySqlToken.PuncRightParen);
                    return new ArithmeticModExpression(tempExpr, tempExpr2).SetCacheEvalRst(cacheEvalRst);
                }

                case MySqlToken.KwChar:
                {
                    lexer.NextToken();
                    Match(MySqlToken.PuncLeftParen);
                    return FunctionChar();
                }

                case MySqlToken.KwConvert:
                {
                    lexer.NextToken();
                    Match(MySqlToken.PuncLeftParen);
                    return FunctionConvert();
                }

                case MySqlToken.Identifier:
                {
                    tempStr = lexer.GetStringValue();
                    tempStrUp = lexer.GetStringValueUppercase();
                    lexer.NextToken();
                    return StartedFromIdentifier(tempStr, tempStrUp);
                }

                case MySqlToken.OpAsterisk:
                {
                    lexer.NextToken();
                    return new Wildcard(null).SetCacheEvalRst(cacheEvalRst);
                }

                default:
                {
                    throw Err("unrecognized token as first token of primary: " + lexer.Token());
                }
            }
        }