MCPcopy Index your code
hub / github.com/bytebase/bytebase / validateQuery

Function validateQuery

backend/plugin/parser/plsql/query.go:16–44  ·  view source on GitHub ↗

validateQuery validates the SQL statement for SQL editor.

(statement string)

Source from the content-addressed store, hash-verified

14
15// validateQuery validates the SQL statement for SQL editor.
16func validateQuery(statement string) (bool, bool, error) {
17 for _, segment := range oracleparser.Split(statement) {
18 if segment.Kind == oracleparser.SegmentSQLPlusCommand && !segment.Empty() {
19 return false, false, nil
20 }
21 }
22
23 list, err := ParsePLSQLOmni(statement)
24 if err != nil {
25 return false, false, convertOmniError(err, base.Statement{Text: statement})
26 }
27 if list == nil || len(list.Items) == 0 {
28 return false, false, nil
29 }
30
31 for _, item := range list.Items {
32 raw, ok := item.(*oracleast.RawStmt)
33 if !ok || raw.Stmt == nil {
34 return false, false, nil
35 }
36 switch raw.Stmt.(type) {
37 case *oracleast.SelectStmt, *oracleast.ExplainPlanStmt:
38 default:
39 return false, false, nil
40 }
41 }
42
43 return true, true, nil
44}

Callers 1

TestValidateSQLForEditorFunction · 0.70

Calls 2

ParsePLSQLOmniFunction · 0.85
convertOmniErrorFunction · 0.70

Tested by 1

TestValidateSQLForEditorFunction · 0.56