private IExpression StartedFromIdentifier(string consumed, string consumedUp)
{
IExpression tempExpr;
IExpression tempExpr2;
IList<IExpression> tempExprList;
string tempStr;
StringBuilder tempSb;
bool tempGroupDistinct;
switch (lexer.Token())
{
case MySqlToken.PuncDot:
{
for (tempExpr = new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
lexer.Token() == MySqlToken.PuncDot;)
{
switch (lexer.NextToken())
{
case MySqlToken.Identifier:
{
tempExpr =
new Identifier((Identifier)tempExpr, lexer.GetStringValue(),
lexer.GetStringValueUppercase()).SetCacheEvalRst(cacheEvalRst);
lexer.NextToken();
break;
}
case MySqlToken.OpAsterisk:
{
lexer.NextToken();
return new Wildcard((Identifier)tempExpr).SetCacheEvalRst(cacheEvalRst);
}
default:
{
throw Err("expect IDENTIFIER or '*' after '.', but is " + lexer.Token());
}
}
}
return tempExpr;
}
case MySqlToken.LiteralBit:
{
if (consumed[0] != '_')
{
return new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
}
tempStr = lexer.GetStringValue();
lexer.NextToken();
return new LiteralBitField(consumed, tempStr).SetCacheEvalRst(cacheEvalRst);
}
case MySqlToken.LiteralHex:
{
if (consumed[0] != '_')
{
return new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
}
var hex = new LiteralHexadecimal(consumed, lexer.Sql, lexer.OffsetCache, lexer.SizeCache, charset);
lexer.NextToken();
return hex.SetCacheEvalRst(cacheEvalRst);
}
case MySqlToken.LiteralChars:
{
if (consumed[0] != '_')
{
return new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
}
tempSb = new StringBuilder();
do
{
lexer.AppendStringContent(tempSb);
} while (lexer.NextToken() == MySqlToken.LiteralChars);
return new LiteralString(consumed, tempSb.ToString(), false).SetCacheEvalRst(cacheEvalRst);
}
case MySqlToken.PuncLeftParen:
{
consumedUp = IdentifierExpr.UnescapeName(consumedUp);
switch (functionManager.GetParsingStrategy(consumedUp))
{
case FunctionParsingStrategy.GetFormat:
{
// GET_FORMAT({DATE|TIME|DATETIME},
// {'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL'})
lexer.NextToken();
var gfi = MatchIdentifier("DATE", "TIME", "DATETIME", "TIMESTAMP");
Match(MySqlToken.PuncComma);
var getFormatArg = Expression();
Match(MySqlToken.PuncRightParen);
switch (gfi)
{
case 0:
{
return new GetFormat(GetFormat.FormatType.Date, getFormatArg);
}
case 1:
{
return new GetFormat(GetFormat.FormatType.Time, getFormatArg);
}
case 2:
case 3:
{
return new GetFormat(GetFormat.FormatType.Datetime, getFormatArg);
}
}
throw Err("unexpected format type for GET_FORMAT()");
}
case FunctionParsingStrategy.Cast:
{
lexer.NextToken();
tempExpr = Expression();
Match(MySqlToken.KwAs);
var type = Type4specialFunc();
Match(MySqlToken.PuncRightParen);
var info = type.Value;
if (info != null)
{
return
new Cast(tempExpr, type.Key, info.Key, info.Value).SetCacheEvalRst(
cacheEvalRst);
}
return new Cast(tempExpr, type.Key, null, null).SetCacheEvalRst(cacheEvalRst);
//goto case FunctionParsingStrategy.Position;
}
case FunctionParsingStrategy.Position:
{
lexer.NextToken();
tempExprList = new List<IExpression>(2);
tempExprList.Add(Expression());
Match(MySqlToken.KwIn);
tempExprList.Add(Expression());
Match(MySqlToken.PuncRightParen);
return new Locate(tempExprList).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Substring:
{
lexer.NextToken();
tempExprList = new List<IExpression>(3);
tempExprList.Add(Expression());
Match(MySqlToken.PuncComma, MySqlToken.KwFrom);
tempExprList.Add(Expression());
switch (lexer.Token())
{
case MySqlToken.PuncComma:
case MySqlToken.KwFor:
{
lexer.NextToken();
tempExprList.Add(Expression());
goto default;
}
default:
{
Match(MySqlToken.PuncRightParen);
break;
}
}
return new Substring(tempExprList).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Row:
{
lexer.NextToken();
tempExprList = ExpressionList(new List<IExpression>());
return new RowExpression(tempExprList).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Trim:
{
TrimDirection _trimDirection;
switch (lexer.NextToken())
{
case MySqlToken.KwBoth:
{
lexer.NextToken();
_trimDirection = TrimDirection.Both;
break;
}
case MySqlToken.KwLeading:
{
lexer.NextToken();
_trimDirection = TrimDirection.Leading;
break;
}
case MySqlToken.KwTrailing:
{
lexer.NextToken();
_trimDirection = TrimDirection.Trailing;
break;
}
default:
{
_trimDirection = TrimDirection.Default;
break;
}
}
if (_trimDirection == TrimDirection.Default)
{
tempExpr = Expression();
if (lexer.Token() == MySqlToken.KwFrom)
{
lexer.NextToken();
tempExpr2 = Expression();
Match(MySqlToken.PuncRightParen);
return new Trim(_trimDirection, tempExpr, tempExpr2).SetCacheEvalRst(cacheEvalRst);
}
Match(MySqlToken.PuncRightParen);
return new Trim(_trimDirection, null, tempExpr).SetCacheEvalRst(cacheEvalRst);
}
if (lexer.Token() == MySqlToken.KwFrom)
{
lexer.NextToken();
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Trim(_trimDirection, null, tempExpr).SetCacheEvalRst(cacheEvalRst);
}
tempExpr = Expression();
Match(MySqlToken.KwFrom);
tempExpr2 = Expression();
Match(MySqlToken.PuncRightParen);
return new Trim(_trimDirection, tempExpr, tempExpr2).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Avg:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
tempGroupDistinct = true;
lexer.NextToken();
}
else
{
tempGroupDistinct = false;
}
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Avg(tempExpr, tempGroupDistinct).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Max:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
tempGroupDistinct = true;
lexer.NextToken();
}
else
{
tempGroupDistinct = false;
}
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Max(tempExpr, tempGroupDistinct).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Min:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
tempGroupDistinct = true;
lexer.NextToken();
}
else
{
tempGroupDistinct = false;
}
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Min(tempExpr, tempGroupDistinct).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Sum:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
tempGroupDistinct = true;
lexer.NextToken();
}
else
{
tempGroupDistinct = false;
}
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Sum(tempExpr, tempGroupDistinct).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Count:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
lexer.NextToken();
tempExprList = ExpressionList(new List<IExpression>());
return new Count(tempExprList).SetCacheEvalRst(cacheEvalRst);
}
tempExpr = Expression();
Match(MySqlToken.PuncRightParen);
return new Count(tempExpr).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.GroupConcat:
{
if (lexer.NextToken() == MySqlToken.KwDistinct)
{
lexer.NextToken();
tempGroupDistinct = true;
}
else
{
tempGroupDistinct = false;
}
for (tempExprList = new List<IExpression>();;)
{
tempExpr = Expression();
tempExprList.Add(tempExpr);
if (lexer.Token() == MySqlToken.PuncComma)
{
lexer.NextToken();
}
else
{
break;
}
}
var isDesc = false;
IList<IExpression> appendedColumnNames = null;
tempExpr = null;
// order by
tempStr = null;
switch (lexer.Token())
{
case MySqlToken.KwOrder:
{
// literalChars
lexer.NextToken();
Match(MySqlToken.KwBy);
tempExpr = Expression();
if (lexer.Token() == MySqlToken.KwAsc)
{
lexer.NextToken();
}
else
{
if (lexer.Token() == MySqlToken.KwDesc)
{
isDesc = true;
lexer.NextToken();
}
}
for (appendedColumnNames = new List<IExpression>()
;
lexer.Token() == MySqlToken.PuncComma;)
{
lexer.NextToken();
appendedColumnNames.Add(Expression());
}
if (lexer.Token() != MySqlToken.KwSeparator)
{
break;
}
goto case MySqlToken.KwSeparator;
}
case MySqlToken.KwSeparator:
{
lexer.NextToken();
tempSb = new StringBuilder();
lexer.AppendStringContent(tempSb);
tempStr = LiteralString.GetUnescapedString(tempSb.ToString());
Match(MySqlToken.LiteralChars);
break;
}
}
Match(MySqlToken.PuncRightParen);
return
new GroupConcat(tempGroupDistinct, tempExprList, tempExpr, isDesc, appendedColumnNames,
tempStr).SetCacheEvalRst(cacheEvalRst);
}
case FunctionParsingStrategy.Char:
{
lexer.NextToken();
return FunctionChar();
}
case FunctionParsingStrategy.Convert:
{
lexer.NextToken();
return FunctionConvert();
}
case FunctionParsingStrategy.Extract:
{
lexer.NextToken();
return Extract();
}
case FunctionParsingStrategy.Timestampdiff:
{
lexer.NextToken();
return Timestampdiff();
}
case FunctionParsingStrategy.Timestampadd:
{
lexer.NextToken();
return Timestampadd();
}
case FunctionParsingStrategy.Ordinary:
{
return OrdinaryFunction(consumed, consumedUp);
}
case FunctionParsingStrategy.Default:
{
return new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
}
default:
{
throw Err("unexpected function parsing strategy for id of " + consumed);
}
}
//goto default;
}
default:
{
return new Identifier(null, consumed, consumedUp).SetCacheEvalRst(cacheEvalRst);
}
}
}