(stripped, raw string)
| 139 | } |
| 140 | |
| 141 | func BuildStatementWithComments(stripped, raw string) (Statement, error) { |
| 142 | switch { |
| 143 | case exitRe.MatchString(stripped): |
| 144 | return &ExitStatement{}, nil |
| 145 | case useRe.MatchString(stripped): |
| 146 | matched := useRe.FindStringSubmatch(stripped) |
| 147 | return &UseStatement{Database: unquoteIdentifier(matched[1]), Role: unquoteIdentifier(matched[2])}, nil |
| 148 | case selectRe.MatchString(stripped), graphRe.MatchString(stripped), callRe.MatchString(stripped): |
| 149 | return &SelectStatement{Query: raw}, nil |
| 150 | case createDatabaseRe.MatchString(stripped): |
| 151 | return &CreateDatabaseStatement{CreateStatement: stripped}, nil |
| 152 | case createRe.MatchString(stripped): |
| 153 | return &DdlStatement{Ddl: stripped}, nil |
| 154 | case dropDatabaseRe.MatchString(stripped): |
| 155 | matched := dropDatabaseRe.FindStringSubmatch(stripped) |
| 156 | return &DropDatabaseStatement{DatabaseId: unquoteIdentifier(matched[1])}, nil |
| 157 | case dropRe.MatchString(stripped): |
| 158 | return &DdlStatement{Ddl: stripped}, nil |
| 159 | case alterRe.MatchString(stripped): |
| 160 | return &DdlStatement{Ddl: stripped}, nil |
| 161 | case renameRe.MatchString(stripped): |
| 162 | return &DdlStatement{Ddl: stripped}, nil |
| 163 | case grantRe.MatchString(stripped): |
| 164 | return &DdlStatement{Ddl: stripped}, nil |
| 165 | case revokeRe.MatchString(stripped): |
| 166 | return &DdlStatement{Ddl: stripped}, nil |
| 167 | case truncateTableRe.MatchString(stripped): |
| 168 | matched := truncateTableRe.FindStringSubmatch(stripped) |
| 169 | return &TruncateTableStatement{Table: unquoteIdentifier(matched[1])}, nil |
| 170 | case analyzeRe.MatchString(stripped): |
| 171 | return &DdlStatement{Ddl: stripped}, nil |
| 172 | case showDatabasesRe.MatchString(stripped): |
| 173 | return &ShowDatabasesStatement{}, nil |
| 174 | case showCreateTableRe.MatchString(stripped): |
| 175 | matched := showCreateTableRe.FindStringSubmatch(stripped) |
| 176 | schema, table := extractSchemaAndTable(unquoteIdentifier(matched[1])) |
| 177 | return &ShowCreateTableStatement{Schema: schema, Table: table}, nil |
| 178 | case showTablesRe.MatchString(stripped): |
| 179 | matched := showTablesRe.FindStringSubmatch(stripped) |
| 180 | return &ShowTablesStatement{Schema: unquoteIdentifier(matched[1])}, nil |
| 181 | case describeRe.MatchString(stripped): |
| 182 | matched := describeRe.FindStringSubmatch(stripped) |
| 183 | isDML := dmlRe.MatchString(matched[1]) |
| 184 | switch { |
| 185 | case isDML: |
| 186 | return &DescribeStatement{Statement: matched[1], IsDML: true}, nil |
| 187 | default: |
| 188 | return &DescribeStatement{Statement: matched[1]}, nil |
| 189 | } |
| 190 | case explainRe.MatchString(stripped): |
| 191 | matched := explainRe.FindStringSubmatch(stripped) |
| 192 | isAnalyze := matched[1] != "" |
| 193 | isDML := dmlRe.MatchString(matched[2]) |
| 194 | switch { |
| 195 | case isAnalyze && isDML: |
| 196 | return &ExplainAnalyzeDmlStatement{Dml: matched[2]}, nil |
| 197 | case isAnalyze: |
| 198 | return &ExplainAnalyzeStatement{Query: matched[2]}, nil |
no test coverage detected