MCPcopy
hub / github.com/jackc/pgx / Rollback

Method Rollback

tx.go:209–223  ·  view source on GitHub ↗

Rollback rolls back the transaction. Rollback will return ErrTxClosed if the Tx is already closed, but is otherwise safe to call multiple times. Hence, a defer tx.Rollback() is safe even if tx.Commit() will be called first in a non-error condition.

(ctx context.Context)

Source from the content-addressed store, hash-verified

207// defer tx.Rollback() is safe even if tx.Commit() will be called first in a
208// non-error condition.
209func (tx *dbTx) Rollback(ctx context.Context) error {
210 if tx.closed {
211 return ErrTxClosed
212 }
213
214 _, err := tx.conn.Exec(ctx, "rollback")
215 tx.closed = true
216 if err != nil {
217 // A rollback failure leaves the connection in an undefined state
218 tx.conn.die()
219 return err
220 }
221
222 return nil
223}
224
225// Exec delegates to the underlying *Conn
226func (tx *dbTx) Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error) {

Callers

nothing calls this directly

Calls 2

dieMethod · 0.80
ExecMethod · 0.65

Tested by

no test coverage detected