validateQuery validates the SQL statement for SQL editor.
(statement string)
| 14 | |
| 15 | // validateQuery validates the SQL statement for SQL editor. |
| 16 | func 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 | } |