executeInAutoCommitMode executes statements sequentially in auto-commit mode
(ctx context.Context, conn *sql.Conn, commands []base.Statement, opts db.ExecuteOptions)
| 202 | |
| 203 | // executeInAutoCommitMode executes statements sequentially in auto-commit mode |
| 204 | func (*Driver) executeInAutoCommitMode(ctx context.Context, conn *sql.Conn, commands []base.Statement, opts db.ExecuteOptions) (int64, error) { |
| 205 | totalRowsAffected := int64(0) |
| 206 | for _, command := range commands { |
| 207 | opts.LogCommandExecute(command.Range, command.Text) |
| 208 | |
| 209 | sqlResult, err := conn.ExecContext(ctx, command.Text) |
| 210 | if err != nil { |
| 211 | opts.LogCommandResponse(0, nil, err.Error()) |
| 212 | // In auto-commit mode, we stop at the first error |
| 213 | // The database is left in a partially migrated state |
| 214 | return totalRowsAffected, err |
| 215 | } |
| 216 | rowsAffected, err := sqlResult.RowsAffected() |
| 217 | if err != nil { |
| 218 | // Since we cannot differentiate DDL and DML yet, we have to ignore the error. |
| 219 | slog.Debug("rowsAffected returns error", log.BBError(err)) |
| 220 | rowsAffected = 0 |
| 221 | } |
| 222 | opts.LogCommandResponse(rowsAffected, []int64{rowsAffected}, "") |
| 223 | totalRowsAffected += rowsAffected |
| 224 | } |
| 225 | return totalRowsAffected, nil |
| 226 | } |
| 227 | |
| 228 | // QueryConn queries a SQL statement in a given connection. |
| 229 | func (d *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string, queryContext db.QueryContext) ([]*v1pb.QueryResult, error) { |
no test coverage detected