ValidateSQLForEditor validates the SQL statement for SQL editor. We validate the statement by following steps: 1. Remove all quoted text(quoted identifier, string literal) and comments from the statement. 2. Use regexp to check if the statement is a normal SELECT statement and EXPLAIN statement. 3.
(statement string)
| 26 | // 2. Use regexp to check if the statement is a normal SELECT statement and EXPLAIN statement. |
| 27 | // 3. For CTE, use regexp to check if the statement has UPDATE, DELETE and INSERT statements. |
| 28 | func ValidateSQLForEditor(statement string) (bool, bool, error) { |
| 29 | textWithoutQuotedAndComment, err := tokenizer.StandardRemoveQuotedTextAndComment(statement) |
| 30 | if err != nil { |
| 31 | slog.Debug("Failed to remove quoted text and comment", slog.String("statement", statement), log.BBError(err)) |
| 32 | return false, false, err |
| 33 | } |
| 34 | |
| 35 | ok := CheckStatementWithoutQuotedTextAndComment(textWithoutQuotedAndComment) |
| 36 | return ok, ok, nil |
| 37 | } |
| 38 | |
| 39 | func CheckStatementWithoutQuotedTextAndComment(statement string) bool { |
| 40 | formattedStr := strings.ToUpper(strings.TrimSpace(statement)) |