SplitSQL splits the given SQL statement into multiple SQL statements. It uses omni's lexical splitter which handles quotes, dollar-quotes, comments, and BEGIN ATOMIC blocks without requiring valid SQL.
(statement string)
| 16 | // It uses omni's lexical splitter which handles quotes, dollar-quotes, |
| 17 | // comments, and BEGIN ATOMIC blocks without requiring valid SQL. |
| 18 | func SplitSQL(statement string) ([]base.Statement, error) { |
| 19 | segments := omnipg.Split(statement) |
| 20 | |
| 21 | result := make([]base.Statement, 0, len(segments)) |
| 22 | positionMapper := base.NewByteOffsetPositionMapper(statement) |
| 23 | for _, seg := range segments { |
| 24 | result = append(result, base.Statement{ |
| 25 | Text: seg.Text, |
| 26 | Empty: seg.Empty(), |
| 27 | Start: positionMapper.Position(seg.ByteStart), |
| 28 | End: positionMapper.Position(seg.ByteEnd), |
| 29 | Range: &storepb.Range{ |
| 30 | Start: int32(seg.ByteStart), |
| 31 | End: int32(seg.ByteEnd), |
| 32 | }, |
| 33 | }) |
| 34 | } |
| 35 | return result, nil |
| 36 | } |