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

Method Commit

tx.go:180–203  ·  view source on GitHub ↗

Commit commits the transaction.

(ctx context.Context)

Source from the content-addressed store, hash-verified

178
179// Commit commits the transaction.
180func (tx *dbTx) Commit(ctx context.Context) error {
181 if tx.closed {
182 return ErrTxClosed
183 }
184
185 commandSQL := "commit"
186 if tx.commitQuery != "" {
187 commandSQL = tx.commitQuery
188 }
189
190 commandTag, err := tx.conn.Exec(ctx, commandSQL)
191 tx.closed = true
192 if err != nil {
193 if tx.conn.PgConn().TxStatus() != 'I' {
194 _ = tx.conn.Close(ctx) // already have error to return
195 }
196 return err
197 }
198 if commandTag.String() == "ROLLBACK" {
199 return ErrTxCommitRollback
200 }
201
202 return nil
203}
204
205// Rollback rolls back the transaction. Rollback will return ErrTxClosed if the
206// Tx is already closed, but is otherwise safe to call multiple times. Hence, a

Callers

nothing calls this directly

Calls 5

TxStatusMethod · 0.80
PgConnMethod · 0.80
ExecMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected