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
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
93 public const LB_TRX_ROUND_FNAME = 'trxRoundOwner';
98 public const LB_READ_ONLY_REASON = 'readOnlyReason';
104
106 public const ROLE_STREAMING_MASTER = 'streaming-master';
108 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
110 public const ROLE_STATIC_CLONE = 'static-clone';
112 public const ROLE_UNKNOWN = 'unknown';
113
122 public function trxLevel();
123
135 public function trxTimestamp();
136
146 public function explicitTrxActive();
147
156 public function getLBInfo( $name = null );
157
178 public function insertId();
179
202 public function affectedRows();
203
234 public function query( $sql, $fname = __METHOD__, $flags = 0 );
235
247
259
271
283
298 public function lockForUpdate(
299 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
300 );
301
326 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
327
366 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
367
404 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
405
446 public function upsert(
447 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
448 );
449
471 public function deleteJoin(
472 $delTable,
473 $joinTable,
474 $delVar,
475 $joinVar,
476 $conds,
477 $fname = __METHOD__
478 );
479
502 public function delete( $table, $conds, $fname = __METHOD__ );
503
537 public function insertSelect(
538 $destTable,
539 $srcTable,
540 $varMap,
541 $conds,
542 $fname = __METHOD__,
543 $insertOptions = [],
544 $selectOptions = [],
545 $selectJoinConds = []
546 );
547
578 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
579
614 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
615
645 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
646
721 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
722
734 public function endAtomic( $fname = __METHOD__ );
735
761 public function cancelAtomic( $fname = __METHOD__, ?AtomicSectionIdentifier $sectionId = null );
762
835 public function doAtomicSection(
836 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
837 );
838
858 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
859
878 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
879
899 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
900
921 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
922
940 public function setSessionOptions( array $options );
941
951 public function lockIsFree( $lockName, $method );
952
965 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
966
977 public function unlock( $lockName, $method );
978
1000 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1001
1010 public function isReadOnly();
1011}
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.
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
const ROLE_STATIC_CLONE
Replica server within a static dataset.
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
Alias to LB_TRX_ROUND_FNAME.
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.
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.
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.
const LB_TRX_ROUND_FNAME
Field for getLBInfo()/setLBInfo()
Definition IDatabase.php:93
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:98
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.