Skip to content

Commit 1d571bb

Browse files
authored
Add SHOW PRIVILEGES statement parsing (#30)
1 parent ebc9989 commit 1d571bb

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

ast/ast.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,15 @@ func (e *ExistsQuery) Pos() token.Position { return e.Position }
620620
func (e *ExistsQuery) End() token.Position { return e.Position }
621621
func (e *ExistsQuery) statementNode() {}
622622

623+
// ShowPrivilegesQuery represents a SHOW PRIVILEGES statement.
624+
type ShowPrivilegesQuery struct {
625+
Position token.Position `json:"-"`
626+
}
627+
628+
func (s *ShowPrivilegesQuery) Pos() token.Position { return s.Position }
629+
func (s *ShowPrivilegesQuery) End() token.Position { return s.Position }
630+
func (s *ShowPrivilegesQuery) statementNode() {}
631+
623632
// -----------------------------------------------------------------------------
624633
// Expressions
625634

internal/explain/explain.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func Node(sb *strings.Builder, node interface{}, depth int) {
115115
explainExplainQuery(sb, n, indent, depth)
116116
case *ast.ShowQuery:
117117
explainShowQuery(sb, n, indent)
118+
case *ast.ShowPrivilegesQuery:
119+
fmt.Fprintf(sb, "%sShowPrivilegesQuery\n", indent)
118120
case *ast.UseQuery:
119121
explainUseQuery(sb, n, indent)
120122
case *ast.DescribeQuery:

parser/parser.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,13 +2612,21 @@ func (p *Parser) parseDescribe() *ast.DescribeQuery {
26122612
return desc
26132613
}
26142614

2615-
func (p *Parser) parseShow() *ast.ShowQuery {
2616-
show := &ast.ShowQuery{
2617-
Position: p.current.Pos,
2618-
}
2615+
func (p *Parser) parseShow() ast.Statement {
2616+
pos := p.current.Pos
26192617

26202618
p.nextToken() // skip SHOW
26212619

2620+
// Handle SHOW PRIVILEGES first - it has its own statement type
2621+
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "PRIVILEGES" {
2622+
p.nextToken()
2623+
return &ast.ShowPrivilegesQuery{Position: pos}
2624+
}
2625+
2626+
show := &ast.ShowQuery{
2627+
Position: pos,
2628+
}
2629+
26222630
switch p.current.Token {
26232631
case token.TABLES:
26242632
show.ShowType = ast.ShowTables
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)