SplitSQL splits the given SQL statement into multiple SQL statements. It uses omni's lexical splitter which handles quotes, comments, compound statements (BEGIN...END, IF...END IF, etc.) and DELIMITER without requiring valid SQL.
(statement string)
| 18 | // statements (BEGIN...END, IF...END IF, etc.) and DELIMITER without |
| 19 | // requiring valid SQL. |
| 20 | func SplitSQL(statement string) ([]base.Statement, error) { |
| 21 | segments := mysqlparser.Split(statement) |
| 22 | |
| 23 | result := make([]base.Statement, 0, len(segments)) |
| 24 | positionMapper := base.NewByteOffsetPositionMapper(statement) |
| 25 | for _, seg := range segments { |
| 26 | result = append(result, base.NewStatementFromRange(statement, positionMapper, seg.ByteStart, seg.ByteEnd, seg.Empty())) |
| 27 | } |
| 28 | return result, nil |
| 29 | } |