MCPcopy Create free account
hub / github.com/dolthub/doltgresql / scanOneStmt

Method scanOneStmt

postgres/parser/parser/parse.go:132–172  ·  view source on GitHub ↗
(parse func(sqlStr string, tokens []sqlSymType) error)

Source from the content-addressed store, hash-verified

130}
131
132func (p *Parser) scanOneStmt(parse func(sqlStr string, tokens []sqlSymType) error) bool {
133 var lval sqlSymType
134 tokens := p.tokBuf[:0]
135
136 // Scan the first token.
137 for {
138 p.scanner.scan(&lval)
139 if lval.id == 0 {
140 return true
141 }
142 if lval.id != ';' {
143 break
144 }
145 }
146
147 startPos := lval.pos
148 // We make the resulting token positions match the returned string.
149 lval.pos = 0
150 tokens = append(tokens, lval)
151 for {
152 if lval.id == ERROR {
153 _ = parse(p.scanner.in[startPos:], tokens)
154 return true
155 }
156 posBeforeScan := p.scanner.pos
157 p.scanner.scan(&lval)
158 if lval.id == 0 || lval.id == ';' {
159 err := parse(p.scanner.in[startPos:posBeforeScan], tokens)
160 if lval.id == 0 || (err != nil && !strings.Contains(err.Error(), "EOF")) {
161 // done scanning all statements OR due to non EOF error
162 return true
163 } else if err == nil {
164 // done scanning single statement
165 return false
166 }
167 // continue scanning if it's EOF error
168 }
169 lval.pos -= startPos
170 tokens = append(tokens, lval)
171 }
172}
173
174func (p *Parser) parseWithDepth(depth int, sql string, nakedIntType *types.T) (Statements, error) {
175 stmts := Statements(p.stmtBuf[:0])

Callers 2

parseWithDepthMethod · 0.95
HasMultipleStatementsFunction · 0.95

Calls 3

scanMethod · 0.80
ContainsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected