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

Function parseMySQLStatements

backend/plugin/parser/mysql/mysql.go:24–59  ·  view source on GitHub ↗

parseMySQLStatements is the ParseStatementsFunc for MySQL, MariaDB, and OceanBase. Returns []ParsedStatement with both text and AST populated.

(statement string)

Source from the content-addressed store, hash-verified

22// parseMySQLStatements is the ParseStatementsFunc for MySQL, MariaDB, and OceanBase.
23// Returns []ParsedStatement with both text and AST populated.
24func parseMySQLStatements(statement string) ([]base.ParsedStatement, error) {
25 // Split once to get Statement with text and positions
26 stmts, err := SplitSQL(statement)
27 if err != nil {
28 return nil, err
29 }
30
31 var result []base.ParsedStatement
32 for _, stmt := range stmts {
33 if stmt.Empty {
34 continue
35 }
36
37 list, omniErr := ParseMySQLOmni(stmt.Text)
38 if omniErr != nil {
39 return nil, convertOmniError(omniErr, stmt)
40 }
41
42 if list == nil || len(list.Items) == 0 {
43 continue
44 }
45
46 for _, node := range list.Items {
47 result = append(result, base.ParsedStatement{
48 Statement: stmt,
49 AST: &OmniAST{
50 Node: node,
51 Text: stmt.Text,
52 StartPosition: stmt.Start,
53 },
54 })
55 }
56 }
57
58 return result, nil
59}
60
61// convertOmniError converts an omni parser error to a base.SyntaxError with proper line:column position.
62func convertOmniError(err error, stmt base.Statement) error {

Callers

nothing calls this directly

Calls 3

ParseMySQLOmniFunction · 0.85
SplitSQLFunction · 0.70
convertOmniErrorFunction · 0.70

Tested by

no test coverage detected