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)
| 25 | // The (bool, bool, error) return shape matches the bytebase QueryValidator |
| 26 | // contract: (isReadOnly, isExplicitReadOnly, syntaxError). |
| 27 | func 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). |