executeSQL executes SQL statements, handling GO separators
(ctx context.Context, driver db.Driver, sql string)
| 32 | |
| 33 | // executeSQL executes SQL statements, handling GO separators |
| 34 | func executeSQL(ctx context.Context, driver db.Driver, sql string) error { |
| 35 | if strings.TrimSpace(sql) == "" { |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | // Split by GO statements (case insensitive) |
| 40 | statements := splitByGO(sql) |
| 41 | |
| 42 | for i, stmt := range statements { |
| 43 | stmt = strings.TrimSpace(stmt) |
| 44 | if stmt == "" { |
| 45 | continue |
| 46 | } |
| 47 | |
| 48 | if _, err := driver.Execute(ctx, stmt, db.ExecuteOptions{}); err != nil { |
| 49 | return errors.Wrapf(err, "failed to execute statement %d: %s", i+1, stmt) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | // splitByGO splits SQL by GO statements (case insensitive) or by semicolons if no GO statements |
| 57 | func splitByGO(sql string) []string { |
no test coverage detected