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

Function ParseTiDB

backend/plugin/parser/tidb/tidb.go:104–123  ·  view source on GitHub ↗

ParseTiDB parses the given SQL statement and returns the AST.

(sql string, charset string, collation string)

Source from the content-addressed store, hash-verified

102
103// ParseTiDB parses the given SQL statement and returns the AST.
104func ParseTiDB(sql string, charset string, collation string) ([]ast.StmtNode, error) {
105 p := tidbparser.New()
106
107 // To support MySQL8 window function syntax.
108 // See https://github.com/bytebase/bytebase/issues/175.
109 p.EnableWindowFunc(true)
110 mode, err := mysql.GetSQLMode(mysql.DefaultSQLMode)
111 if err != nil {
112 return nil, errors.Errorf("failed to get sql mode: %v", err)
113 }
114 mode = mysql.DelSQLMode(mode, mysql.ModeNoZeroDate)
115 mode = mysql.DelSQLMode(mode, mysql.ModeNoZeroInDate)
116 p.SetSQLMode(mode)
117
118 nodes, _, err := p.Parse(sql, charset, collation)
119 if err != nil {
120 return nil, convertParserError(err)
121 }
122 return nodes, nil
123}
124
125var (
126 lineColumnRegex = regexp.MustCompile(`line (\d+) column (\d+)`)

Callers 5

validateQueryFunction · 0.85
TestTiDBParserErrorFunction · 0.85
DiagnoseFunction · 0.85
AsPingCapASTMethod · 0.85

Calls 2

convertParserErrorFunction · 0.85
ErrorfMethod · 0.80

Tested by 2

TestTiDBParserErrorFunction · 0.68