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

Function SplitSQL

backend/plugin/parser/plsql/split.go:20–50  ·  view source on GitHub ↗

SplitSQL splits the given SQL statement into multiple SQL statements. It uses omni's lexical Oracle splitter, which handles strings, comments, SQL*Plus separators, and PL/SQL blocks without requiring valid SQL.

(statement string)

Source from the content-addressed store, hash-verified

18// It uses omni's lexical Oracle splitter, which handles strings, comments,
19// SQL*Plus separators, and PL/SQL blocks without requiring valid SQL.
20func SplitSQL(statement string) ([]base.Statement, error) {
21 segments := oracleparser.Split(statement)
22
23 result := make([]base.Statement, 0, len(segments))
24 positionMapper := base.NewByteOffsetPositionMapper(statement)
25 for i := 0; i < len(segments); i++ {
26 seg := segments[i]
27 if seg.Kind == oracleparser.SegmentSQLPlusCommand {
28 continue
29 }
30 byteStart := seg.ByteStart
31 byteEnd := seg.ByteEnd
32 if end, ok := matchRecognizeDefineMergeEnd(statement, segments, i); ok {
33 byteEnd = end
34 i += 2
35 }
36 byteEnd = byteStart + trimOracleSegmentTrailingHidden(statement[byteStart:byteEnd])
37 text := statement[byteStart:byteEnd]
38 result = append(result, base.Statement{
39 Text: text,
40 Start: positionMapper.Position(byteStart),
41 End: positionMapper.Position(byteEnd),
42 Empty: seg.Empty(),
43 Range: &storepb.Range{
44 Start: int32(byteStart),
45 End: int32(byteEnd),
46 },
47 })
48 }
49 return result, nil
50}
51
52func matchRecognizeDefineMergeEnd(statement string, segments []oracleparser.Segment, index int) (int, bool) {
53 if index+2 >= len(segments) {

Calls 4

PositionMethod · 0.95