executeInAutoCommitMode executes statements sequentially in auto-commit mode
(ctx context.Context, commands []base.Statement, opts db.ExecuteOptions)
| 289 | |
| 290 | // executeInAutoCommitMode executes statements sequentially in auto-commit mode |
| 291 | func (d *Driver) executeInAutoCommitMode(ctx context.Context, commands []base.Statement, opts db.ExecuteOptions) (int64, error) { |
| 292 | totalRowsAffected := int64(0) |
| 293 | |
| 294 | for i, command := range commands { |
| 295 | opts.LogCommandExecute(command.Range, command.Text) |
| 296 | // Log the query statement in char code to see if there are some control characters that cause issues. |
| 297 | var charCode []rune |
| 298 | for _, r := range command.Text { |
| 299 | charCode = append(charCode, r) |
| 300 | } |
| 301 | slog.Debug("executing command", slog.Any("command", charCode), slog.Int("index", i)) |
| 302 | sqlResult, err := d.db.ExecContext(ctx, command.Text) |
| 303 | if err != nil { |
| 304 | opts.LogCommandResponse(0, nil, err.Error()) |
| 305 | // In auto-commit mode, we stop at the first error |
| 306 | // The database is left in a partially migrated state |
| 307 | return totalRowsAffected, err |
| 308 | } |
| 309 | rowsAffected, err := sqlResult.RowsAffected() |
| 310 | if err != nil { |
| 311 | // Since we cannot differentiate DDL and DML yet, we have to ignore the error. |
| 312 | slog.Debug("rowsAffected returns error", log.BBError(err)) |
| 313 | } |
| 314 | opts.LogCommandResponse(rowsAffected, nil, "") |
| 315 | totalRowsAffected += rowsAffected |
| 316 | } |
| 317 | |
| 318 | return totalRowsAffected, nil |
| 319 | } |
| 320 | |
| 321 | func getDatabaseInCreateDatabaseStatement(createDatabaseStatement string) (string, error) { |
| 322 | raw := strings.TrimRight(createDatabaseStatement, ";") |
no test coverage detected