MediaWiki 1.43.1
IDatabase.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use Exception;
23use Wikimedia\ScopedCallback;
24
31// Very long type annotations :(
32// phpcs:disable Generic.Files.LineLength
33
48interface IDatabase extends IReadableDatabase {
50 public const TRIGGER_IDLE = 1;
52 public const TRIGGER_COMMIT = 2;
54 public const TRIGGER_ROLLBACK = 3;
56 public const TRIGGER_CANCEL = 4;
57
59 public const TRANSACTION_EXPLICIT = '';
61 public const TRANSACTION_INTERNAL = 'implicit';
62
64 public const ATOMIC_NOT_CANCELABLE = '';
66 public const ATOMIC_CANCELABLE = 'cancelable';
67
69 public const FLUSHING_ONE = '';
74 public const FLUSHING_ALL_PEERS = 'flush';
79 public const FLUSHING_INTERNAL = 'flush-internal';
80
82 public const ESTIMATE_TOTAL = 'total';
84 public const ESTIMATE_DB_APPLY = 'apply';
85
87 public const LOCK_TIMESTAMP = 1;
88
90 public const LB_TRX_ROUND_ID = 'trxRoundId';
92 public const LB_READ_ONLY_REASON = 'readOnlyReason';
93
95 public const ROLE_STREAMING_MASTER = 'streaming-master';
97 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
99 public const ROLE_STATIC_CLONE = 'static-clone';
101 public const ROLE_UNKNOWN = 'unknown';
102
111 public function trxLevel();
112
124 public function trxTimestamp();
125
135 public function explicitTrxActive();
136
145 public function getLBInfo( $name = null );
146
167 public function insertId();
168
191 public function affectedRows();
192
223 public function query( $sql, $fname = __METHOD__, $flags = 0 );
224
236
248
260
272
287 public function lockForUpdate(
288 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
289 );
290
315 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
316
355 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
356
393 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
394
435 public function upsert(
436 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
437 );
438
460 public function deleteJoin(
461 $delTable,
462 $joinTable,
463 $delVar,
464 $joinVar,
465 $conds,
466 $fname = __METHOD__
467 );
468
491 public function delete( $table, $conds, $fname = __METHOD__ );
492
526 public function insertSelect(
527 $destTable,
528 $srcTable,
529 $varMap,
530 $conds,
531 $fname = __METHOD__,
532 $insertOptions = [],
533 $selectOptions = [],
534 $selectJoinConds = []
535 );
536
569 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
570
605 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
606
636 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
637
661 public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ );
662
737 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
738
750 public function endAtomic( $fname = __METHOD__ );
751
777 public function cancelAtomic( $fname = __METHOD__, ?AtomicSectionIdentifier $sectionId = null );
778
851 public function doAtomicSection(
852 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
853 );
854
874 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
875
894 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
895
915 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
916
937 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
938
956 public function setSessionOptions( array $options );
957
967 public function lockIsFree( $lockName, $method );
968
981 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
982
993 public function unlock( $lockName, $method );
994
1016 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1017
1026 public function isReadOnly();
1027}
Class used for token representing identifiers for atomic sections from IDatabase instances.
A query builder for DELETE queries with a fluent interface.
Build INSERT queries with a fluent interface.
Build REPLACE queries with a fluent interface.
Build UPDATE queries with a fluent interface.
Interface to a relational database.
Definition IDatabase.php:48
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or rolls back.
onTransactionPreCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback before the current transaction commits or now if there is none.
flushSnapshot( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commit any transaction but error out if writes or callbacks are pending.
rollback( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Rollback a transaction previously started using begin()
setSessionOptions(array $options)
Override database's default behavior.
unlock( $lockName, $method)
Release a lock.
explicitTrxActive()
Check whether there is a transaction open at the specific request of a caller.
doAtomicSection( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Perform an atomic section of reversible SQL statements from a callback.
const ATOMIC_NOT_CANCELABLE
Atomic section is not cancelable.
Definition IDatabase.php:64
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
const ROLE_STREAMING_MASTER
Primary server than can stream writes to replica servers.
Definition IDatabase.php:95
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
const ROLE_STATIC_CLONE
Replica server within a static dataset.
Definition IDatabase.php:99
lockForUpdate( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Lock all rows meeting the given conditions/options FOR UPDATE.
getLBInfo( $name=null)
Get properties passed down from the server info array of the load balancer.
newUpdateQueryBuilder()
Get an UpdateQueryBuilder bound to this connection.
insertSelect( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
INSERT SELECT wrapper.
const FLUSHING_ONE
Commit/rollback is from outside the IDatabase handle and connection manager.
Definition IDatabase.php:69
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
Delete all rows in a table that match a condition which includes a join.
newDeleteQueryBuilder()
Get an DeleteQueryBuilder bound to this connection.
const TRANSACTION_INTERNAL
Transaction is requested internally via DBO_TRX/startAtomic()
Definition IDatabase.php:61
affectedRows()
Get the number of rows affected by the last query method call.
newReplaceQueryBuilder()
Get an ReplaceQueryBuilder bound to this connection.
const TRIGGER_ROLLBACK
Callback triggered by ROLLBACK.
Definition IDatabase.php:54
lockIsFree( $lockName, $method)
Check to see if a named lock is not locked by any thread (non-blocking)
const LB_TRX_ROUND_ID
Field for getLBInfo()/setLBInfo()
Definition IDatabase.php:90
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
const ROLE_STREAMING_REPLICA
Replica server that receives writes from a primary server.
Definition IDatabase.php:97
upsert( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__)
Upsert row(s) into a table, in the provided order, while updating conflicting rows.
const ESTIMATE_DB_APPLY
Estimate time to apply (scanning, applying)
Definition IDatabase.php:84
commit( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commits a transaction previously started using begin()
onTransactionCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or now if there is none.
const FLUSHING_INTERNAL
Commit/rollback is from the IDatabase handle internally.
Definition IDatabase.php:79
const ROLE_UNKNOWN
Server with unknown topology role.
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
onAtomicSectionCancel(callable $callback, $fname=__METHOD__)
Run a callback when the atomic section is cancelled.
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query statement and return the result.
cancelAtomic( $fname=__METHOD__, ?AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
begin( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
Begin a transaction.
insert( $table, $rows, $fname=__METHOD__, $options=[])
Insert row(s) into a table, in the provided order.
replace( $table, $uniqueKeys, $rows, $fname=__METHOD__)
Insert row(s) into a table, in the provided order, while deleting conflicting rows.
trxLevel()
Gets the current transaction level.
startAtomic( $fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Begin an atomic section of SQL statements.
insertId()
Get the sequence-based ID assigned by the last query method call.
const TRIGGER_COMMIT
Callback triggered by COMMIT.
Definition IDatabase.php:52
const TRIGGER_CANCEL
Callback triggered by atomic section cancel (ROLLBACK TO SAVEPOINT)
Definition IDatabase.php:56
const ESTIMATE_TOTAL
Estimate total time (RTT, scanning, waiting on locks, applying)
Definition IDatabase.php:82
const LB_READ_ONLY_REASON
Field for getLBInfo()/setLBInfo()
Definition IDatabase.php:92
const TRANSACTION_EXPLICIT
Transaction is requested by regular caller outside of the DB layer.
Definition IDatabase.php:59
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
const LOCK_TIMESTAMP
Flag to return the lock acquisition timestamp (null if not acquired)
Definition IDatabase.php:87
newInsertQueryBuilder()
Get an InsertQueryBuilder bound to this connection.
const FLUSHING_ALL_PEERS
Commit/rollback is from the owning connection manager for the IDatabase handle.
Definition IDatabase.php:74
const ATOMIC_CANCELABLE
Atomic section is cancelable.
Definition IDatabase.php:66
const TRIGGER_IDLE
Callback triggered immediately due to no active transaction.
Definition IDatabase.php:50
isReadOnly()
Check if this DB server is marked as read-only according to load balancer info.
A database connection without write operations.