MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / parseSQL

Function parseSQL

pkg/transform/transform.go:110–132  ·  view source on GitHub ↗

parseSQL parses a full SQL statement and returns the first statement's AST.

(sql string)

Source from the content-addressed store, hash-verified

108
109// parseSQL parses a full SQL statement and returns the first statement's AST.
110func parseSQL(sql string) (ast.Statement, error) {
111 tkz := tokenizer.GetTokenizer()
112 defer tokenizer.PutTokenizer(tkz)
113
114 tokens, err := tkz.Tokenize([]byte(sql))
115 if err != nil {
116 return nil, fmt.Errorf("tokenize: %w", err)
117 }
118
119 p := parser.NewParser()
120 defer p.Release()
121
122 tree, err := p.ParseFromModelTokens(tokens)
123 if err != nil {
124 return nil, fmt.Errorf("parse: %w", err)
125 }
126
127 if tree == nil || len(tree.Statements) == 0 {
128 return nil, fmt.Errorf("no statements parsed")
129 }
130
131 return tree.Statements[0], nil
132}
133
134// parseCondition parses a SQL condition expression by wrapping it in a SELECT.
135func parseCondition(sql string) (ast.Expression, error) {

Callers 2

parseConditionFunction · 0.70
parseJoinClauseFunction · 0.70

Calls 7

ReleaseMethod · 0.95
ParseFromModelTokensMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
TokenizeMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected