MCPcopy Create free account
hub / github.com/bytebase/bytebase / ContainsDDL

Function ContainsDDL

backend/plugin/advisor/utils.go:144–161  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

142// by DDL statements, causing false positives in dry run checks.
143// BYT-8855
144func 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
163func DatabaseExists(ctx context.Context, checkCtx Context, database string) bool {
164 if checkCtx.ListDatabaseNamesFunc == nil {

Callers 5

TestContainsDDLFunction · 0.92
CheckMethod · 0.92
CheckMethod · 0.92
CheckMethod · 0.92
CheckMethod · 0.92

Calls 2

ExtractASTsFunction · 0.92
GetStatementTypesFunction · 0.92

Tested by 1

TestContainsDDLFunction · 0.74