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

Function SplitSQL

backend/plugin/parser/standard/split.go:23–48  ·  view source on GitHub ↗

SplitSQL splits the given SQL statement into multiple SQL statements.

(statement string)

Source from the content-addressed store, hash-verified

21
22// SplitSQL splits the given SQL statement into multiple SQL statements.
23func SplitSQL(statement string) ([]base.Statement, error) {
24 var list []base.Statement
25 err := applyMultiStatements(statement, func(text string, start, end int) error {
26 startLine, startColumn := base.CalculateLineAndColumn(statement, start)
27 endLine, endColumn := base.CalculateLineAndColumn(statement, end)
28
29 list = append(list, base.Statement{
30 Text: text,
31 Start: &storepb.Position{
32 Line: int32(startLine + 1), // 1-based
33 Column: int32(startColumn + 1), // 1-based per proto spec
34 },
35 End: &storepb.Position{
36 Line: int32(endLine + 1), // 1-based
37 Column: int32(endColumn + 1), // 1-based per proto spec
38 },
39 Range: &storepb.Range{
40 Start: int32(start),
41 End: int32(end),
42 },
43 Empty: isEmptySQL(text),
44 })
45 return nil
46 })
47 return list, err
48}
49
50// isEmptySQL checks if the SQL contains only whitespace and comments.
51func isEmptySQL(sql string) bool {

Callers 3

QueryConnMethod · 0.92
ExecuteMethod · 0.92
TestSplitSQLWithBeginEndFunction · 0.50

Calls 3

CalculateLineAndColumnFunction · 0.92
applyMultiStatementsFunction · 0.85
isEmptySQLFunction · 0.85

Tested by 1

TestSplitSQLWithBeginEndFunction · 0.40