SplitSQL splits the input into multiple MongoDB statements. Unlike SQL-based engines that split on semicolons, MongoDB statements can be separated by newlines without semicolons, so we use the parser to identify statement boundaries.
(statement string)
| 16 | // separated by newlines without semicolons, so we use the parser to identify |
| 17 | // statement boundaries. |
| 18 | func SplitSQL(statement string) ([]base.Statement, error) { |
| 19 | stmts, err := ParseMongoShell(statement) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | |
| 24 | if len(stmts) == 0 { |
| 25 | if len(strings.TrimSpace(statement)) == 0 { |
| 26 | return nil, nil |
| 27 | } |
| 28 | return []base.Statement{{Text: statement}}, nil |
| 29 | } |
| 30 | |
| 31 | var result []base.Statement |
| 32 | for _, ps := range stmts { |
| 33 | result = append(result, ps.Statement) |
| 34 | } |
| 35 | return result, nil |
| 36 | } |