class Transaction (View source)

A database transaction.

NOTE: Transactional properties like pq\Transaction::$isolation, pq\Transaction::$readonly and pq\Transaction::$deferrable can be changed after the transaction begun and the first query has been executed. Doing this will lead to appropriate SET TRANSACTION queries.

Constants

READ_COMMITTED

Transaction isolation level where only rows committed before the transaction began can be seen.

REPEATABLE_READ

Transaction isolation level where only rows committed before the first query was executed in this transaction.

SERIALIZABLE

Transaction isolation level that guarantees serializable repeatability which might lead to serialization_failure on high concurrency.

Properties

Connection read-only $connection

The connection the transaction was started on.

int $isolation

The transaction isolation level.

bool $readonly

Whether this transaction performs read only queries.

bool $deferrable

Whether the transaction is deferrable. See pq\Connection::startTransaction().

Methods

__construct(Connection $conn, bool $async = false, int $isolation = \pq\Transaction::READ_COMMITTED, bool $readonly = false, bool $deferrable = false)

Start a transaction.

commit()

Commit the transaction or release the previous savepoint.

commitAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) commit the transaction or release the previous savepoint.

LOB
createLOB(int $mode = \pq\LOB::RW)

Create a new large object and open it.

exportLOB(int $oid, string $path)

Export a large object to a local file.

string
exportSnapshot()

Export a snapshot for transaction synchronization.

exportSnapshotAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) export a snapshot for transaction synchronization.

int
importLOB(string $local_path, int $oid = \pq\LOB::INVALID_OID)

Import a local file into a large object.

importSnapshot(string $snapshot_id)

Import a snapshot from another transaction to synchronize with.

importSnapshotAsync(string $snapshot_id)

[Asynchronously](pq/Connection/: Asynchronous Usage) import a snapshot from another transaction to synchronize with.

LOB
openLOB(int $oid, int $mode = \pq\LOB::RW)

Open a large object.

rollback()

Rollback the transaction or to the previous savepoint within this transaction.

rollbackAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) rollback the transaction or to the previous savepoint within this transaction.

savepoint()

Create a SAVEPOINT within this transaction.

savepointAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) create a SAVEPOINT within this transaction.

LOB
unlinkLOB(int $oid)

Unlink a large object.

Details

__construct(Connection $conn, bool $async = false, int $isolation = \pq\Transaction::READ_COMMITTED, bool $readonly = false, bool $deferrable = false)

Start a transaction.

See pq\Connection::startTransaction().

Parameters

Connection $conn

The connection to start the transaction on.

bool $async

Whether to start the transaction [asynchronously](pq/Connection/: Asynchronous Usage).

int $isolation

The transaction isolation level (defaults to pq\Connection::$defaultTransactionIsolation).

bool $readonly

Whether the transaction is readonly (defaults to pq\Connection::$defaultTransactionReadonly).

bool $deferrable

Whether the transaction is deferrable (defaults to pq\Connection::$defaultTransactionDeferrable).

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

commit()

Commit the transaction or release the previous savepoint.

See pq\Transaction::savepoint().

commitAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) commit the transaction or release the previous savepoint.

See pq\Transaction::commit() and pq\Transaction::savepoint().

LOB createLOB(int $mode = \pq\LOB::RW)

Create a new large object and open it.

See pq\Transaction::openLOB().

Parameters

int $mode

How to open the large object (read, write or both; see pq\LOB constants).

Return Value

LOB

instance of the new large object.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

exportLOB(int $oid, string $path)

Export a large object to a local file.

See pq\Transaction::importLOB().

Parameters

int $oid

The OID of the large object.

string $path

The path of a local file to export to.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

string exportSnapshot()

Export a snapshot for transaction synchronization.

See pq\Transaction::importSnapshot().

Return Value

string

the snapshot identifier usable with pq\Transaction::importSnapshot().

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException
DomainException

exportSnapshotAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) export a snapshot for transaction synchronization.

See pq\Transaction::exportSnapshot().

int importLOB(string $local_path, int $oid = \pq\LOB::INVALID_OID)

Import a local file into a large object.

Parameters

string $local_path

A path to a local file to import.

int $oid

The target OID. A new large object will be created if INVALID_OID.

Return Value

int

the (new) OID of the large object.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

importSnapshot(string $snapshot_id)

Import a snapshot from another transaction to synchronize with.

See pq\Transaction::exportSnapshot().

NOTE: The transaction must have an isolation level of at least pq\Transaction::REPEATABLE_READ.

Parameters

string $snapshot_id

The snapshot identifier obtained by exporting a snapshot from a transaction.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException
DomainException

importSnapshotAsync(string $snapshot_id)

[Asynchronously](pq/Connection/: Asynchronous Usage) import a snapshot from another transaction to synchronize with.

See pq\Transaction::importSnapshot().

NOTE: The transaction must have an isolation level of at least pq\Transaction::REPEATABLE_READ.

Parameters

string $snapshot_id

The snapshot identifier obtained by exporting a snapshot from a transaction.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

LOB openLOB(int $oid, int $mode = \pq\LOB::RW)

Open a large object.

See pq\Transaction::createLOB().

Parameters

int $oid

The OID of the large object.

int $mode

Operational mode; read, write or both.

Return Value

LOB

instance of the opened large object.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException

rollback()

Rollback the transaction or to the previous savepoint within this transaction.

See pq\Transaction::commit() and pq\Transaction::savepoint().

rollbackAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) rollback the transaction or to the previous savepoint within this transaction.

See pq\Transaction::rollback() and pq\Transaction::savepoint().

savepoint()

Create a SAVEPOINT within this transaction.

NOTE: pq\Transaction tracks an internal counter as savepoint identifier.

savepointAsync()

[Asynchronously](pq/Connection/: Asynchronous Usage) create a SAVEPOINT within this transaction.

See pq\Transaction::savepoint().

LOB unlinkLOB(int $oid)

Unlink a large object.

See pq\Transaction::createLOB().

Parameters

int $oid

The OID of the large object.

Return Value

LOB

instance of the opened large object.

Exceptions

InvalidArgumentException
BadMethodCallException
RuntimeException