Skip to content

Commit

Permalink
parser: use ShowLikeOrWhereOpt to reduce code
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Sep 28, 2015
1 parent 49ae949 commit 55a5b39
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ import (
SetStmt "Set variable statement"
ShowStmt "Show engines/databases/tables/columns/warnings statement"
ShowDatabaseNameOpt "Show tables/columns statement database name option"
ShowLikeOrWhereOpt "Show like or where condition option"
ShowTableIdentOpt "Show columns statement table name option"
SignedLiteral "Literal or NumLiteral with sign"
SimpleQualifiedIdent "Qualified identifier without *"
Expand Down Expand Up @@ -3165,51 +3166,35 @@ ShowStmt:
{
$$ = &stmts.ShowStmt{Target: stmt.ShowWarnings}
}
// See: https://dev.mysql.com/doc/refman/5.7/en/show-variables.html
// TODO: Support show variables with where clause.
| "SHOW" GlobalScope "VARIABLES"
| "SHOW" GlobalScope "VARIABLES" ShowLikeOrWhereOpt
{
$$ = &stmts.ShowStmt{
Target: stmt.ShowVariables,
GlobalScope: $2.(bool),
}

}
| "SHOW" GlobalScope "VARIABLES" "LIKE" PrimaryExpression
{
$$ = &stmts.ShowStmt{
stmt := &stmts.ShowStmt{
Target: stmt.ShowVariables,
GlobalScope: $2.(bool),
Pattern: &expression.PatternLike{Pattern: $5.(expression.Expression)},
}
stmt.SetCondition($4)
$$ = stmt
}
| "SHOW" GlobalScope "VARIABLES" "WHERE" Expression
| "SHOW" "COLLATION" ShowLikeOrWhereOpt
{
$$ = &stmts.ShowStmt{
Target: stmt.ShowVariables,
GlobalScope: $2.(bool),
Where: expression.Expr($5),
stmt := &stmts.ShowStmt{
Target: stmt.ShowCollation,
}
stmt.SetCondition($3)
$$ = stmt
}
| "SHOW" "COLLATION"

ShowLikeOrWhereOpt:
{
$$ = &stmts.ShowStmt{
Target: stmt.ShowCollation,
}
$$ = nil
}
| "SHOW" "COLLATION" "LIKE" PrimaryExpression
| "LIKE" PrimaryExpression
{
$$ = &stmts.ShowStmt{
Target: stmt.ShowCollation,
Pattern: &expression.PatternLike{Pattern: $4.(expression.Expression)},
}
$$ = &expression.PatternLike{Pattern: $2.(expression.Expression)}
}
| "SHOW" "COLLATION" "WHERE" Expression
| "WHERE" Expression
{
$$ = &stmts.ShowStmt{
Target: stmt.ShowCollation,
Where: expression.Expr($4),
}
$$ = expression.Expr($2)
}

GlobalScope:
Expand Down

0 comments on commit 55a5b39

Please sign in to comment.