parseDropStatement parses DROP statements (TABLE, VIEW, MATERIALIZED VIEW, INDEX)
()
| 613 | |
| 614 | // parseDropStatement parses DROP statements (TABLE, VIEW, MATERIALIZED VIEW, INDEX) |
| 615 | func (p *Parser) parseDropStatement() (*ast.DropStatement, error) { |
| 616 | stmt := &ast.DropStatement{} |
| 617 | |
| 618 | // Determine object type |
| 619 | if p.isType(models.TokenTypeMaterialized) { |
| 620 | p.advance() // Consume MATERIALIZED |
| 621 | if !p.isType(models.TokenTypeView) { |
| 622 | return nil, p.expectedError("VIEW after MATERIALIZED") |
| 623 | } |
| 624 | p.advance() // Consume VIEW |
| 625 | stmt.ObjectType = "MATERIALIZED VIEW" |
| 626 | } else if p.isType(models.TokenTypeView) { |
| 627 | p.advance() // Consume VIEW |
| 628 | stmt.ObjectType = "VIEW" |
| 629 | } else if p.isType(models.TokenTypeTable) { |
| 630 | p.advance() // Consume TABLE |
| 631 | stmt.ObjectType = "TABLE" |
| 632 | } else if p.isType(models.TokenTypeIndex) { |
| 633 | p.advance() // Consume INDEX |
| 634 | stmt.ObjectType = "INDEX" |
| 635 | } else { |
| 636 | return nil, p.expectedError("TABLE, VIEW, MATERIALIZED VIEW, or INDEX after DROP") |
| 637 | } |
| 638 | |
| 639 | // Check for IF EXISTS |
| 640 | if p.isType(models.TokenTypeIf) { |
| 641 | p.advance() // Consume IF |
| 642 | if !p.isType(models.TokenTypeExists) { |
| 643 | return nil, p.expectedError("EXISTS after IF") |
| 644 | } |
| 645 | p.advance() // Consume EXISTS |
| 646 | stmt.IfExists = true |
| 647 | } |
| 648 | |
| 649 | // Parse object names (can be comma-separated, supports schema.name qualification) |
| 650 | for { |
| 651 | dropName, err := p.parseQualifiedName() |
| 652 | if err != nil { |
| 653 | return nil, p.expectedError("object name") |
| 654 | } |
| 655 | stmt.Names = append(stmt.Names, dropName) |
| 656 | |
| 657 | if p.isType(models.TokenTypeComma) { |
| 658 | p.advance() // Consume comma |
| 659 | continue |
| 660 | } |
| 661 | break |
| 662 | } |
| 663 | |
| 664 | // Parse optional CASCADE/RESTRICT |
| 665 | if p.isType(models.TokenTypeCascade) { |
| 666 | stmt.CascadeType = "CASCADE" |
| 667 | p.advance() |
| 668 | } else if p.isType(models.TokenTypeRestrict) { |
| 669 | stmt.CascadeType = "RESTRICT" |
| 670 | p.advance() |
| 671 | } |
| 672 |
no test coverage detected