parseCreateStatement parses CREATE statements (TABLE, VIEW, MATERIALIZED VIEW, INDEX)
()
| 39 | |
| 40 | // parseCreateStatement parses CREATE statements (TABLE, VIEW, MATERIALIZED VIEW, INDEX) |
| 41 | func (p *Parser) parseCreateStatement() (ast.Statement, error) { |
| 42 | // Check for modifiers: OR REPLACE, TEMPORARY, TEMP |
| 43 | orReplace := false |
| 44 | temporary := false |
| 45 | |
| 46 | for { |
| 47 | if p.isType(models.TokenTypeOr) { |
| 48 | p.advance() // Consume OR |
| 49 | if !p.isType(models.TokenTypeReplace) { |
| 50 | return nil, p.expectedError("REPLACE after OR") |
| 51 | } |
| 52 | p.advance() // Consume REPLACE |
| 53 | orReplace = true |
| 54 | } else if p.isTokenMatch("TEMPORARY") || p.isTokenMatch("TEMP") { |
| 55 | p.advance() // Consume TEMPORARY/TEMP |
| 56 | temporary = true |
| 57 | } else { |
| 58 | break |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Determine object type |
| 63 | if p.isType(models.TokenTypeMaterialized) { |
| 64 | p.advance() // Consume MATERIALIZED |
| 65 | if !p.isType(models.TokenTypeView) { |
| 66 | return nil, p.expectedError("VIEW after MATERIALIZED") |
| 67 | } |
| 68 | p.advance() // Consume VIEW |
| 69 | return p.parseCreateMaterializedView() |
| 70 | } else if p.isType(models.TokenTypeView) { |
| 71 | p.advance() // Consume VIEW |
| 72 | return p.parseCreateView(orReplace, temporary) |
| 73 | } else if p.isType(models.TokenTypeTable) { |
| 74 | p.advance() // Consume TABLE |
| 75 | return p.parseCreateTable(temporary) |
| 76 | } else if p.isType(models.TokenTypeIndex) { |
| 77 | p.advance() // Consume INDEX |
| 78 | return p.parseCreateIndex(false) // Not unique |
| 79 | } else if p.isType(models.TokenTypeUnique) { |
| 80 | p.advance() // Consume UNIQUE |
| 81 | if !p.isType(models.TokenTypeIndex) { |
| 82 | return nil, p.expectedError("INDEX after UNIQUE") |
| 83 | } |
| 84 | p.advance() // Consume INDEX |
| 85 | return p.parseCreateIndex(true) // Unique |
| 86 | } else if p.isMariaDB() && p.isTokenMatch("SEQUENCE") { |
| 87 | seqPos := p.currentLocation() // position of SEQUENCE token |
| 88 | p.advance() // Consume SEQUENCE |
| 89 | stmt, err := p.parseCreateSequenceStatement(orReplace) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | if stmt.Pos.IsZero() { |
| 94 | stmt.Pos = seqPos |
| 95 | } |
| 96 | return stmt, nil |
| 97 | } |
| 98 |
no test coverage detected