MediaWiki REL1_28
IDatabase.php
Go to the documentation of this file.
1<?php
26use Wikimedia\ScopedCallback;
27
34interface IDatabase {
36 const TRIGGER_IDLE = 1;
38 const TRIGGER_COMMIT = 2;
40 const TRIGGER_ROLLBACK = 3;
41
43 const TRANSACTION_EXPLICIT = '';
45 const TRANSACTION_INTERNAL = 'implicit';
46
48 const FLUSHING_ALL_PEERS = 'flush';
50 const FLUSHING_INTERNAL = 'flush';
51
53 const REMEMBER_NOTHING = '';
55 const REMEMBER_PRIOR = 'remember';
57 const RESTORE_PRIOR = 'prior';
59 const RESTORE_INITIAL = 'initial';
60
62 const ESTIMATE_TOTAL = 'total';
64 const ESTIMATE_DB_APPLY = 'apply';
65
67 const LIST_COMMA = 0;
69 const LIST_AND = 1;
71 const LIST_SET = 2;
73 const LIST_NAMES = 3;
75 const LIST_OR = 4;
76
78 const DBO_DEBUG = 1;
80 const DBO_NOBUFFER = 2;
82 const DBO_IGNORE = 4;
84 const DBO_TRX = 8;
86 const DBO_DEFAULT = 16;
88 const DBO_PERSISTENT = 32;
90 const DBO_SYSDBA = 64;
92 const DBO_DDLMODE = 128;
94 const DBO_SSL = 256;
96 const DBO_COMPRESS = 512;
97
105 public function getServerInfo();
106
127 public function bufferResults( $buffer = null );
128
137 public function trxLevel();
138
148 public function trxTimestamp();
149
154 public function explicitTrxActive();
155
161 public function tablePrefix( $prefix = null );
162
168 public function dbSchema( $schema = null );
169
179 public function getLBInfo( $name = null );
180
189 public function setLBInfo( $name, $value = null );
190
197 public function setLazyMasterHandle( IDatabase $conn );
198
204 public function implicitGroupby();
205
212 public function implicitOrderby();
213
218 public function lastQuery();
219
226 public function doneWrites();
227
235 public function lastDoneWrites();
236
241 public function writesPending();
242
250 public function writesOrCallbacksPending();
251
261 public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL );
262
269 public function pendingWriteCallers();
270
275 public function isOpen();
276
289 public function setFlag( $flag, $remember = self::REMEMBER_NOTHING );
290
303 public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING );
304
311 public function restoreFlags( $state = self::RESTORE_PRIOR );
312
323 public function getFlag( $flag );
324
328 public function getDomainID();
329
335 public function getWikiID();
336
342 public function getType();
343
354 public function open( $server, $user, $password, $dbName );
355
366 public function fetchObject( $res );
367
377 public function fetchRow( $res );
378
385 public function numRows( $res );
386
394 public function numFields( $res );
395
404 public function fieldName( $res, $n );
405
418 public function insertId();
419
427 public function dataSeek( $res, $row );
428
435 public function lastErrno();
436
443 public function lastError();
444
454 public function fieldInfo( $table, $field );
455
462 public function affectedRows();
463
472 public function getSoftwareLink();
473
480 public function getServerVersion();
481
489 public function close();
490
495 public function reportConnectionError( $error = 'Unknown error' );
496
519 public function query( $sql, $fname = __METHOD__, $tempIgnore = false );
520
532 public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false );
533
541 public function freeResult( $res );
542
560 public function selectField(
561 $table, $var, $cond = '', $fname = __METHOD__, $options = []
562 );
563
582 public function selectFieldValues(
583 $table, $var, $cond = '', $fname = __METHOD__, $options = []
584 );
585
735 public function select(
736 $table, $vars, $conds = '', $fname = __METHOD__,
737 $options = [], $join_conds = []
738 );
739
756 public function selectSQLText(
757 $table, $vars, $conds = '', $fname = __METHOD__,
758 $options = [], $join_conds = []
759 );
760
775 public function selectRow( $table, $vars, $conds, $fname = __METHOD__,
776 $options = [], $join_conds = []
777 );
778
799 public function estimateRowCount(
800 $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = []
801 );
802
820 public function selectRowCount(
821 $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
822 );
823
832 public function fieldExists( $table, $field, $fname = __METHOD__ );
833
844 public function indexExists( $table, $index, $fname = __METHOD__ );
845
853 public function tableExists( $table, $fname = __METHOD__ );
854
863 public function indexUnique( $table, $index );
864
898 public function insert( $table, $a, $fname = __METHOD__, $options = [] );
899
918 public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] );
919
945 public function makeList( $a, $mode = self::LIST_COMMA );
946
957 public function makeWhereFrom2d( $data, $baseKey, $subKey );
958
967 public function aggregateValue( $valuedata, $valuename = 'value' );
968
973 public function bitNot( $field );
974
980 public function bitAnd( $fieldLeft, $fieldRight );
981
987 public function bitOr( $fieldLeft, $fieldRight );
988
995 public function buildConcat( $stringList );
996
1013 public function buildGroupConcatField(
1014 $delim, $table, $field, $conds = '', $join_conds = []
1015 );
1016
1022 public function buildStringCast( $field );
1023
1030 public function selectDB( $db );
1031
1036 public function getDBname();
1037
1042 public function getServer();
1043
1050 public function addQuotes( $s );
1051
1068 public function buildLike();
1069
1075 public function anyChar();
1076
1082 public function anyString();
1083
1095 public function nextSequenceValue( $seqName );
1096
1119 public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ );
1120
1155 public function upsert(
1156 $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
1157 );
1158
1179 public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
1180 $fname = __METHOD__
1181 );
1182
1193 public function delete( $table, $conds, $fname = __METHOD__ );
1194
1221 public function insertSelect( $destTable, $srcTable, $varMap, $conds,
1222 $fname = __METHOD__,
1223 $insertOptions = [], $selectOptions = []
1224 );
1225
1232
1241 public function unionQueries( $sqls, $all );
1242
1252 public function conditional( $cond, $trueVal, $falseVal );
1253
1264 public function strreplace( $orig, $old, $new );
1265
1271 public function getServerUptime();
1272
1278 public function wasDeadlock();
1279
1285 public function wasLockTimeout();
1286
1293 public function wasErrorReissuable();
1294
1300 public function wasReadOnlyError();
1301
1311 public function masterPosWait( DBMasterPos $pos, $timeout );
1312
1318 public function getReplicaPos();
1319
1325 public function getMasterPos();
1326
1331 public function serverIsReadOnly();
1332
1349 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
1350
1371 public function onTransactionIdle( callable $callback, $fname = __METHOD__ );
1372
1388 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
1389
1405 public function setTransactionListener( $name, callable $callback = null );
1406
1428 public function startAtomic( $fname = __METHOD__ );
1429
1441 public function endAtomic( $fname = __METHOD__ );
1442
1470 public function doAtomicSection( $fname, callable $callback );
1471
1492 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
1493
1514 public function commit( $fname = __METHOD__, $flush = '' );
1515
1534 public function rollback( $fname = __METHOD__, $flush = '' );
1535
1548 public function flushSnapshot( $fname = __METHOD__ );
1549
1558 public function listTables( $prefix = null, $fname = __METHOD__ );
1559
1571 public function timestamp( $ts = 0 );
1572
1586 public function timestampOrNull( $ts = null );
1587
1594 public function ping( &$rtt = null );
1595
1605 public function getLag();
1606
1620 public function getSessionLagStatus();
1621
1627 public function maxListLen();
1628
1638 public function encodeBlob( $b );
1639
1648 public function decodeBlob( $b );
1649
1661
1669 public function setSchemaVars( $vars );
1670
1679 public function lockIsFree( $lockName, $method );
1680
1691 public function lock( $lockName, $method, $timeout = 5 );
1692
1705 public function unlock( $lockName, $method );
1706
1728 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1729
1736 public function namedLocksEnqueue();
1737
1745 public function getInfinity();
1746
1753 public function encodeExpiry( $expiry );
1754
1762 public function decodeExpiry( $expiry, $format = TS_MW );
1763
1773 public function setBigSelects( $value = true );
1774
1779 public function isReadOnly();
1780
1794 public function setTableAliases( array $aliases );
1795
1800 public function getSearchEngine();
1801}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:36
$res
Definition database.txt:21
const LIST_NAMES
Definition Defines.php:37
const LIST_COMMA
Definition Defines.php:34
const LIST_SET
Definition Defines.php:36
const LIST_OR
Definition Defines.php:38
const LIST_AND
Definition Defines.php:35
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2162
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2568
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition hooks.txt:1028
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition hooks.txt:1096
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
An object representing a master or replica DB position in a replicated setup.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:34
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
fetchObject( $res)
Fetch the next row from the given result object, in object form.
getLBInfo( $name=null)
Get properties passed down from the server info array of the load balancer.
decodeBlob( $b)
Some DBMSs return a special placeholder object representing blob fields in result objects.
getWikiID()
Alias for getDomainID()
reportQueryError( $error, $errno, $sql, $fname, $tempIgnore=false)
Report a query error.
upsert( $table, array $rows, array $uniqueIndexes, array $set, $fname=__METHOD__)
INSERT ON DUPLICATE KEY UPDATE wrapper, upserts an array into a table.
insertSelect( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[])
INSERT SELECT wrapper.
lastErrno()
Get the last error number.
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
explicitTrxActive()
maxListLen()
Return the maximum number of items allowed in a list, or 0 for unlimited.
dataSeek( $res, $row)
Change the position of the cursor in a result object.
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way.
freeResult( $res)
Free a result object returned by query() or select().
decodeExpiry( $expiry, $format=TS_MW)
Decode an expiry time into a DBMS independent format.
close()
Closes a database connection.
timestampOrNull( $ts=null)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
addQuotes( $s)
Adds quotes and backslashes.
wasErrorReissuable()
Determines if the last query error was due to a dropped connection and should be dealt with by pingin...
unionQueries( $sqls, $all)
Construct a UNION query This is used for providing overload point for other DB abstractions not compa...
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback as soon as the current transaction commits or rolls back.
clearFlag( $flag, $remember=self::REMEMBER_NOTHING)
Clear a flag for this connection.
getDBname()
Get the current DB name.
setLazyMasterHandle(IDatabase $conn)
Set a lazy-connecting DB handle to the master DB (for replication status purposes)
ping(&$rtt=null)
Ping the server and try to reconnect if it there is no connection.
getServerUptime()
Determines how long the server has been up.
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
fieldName( $res, $n)
Get a field name in a result object.
buildStringCast( $field)
wasDeadlock()
Determines if the last failure was due to a deadlock.
insertId()
Get the inserted value of an auto-increment row.
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
The equivalent of IDatabase::select() except that the constructed SQL is returned,...
insert( $table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
selectRowCount( $tables, $vars=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Get the number of rows in dataset.
lockIsFree( $lockName, $method)
Check to see if a named lock is available (non-blocking)
getSearchEngine()
setBigSelects( $value=true)
Allow or deny "big selects" for this session only.
doneWrites()
Returns true if the connection may have been used for write queries.
bitAnd( $fieldLeft, $fieldRight)
aggregateValue( $valuedata, $valuename='value')
Return aggregated value alias.
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
DELETE where the condition is a join.
makeWhereFrom2d( $data, $baseKey, $subKey)
Build a partial where clause from a 2-d array such as used for LinkBatch.
encodeExpiry( $expiry)
Encode an expiry time into the DBMS dependent format.
flushSnapshot( $fname=__METHOD__)
Commit any transaction but error out if writes or callbacks are pending.
namedLocksEnqueue()
Check to see if a named lock used by lock() use blocking queues.
startAtomic( $fname=__METHOD__)
Begin an atomic section of statements.
open( $server, $user, $password, $dbName)
Open a connection to the database.
lastError()
Get a description of the last error.
numFields( $res)
Get the number of fields in a result object.
unlock( $lockName, $method)
Release a lock.
getSoftwareLink()
Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at ...
reportConnectionError( $error='Unknown error')
restoreFlags( $state=self::RESTORE_PRIOR)
Restore the flags to their prior state before the last setFlag/clearFlag call.
pendingWriteQueryDuration( $type=self::ESTIMATE_TOTAL)
Get the time spend running write queries for this transaction.
lastQuery()
Return the last query that went through IDatabase::query()
pendingWriteCallers()
Get the list of method names that did write queries for this transaction.
bufferResults( $buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
getInfinity()
Find out when 'infinity' is.
dbSchema( $schema=null)
Get/set the db schema.
unionSupportsOrderAndLimit()
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within th...
lock( $lockName, $method, $timeout=5)
Acquire a named lock.
writesOrCallbacksPending()
Returns true if there is a transaction open with possible write queries or transaction pre-commit/idl...
fieldInfo( $table, $field)
mysql_fetch_field() wrapper Returns false if the field doesn't exist
nextSequenceValue( $seqName)
Returns an appropriately quoted sequence value for inserting a new row.
getServer()
Get the server hostname or IP address.
wasReadOnlyError()
Determines if the last failure was due to the database being read-only.
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
selectDB( $db)
Change the current database.
buildLike()
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match conta...
makeList( $a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.
implicitOrderby()
Returns true if this database does an implicit order by when the column has an index For example: SEL...
doAtomicSection( $fname, callable $callback)
Run a callback to do an atomic set of updates for this database.
strreplace( $orig, $old, $new)
Returns a comand for str_replace function in SQL query.
begin( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
Begin a transaction.
setTransactionListener( $name, callable $callback=null)
Run a callback each time any transaction commits or rolls back.
update( $table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
lastDoneWrites()
Returns the last time the connection may have been used for write queries.
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
estimateRowCount( $table, $vars=' *', $conds='', $fname=__METHOD__, $options=[])
Estimate the number of rows in dataset.
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a single field from a single result row.
tablePrefix( $prefix=null)
Get/set the table prefix.
conditional( $cond, $trueVal, $falseVal)
Returns an SQL expression for a simple conditional.
anyString()
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
bitOr( $fieldLeft, $fieldRight)
getLag()
Get replica DB lag.
bitNot( $field)
getMasterPos()
Get the position of this master.
setSchemaVars( $vars)
Set variables to be used in sourceFile/sourceStream, in preference to the ones in $GLOBALS.
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
wasLockTimeout()
Determines if the last failure was due to a lock timeout.
fetchRow( $res)
Fetch the next row from the given result object, in associative array form.
setSessionOptions(array $options)
Override database's default behavior.
getFlag( $flag)
Returns a boolean whether the flag $flag is set for this connection.
setFlag( $flag, $remember=self::REMEMBER_NOTHING)
Set a flag for this connection.
setLBInfo( $name, $value=null)
Set the LB info array, or a member of it.
onTransactionPreCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback before the current transaction commits or now if there is none.
selectFieldValues( $table, $var, $cond='', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a list of single field values from result rows.
rollback( $fname=__METHOD__, $flush='')
Rollback a transaction previously started using begin().
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
replace( $table, $uniqueIndexes, $rows, $fname=__METHOD__)
REPLACE query wrapper.
onTransactionIdle(callable $callback, $fname=__METHOD__)
Run a callback as soon as there is no transaction pending.
encodeBlob( $b)
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strin...
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Single row SELECT wrapper.
indexExists( $table, $index, $fname=__METHOD__)
Determines whether an index exists Usually throws a DBQueryError on failure If errors are explicitly ...
affectedRows()
Get the number of rows affected by the last write query.
numRows( $res)
Get the number of rows in a result object.
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
implicitGroupby()
Returns true if this database does an implicit sort when doing GROUP BY.
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
indexUnique( $table, $index)
Determines if a given index is unique.
anyChar()
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
serverIsReadOnly()
commit( $fname=__METHOD__, $flush='')
Commits a transaction previously started using begin().
trxLevel()
Gets the current transaction level.
getSessionLagStatus()
Get the replica DB lag when the current transaction started or a general lag estimate if not transact...
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
masterPosWait(DBMasterPos $pos, $timeout)
Wait for the replica DB to catch up to a given master position.
isOpen()
Is a connection to the database open?
fieldExists( $table, $field, $fname=__METHOD__)
Determines whether a field exists in a table.
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
getReplicaPos()
Get the replication position of this replica DB.
$buffer
const DBO_NOBUFFER
Definition defines.php:7
const DBO_DDLMODE
Definition defines.php:13
const DBO_SYSDBA
Definition defines.php:12
const DBO_COMPRESS
Definition defines.php:15
const DBO_DEFAULT
Definition defines.php:10
const DBO_SSL
Definition defines.php:14
const DBO_IGNORE
Definition defines.php:8
const DBO_PERSISTENT
Definition defines.php:11
const DBO_DEBUG
Definition defines.php:6
const DBO_TRX
Definition defines.php:9
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition defines.php:11