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

Function ValidateSQLForEditor

backend/plugin/parser/tsql/query.go:17–35  ·  view source on GitHub ↗

ValidateSQLForEditor validates that every statement in the SQL is a read-only SELECT (no SELECT INTO). Returns (valid, allAlike, err). For MSSQL the two booleans move together — we reject on the first non-SELECT.

(statement string)

Source from the content-addressed store, hash-verified

15// SELECT (no SELECT INTO). Returns (valid, allAlike, err). For MSSQL the two
16// booleans move together — we reject on the first non-SELECT.
17func ValidateSQLForEditor(statement string) (bool, bool, error) {
18 stmts, err := ParseTSQLOmni(statement)
19 if err != nil {
20 return false, false, err
21 }
22 if len(stmts) == 0 {
23 return false, false, nil
24 }
25
26 for _, s := range stmts {
27 if s.Empty() {
28 continue
29 }
30 if !isReadOnlySelect(s.AST) {
31 return false, false, nil
32 }
33 }
34 return true, true, nil
35}
36
37// isReadOnlySelect returns true for SELECT statements without an INTO target.
38// Non-SELECT nodes and SELECT ... INTO are rejected — INTO materialises a new

Callers

nothing calls this directly

Calls 2

ParseTSQLOmniFunction · 0.85
isReadOnlySelectFunction · 0.85

Tested by

no test coverage detected