Transaction
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
Start a transaction.
Commit the transaction or release the previous savepoint.
[Asynchronously](pq/Connection/: Asynchronous Usage) commit the transaction or release the previous savepoint.
Export a large object to a local file.
Export a snapshot for transaction synchronization.
[Asynchronously](pq/Connection/: Asynchronous Usage) export a snapshot for transaction synchronization.
Import a local file into a large object.
Import a snapshot from another transaction to synchronize with.
[Asynchronously](pq/Connection/: Asynchronous Usage) import a snapshot from another transaction to synchronize with.
Rollback the transaction or to the previous savepoint within this transaction.
[Asynchronously](pq/Connection/: Asynchronous Usage) rollback the transaction or to the previous savepoint within this transaction.
Create a SAVEPOINT
within this transaction.
[Asynchronously](pq/Connection/: Asynchronous Usage) create a SAVEPOINT
within this transaction.
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().
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().
exportLOB(int $oid, string $path)
Export a large object to a local file.
See pq\Transaction::importLOB().
string
exportSnapshot()
Export a snapshot for transaction synchronization.
See pq\Transaction::importSnapshot().
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.
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.
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.
LOB
openLOB(int $oid, int $mode = \pq\LOB::RW)
Open a large object.
See pq\Transaction::createLOB().
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().