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

Function ValidateSQLForEditor

backend/plugin/parser/standard/query.go:28–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
28func 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
39func CheckStatementWithoutQuotedTextAndComment(statement string) bool {
40 formattedStr := strings.ToUpper(strings.TrimSpace(statement))

Callers 1

Calls 5

BBErrorFunction · 0.92
DebugMethod · 0.80
StringMethod · 0.65

Tested by 1