ContainsDDL checks if any of the parsed statements is a DDL statement. When DDLs and DMLs are mixed, DML statements often reference objects created by DDL statements, causing false positives in dry run checks. BYT-8855
(engine storepb.Engine, parsedStatements []base.ParsedStatement)
| 142 | // by DDL statements, causing false positives in dry run checks. |
| 143 | // BYT-8855 |
| 144 | func ContainsDDL(engine storepb.Engine, parsedStatements []base.ParsedStatement) bool { |
| 145 | asts := base.ExtractASTs(parsedStatements) |
| 146 | types, err := base.GetStatementTypes(engine, asts) |
| 147 | if err != nil { |
| 148 | return false |
| 149 | } |
| 150 | for _, t := range types { |
| 151 | switch t { |
| 152 | case storepb.StatementType_STATEMENT_TYPE_UNSPECIFIED, |
| 153 | storepb.StatementType_INSERT, |
| 154 | storepb.StatementType_UPDATE, |
| 155 | storepb.StatementType_DELETE: |
| 156 | default: |
| 157 | return true |
| 158 | } |
| 159 | } |
| 160 | return false |
| 161 | } |
| 162 | |
| 163 | func DatabaseExists(ctx context.Context, checkCtx Context, database string) bool { |
| 164 | if checkCtx.ListDatabaseNamesFunc == nil { |