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

Function validateQuery

backend/plugin/parser/doris/query.go:27–38  ·  view source on GitHub ↗

validateQuery reports whether the given statement is a read-only query suitable for the SQL editor / data-query path. Decision is AST-based: each parsed top-level statement must be a SELECT, SHOW, DESCRIBE, EXPLAIN, or HELP. Relying on leading-keyword classification alone would mis-accept CTE-prefi

(statement string)

Source from the content-addressed store, hash-verified

25// The (bool, bool, error) return shape matches the bytebase QueryValidator
26// contract: (isReadOnly, isExplicitReadOnly, syntaxError).
27func validateQuery(statement string) (bool, bool, error) {
28 parsed, err := parseDorisSQL(statement)
29 if err != nil {
30 return false, false, err
31 }
32 for _, p := range parsed {
33 if !isReadOnlyAST(p.Node()) {
34 return false, false, nil
35 }
36 }
37 return true, true, nil
38}
39
40// isReadOnlyAST returns true when the given top-level AST node represents a
41// read-only Doris statement (SELECT family, SHOW, DESCRIBE, EXPLAIN, HELP).

Callers 1

TestValidateQueryFunction · 0.70

Calls 3

parseDorisSQLFunction · 0.85
isReadOnlyASTFunction · 0.70
NodeMethod · 0.45

Tested by 1

TestValidateQueryFunction · 0.56