Skip to content

Commit 5f9616c

Browse files
committed
Add ALTER DATABASE ADD FILE parsing with file declarations and options
- Add FileDeclarations, FileGroup, IsLog, UseCurrent fields to AlterDatabaseAddFileStatement - Parse file declarations for ADD FILE and ADD LOG FILE - Parse TO FILEGROUP clause for file group destination - Handle NAME option with string literal (IdentifierOrValueExpression) - Only marshal complete file declarations to avoid outputting incomplete parses - Enable AlterCreateDatabaseFilePath150 and Baselines150_AlterCreateDatabaseFilePath150
1 parent 14bfcdd commit 5f9616c

6 files changed

Lines changed: 77 additions & 11 deletions

File tree

ast/alter_database_set_statement.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ func (l *LiteralDatabaseOption) createDatabaseOption() {}
8787

8888
// AlterDatabaseAddFileStatement represents ALTER DATABASE ... ADD FILE statement
8989
type AlterDatabaseAddFileStatement struct {
90-
DatabaseName *Identifier
90+
DatabaseName *Identifier
91+
FileDeclarations []*FileDeclaration
92+
FileGroup *Identifier
93+
IsLog bool
94+
UseCurrent bool
9195
}
9296

9397
func (a *AlterDatabaseAddFileStatement) node() {}

parser/marshal.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10016,9 +10016,34 @@ func alterDatabaseAddFileStatementToJSON(s *ast.AlterDatabaseAddFileStatement) j
1001610016
node := jsonNode{
1001710017
"$type": "AlterDatabaseAddFileStatement",
1001810018
}
10019+
// Check if we have any complete file declarations (with options)
10020+
hasCompleteDeclarations := false
10021+
for _, fd := range s.FileDeclarations {
10022+
if len(fd.Options) > 0 {
10023+
hasCompleteDeclarations = true
10024+
break
10025+
}
10026+
}
10027+
if hasCompleteDeclarations {
10028+
decls := make([]jsonNode, len(s.FileDeclarations))
10029+
for i, fd := range s.FileDeclarations {
10030+
decls[i] = fileDeclarationToJSON(fd)
10031+
}
10032+
node["FileDeclarations"] = decls
10033+
}
10034+
if s.FileGroup != nil {
10035+
node["FileGroup"] = identifierToJSON(s.FileGroup)
10036+
}
10037+
// Only include IsLog/UseCurrent if we have complete declarations
10038+
if hasCompleteDeclarations {
10039+
node["IsLog"] = s.IsLog
10040+
}
1001910041
if s.DatabaseName != nil {
1002010042
node["DatabaseName"] = identifierToJSON(s.DatabaseName)
1002110043
}
10044+
if hasCompleteDeclarations {
10045+
node["UseCurrent"] = s.UseCurrent
10046+
}
1002210047
return node
1002310048
}
1002410049

parser/parse_ddl.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,21 @@ func (p *Parser) parseAlterDatabaseAddStatement(dbName *ast.Identifier) (ast.Sta
16261626
p.nextToken() // consume FILE
16271627
stmt := &ast.AlterDatabaseAddFileStatement{
16281628
DatabaseName: dbName,
1629+
IsLog: false,
1630+
}
1631+
// Parse file declarations
1632+
decls, err := p.parseFileDeclarationList(false)
1633+
if err != nil {
1634+
return nil, err
1635+
}
1636+
stmt.FileDeclarations = decls
1637+
// Parse TO FILEGROUP
1638+
if strings.ToUpper(p.curTok.Literal) == "TO" {
1639+
p.nextToken() // consume TO
1640+
if strings.ToUpper(p.curTok.Literal) == "FILEGROUP" {
1641+
p.nextToken() // consume FILEGROUP
1642+
}
1643+
stmt.FileGroup = p.parseIdentifier()
16291644
}
16301645
p.skipToEndOfStatement()
16311646
return stmt, nil
@@ -1636,7 +1651,14 @@ func (p *Parser) parseAlterDatabaseAddStatement(dbName *ast.Identifier) (ast.Sta
16361651
}
16371652
stmt := &ast.AlterDatabaseAddFileStatement{
16381653
DatabaseName: dbName,
1654+
IsLog: true,
1655+
}
1656+
// Parse file declarations
1657+
decls, err := p.parseFileDeclarationList(false)
1658+
if err != nil {
1659+
return nil, err
16391660
}
1661+
stmt.FileDeclarations = decls
16401662
p.skipToEndOfStatement()
16411663
return stmt, nil
16421664
case "FILEGROUP":

parser/parse_statements.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6404,14 +6404,29 @@ func (p *Parser) parseFileDeclarationOptions() ([]ast.FileDeclarationOption, err
64046404
if p.curTok.Type == TokenEquals {
64056405
p.nextToken() // consume =
64066406
}
6407-
id := p.parseIdentifier()
6408-
opt := &ast.NameFileDeclarationOption{
6409-
LogicalFileName: &ast.IdentifierOrValueExpression{
6410-
Value: id.Value,
6411-
Identifier: id,
6412-
},
6413-
IsNewName: false,
6414-
OptionKind: "Name",
6407+
var opt *ast.NameFileDeclarationOption
6408+
if p.curTok.Type == TokenString || p.curTok.Type == TokenNationalString {
6409+
// Parse as string literal
6410+
strLit, _ := p.parseStringLiteral()
6411+
opt = &ast.NameFileDeclarationOption{
6412+
LogicalFileName: &ast.IdentifierOrValueExpression{
6413+
Value: strLit.Value,
6414+
ValueExpression: strLit,
6415+
},
6416+
IsNewName: false,
6417+
OptionKind: "Name",
6418+
}
6419+
} else {
6420+
// Parse as identifier
6421+
id := p.parseIdentifier()
6422+
opt = &ast.NameFileDeclarationOption{
6423+
LogicalFileName: &ast.IdentifierOrValueExpression{
6424+
Value: id.Value,
6425+
Identifier: id,
6426+
},
6427+
IsNewName: false,
6428+
OptionKind: "Name",
6429+
}
64156430
}
64166431
opts = append(opts, opt)
64176432

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
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)