MediaWiki master
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
39interface IDatabase extends IReadableDatabase {
41 public const TRIGGER_IDLE = 1;
43 public const TRIGGER_COMMIT = 2;
45 public const TRIGGER_ROLLBACK = 3;
47 public const TRIGGER_CANCEL = 4;
48
50 public const TRANSACTION_EXPLICIT = '';
52 public const TRANSACTION_INTERNAL = 'implicit';
53
55 public const ATOMIC_NOT_CANCELABLE = '';
57 public const ATOMIC_CANCELABLE = 'cancelable';
58
60 public const FLUSHING_ONE = '';
62 public const FLUSHING_ALL_PEERS = 'flush';
64 public const FLUSHING_INTERNAL = 'flush-internal';
65
67 public const ESTIMATE_TOTAL = 'total';
69 public const ESTIMATE_DB_APPLY = 'apply';
70
72 public const LOCK_TIMESTAMP = 1;
73
75 public const LB_TRX_ROUND_ID = 'trxRoundId';
77 public const LB_READ_ONLY_REASON = 'readOnlyReason';
78
80 public const ROLE_STREAMING_MASTER = 'streaming-master';
82 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
84 public const ROLE_STATIC_CLONE = 'static-clone';
86 public const ROLE_UNKNOWN = 'unknown';
87
96 public function trxLevel();
97
109 public function trxTimestamp();
110
120 public function explicitTrxActive();
121
130 public function getLBInfo( $name = null );
131
152 public function insertId();
153
176 public function affectedRows();
177
208 public function query( $sql, $fname = __METHOD__, $flags = 0 );
209
221
233
245
257
272 public function lockForUpdate(
273 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
274 );
275
300 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
301
340 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
341
378 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
379
420 public function upsert(
421 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
422 );
423
445 public function deleteJoin(
446 $delTable,
447 $joinTable,
448 $delVar,
449 $joinVar,
450 $conds,
451 $fname = __METHOD__
452 );
453
476 public function delete( $table, $conds, $fname = __METHOD__ );
477
511 public function insertSelect(
512 $destTable,
513 $srcTable,
514 $varMap,
515 $conds,
516 $fname = __METHOD__,
517 $insertOptions = [],
518 $selectOptions = [],
519 $selectJoinConds = []
520 );
521
554 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
555
590 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
591
621 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
622
646 public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ );
647
722 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
723
735 public function endAtomic( $fname = __METHOD__ );
736
762 public function cancelAtomic( $fname = __METHOD__, AtomicSectionIdentifier $sectionId = null );
763
836 public function doAtomicSection(
837 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
838 );
839
859 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
860
879 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
880
900 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
901
922 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
923
941 public function setSessionOptions( array $options );
942
952 public function lockIsFree( $lockName, $method );
953
966 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
967
978 public function unlock( $lockName, $method );
979
1001 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1002
1011 public function isReadOnly();
1012}
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.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
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:55
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:80
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
const ROLE_STATIC_CLONE
Replica server within a static dataset.
Definition IDatabase.php:84
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:60
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:52
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:45
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:75
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:82
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:69
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:64
const ROLE_UNKNOWN
Server with unknown topology role.
Definition IDatabase.php:86
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.
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:43
const TRIGGER_CANCEL
Callback triggered by atomic section cancel (ROLLBACK TO SAVEPOINT)
Definition IDatabase.php:47
const ESTIMATE_TOTAL
Estimate total time (RTT, scanning, waiting on locks, applying)
Definition IDatabase.php:67
const LB_READ_ONLY_REASON
Field for getLBInfo()/setLBInfo()
Definition IDatabase.php:77
const TRANSACTION_EXPLICIT
Transaction is requested by regular caller outside of the DB layer.
Definition IDatabase.php:50
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:72
newInsertQueryBuilder()
Get an InsertQueryBuilder bound to this connection.
const FLUSHING_ALL_PEERS
Commit/rollback is from the connection manager for the IDatabase handle.
Definition IDatabase.php:62
cancelAtomic( $fname=__METHOD__, AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
const ATOMIC_CANCELABLE
Atomic section is cancelable.
Definition IDatabase.php:57
const TRIGGER_IDLE
Callback triggered immediately due to no active transaction.
Definition IDatabase.php:41
isReadOnly()
Check if this DB server is marked as read-only according to load balancer info.
A database connection without write operations.