MCPcopy Index your code
hub / github.com/bytebase/bytebase / SplitTiDBMultiSQL

Method SplitTiDBMultiSQL

backend/plugin/parser/tokenizer/tokenizer.go:217–366  ·  view source on GitHub ↗

SplitTiDBMultiSQL splits the statement to a string slice.

()

Source from the content-addressed store, hash-verified

215
216// SplitTiDBMultiSQL splits the statement to a string slice.
217func (t *Tokenizer) SplitTiDBMultiSQL() ([]base.Statement, error) {
218 var res []base.Statement
219 delimiter := []rune{';'}
220
221 t.emptyStatement = true
222 // Record position BEFORE skipping whitespace to include leading whitespace in Text
223 startPos := t.cursor
224 startLine := t.line // Track the starting line number (1-based)
225 startColumn := t.getColumn() // Track the starting column (1-based)
226 t.skipBlank()
227 for {
228 switch {
229 case t.char(0) == eofRune:
230 s := t.getString(startPos, t.pos()-startPos)
231 if !emptyString(s) {
232 if t.f == nil {
233 res = append(res, base.Statement{
234 Text: s,
235 Start: &store.Position{
236 Line: int32(startLine),
237 Column: int32(startColumn),
238 },
239 // Consider this text:
240 // CREATE TABLE t(
241 // a int
242 // )
243 //
244 // EOF line
245 //
246 // Our current location is the EOF line.
247 // The line t.line is the line of ')',
248 // but we want to get the line of last line of the SQL
249 // which means the line of ')'.
250 // So we need minus the aboveNonBlankLineDistance.
251 End: &store.Position{
252 Line: int32(t.line - t.aboveNonBlankLineDistance()),
253 Column: int32(t.getLastContentColumn()),
254 },
255 Empty: t.emptyStatement,
256 Range: &store.Range{
257 Start: int32(t.getByteOffset(int(startPos))),
258 End: int32(t.getByteOffset(int(t.pos()))),
259 },
260 })
261 }
262 if err := t.processStreaming(s); err != nil {
263 return nil, err
264 }
265 }
266
267 return res, t.readErr
268 case t.equalWordCaseInsensitive(delimiter):
269 t.skip(uint(len(delimiter)))
270 text := t.getString(startPos, t.pos()-startPos)
271 if t.f == nil {
272 res = append(res, base.Statement{
273 Text: text,
274 Start: &store.Position{

Callers

nothing calls this directly

Calls 15

getColumnMethod · 0.95
skipBlankMethod · 0.95
charMethod · 0.95
getStringMethod · 0.95
posMethod · 0.95
getLastContentColumnMethod · 0.95
getByteOffsetMethod · 0.95
processStreamingMethod · 0.95
skipMethod · 0.95
skipToBlankMethod · 0.95

Tested by

no test coverage detected