Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5577,6 +5577,7 @@ type DropDatabase struct {
Name *Ident
IfExists bool
OnCluster *ClusterClause
Modifier string
}

func (d *DropDatabase) Pos() Pos {
Expand Down
3 changes: 3 additions & 0 deletions parser/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,9 @@ func (d *DropDatabase) FormatSQL(formatter *Formatter) {
formatter.WriteByte(whitespace)
formatter.WriteExpr(d.OnCluster)
}
if len(d.Modifier) != 0 {
formatter.WriteString(" " + d.Modifier)
}
}

func (d *DropStmt) FormatSQL(formatter *Formatter) {
Expand Down
9 changes: 9 additions & 0 deletions parser/parser_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ func (p *Parser) parseDropDatabase(pos Pos) (*DropDatabase, error) {
statementEnd = onCluster.End()
}

modifier, err := p.tryParseModifier()
if err != nil {
return nil, err
}
if modifier != "" {
statementEnd = p.Pos()
}

return &DropDatabase{
DropPos: pos,
Name: name,
IfExists: isExists,
OnCluster: onCluster,
Modifier: modifier,
StatementEnd: statementEnd,
}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions parser/testdata/ddl/drop_database.sql
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
DROP DATABASE IF EXISTS datbase_name;
DROP DATABASE IF EXISTS test_db SYNC;
DROP DATABASE IF EXISTS test_db ON CLUSTER akvorado SYNC;
DROP DATABASE test_db ON CLUSTER akvorado NO DELAY;
6 changes: 6 additions & 0 deletions parser/testdata/ddl/format/beautify/drop_database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
-- Origin SQL:
DROP DATABASE IF EXISTS datbase_name;
DROP DATABASE IF EXISTS test_db SYNC;
DROP DATABASE IF EXISTS test_db ON CLUSTER akvorado SYNC;
DROP DATABASE test_db ON CLUSTER akvorado NO DELAY;


-- Beautify SQL:
DROP DATABASE IF EXISTS datbase_name;
DROP DATABASE IF EXISTS test_db SYNC;
DROP DATABASE IF EXISTS test_db ON CLUSTER akvorado SYNC;
DROP DATABASE test_db ON CLUSTER akvorado NO DELAY;
6 changes: 6 additions & 0 deletions parser/testdata/ddl/format/drop_database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
-- Origin SQL:
DROP DATABASE IF EXISTS datbase_name;
DROP DATABASE IF EXISTS test_db SYNC;
DROP DATABASE IF EXISTS test_db ON CLUSTER akvorado SYNC;
DROP DATABASE test_db ON CLUSTER akvorado NO DELAY;


-- Format SQL:
DROP DATABASE IF EXISTS datbase_name;
DROP DATABASE IF EXISTS test_db SYNC;
DROP DATABASE IF EXISTS test_db ON CLUSTER akvorado SYNC;
DROP DATABASE test_db ON CLUSTER akvorado NO DELAY;
58 changes: 57 additions & 1 deletion parser/testdata/ddl/output/drop_database.sql.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,62 @@
"NameEnd": 36
},
"IfExists": true,
"OnCluster": null
"OnCluster": null,
"Modifier": ""
},
{
"DropPos": 38,
"StatementEnd": 74,
"Name": {
"Name": "test_db",
"QuoteType": 1,
"NamePos": 62,
"NameEnd": 69
},
"IfExists": true,
"OnCluster": null,
"Modifier": "SYNC"
},
{
"DropPos": 76,
"StatementEnd": 132,
"Name": {
"Name": "test_db",
"QuoteType": 1,
"NamePos": 100,
"NameEnd": 107
},
"IfExists": true,
"OnCluster": {
"OnPos": 108,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 119,
"NameEnd": 127
}
},
"Modifier": "SYNC"
},
{
"DropPos": 134,
"StatementEnd": 184,
"Name": {
"Name": "test_db",
"QuoteType": 1,
"NamePos": 148,
"NameEnd": 155
},
"IfExists": false,
"OnCluster": {
"OnPos": 156,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 167,
"NameEnd": 175
}
},
"Modifier": "NO DELAY"
}
]
Loading