MediaWiki  master
IDatabase.php
Go to the documentation of this file.
1 <?php
2 
35 interface IDatabase {
36  /* Constants to onTransactionResolution() callbacks */
37  const TRIGGER_IDLE = 1;
38  const TRIGGER_COMMIT = 2;
39  const TRIGGER_ROLLBACK = 3;
40 
48  public function getServerInfo();
49 
71  public function bufferResults( $buffer = null );
72 
81  public function trxLevel();
82 
92  public function trxTimestamp();
93 
99  public function tablePrefix( $prefix = null );
100 
106  public function dbSchema( $schema = null );
107 
117  public function getLBInfo( $name = null );
118 
127  public function setLBInfo( $name, $value = null );
128 
134  public function implicitGroupby();
135 
142  public function implicitOrderby();
143 
148  public function lastQuery();
149 
156  public function doneWrites();
157 
165  public function lastDoneWrites();
166 
171  public function writesPending();
172 
179  public function writesOrCallbacksPending();
180 
189  public function pendingWriteQueryDuration();
190 
197  public function pendingWriteCallers();
198 
203  public function isOpen();
204 
216  public function setFlag( $flag );
217 
229  public function clearFlag( $flag );
230 
241  public function getFlag( $flag );
242 
249  public function getProperty( $name );
250 
254  public function getWikiID();
255 
261  public function getType();
262 
273  public function open( $server, $user, $password, $dbName );
274 
285  public function fetchObject( $res );
286 
296  public function fetchRow( $res );
297 
304  public function numRows( $res );
305 
313  public function numFields( $res );
314 
323  public function fieldName( $res, $n );
324 
337  public function insertId();
338 
346  public function dataSeek( $res, $row );
347 
354  public function lastErrno();
355 
362  public function lastError();
363 
373  public function fieldInfo( $table, $field );
374 
381  public function affectedRows();
382 
391  public function getSoftwareLink();
392 
399  public function getServerVersion();
400 
408  public function close();
409 
414  public function reportConnectionError( $error = 'Unknown error' );
415 
438  public function query( $sql, $fname = __METHOD__, $tempIgnore = false );
439 
451  public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false );
452 
460  public function freeResult( $res );
461 
479  public function selectField(
480  $table, $var, $cond = '', $fname = __METHOD__, $options = []
481  );
482 
501  public function selectFieldValues(
502  $table, $var, $cond = '', $fname = __METHOD__, $options = []
503  );
504 
654  public function select(
655  $table, $vars, $conds = '', $fname = __METHOD__,
656  $options = [], $join_conds = []
657  );
658 
675  public function selectSQLText(
676  $table, $vars, $conds = '', $fname = __METHOD__,
677  $options = [], $join_conds = []
678  );
679 
694  public function selectRow( $table, $vars, $conds, $fname = __METHOD__,
695  $options = [], $join_conds = []
696  );
697 
718  public function estimateRowCount(
719  $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = []
720  );
721 
739  public function selectRowCount(
740  $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
741  );
742 
751  public function fieldExists( $table, $field, $fname = __METHOD__ );
752 
763  public function indexExists( $table, $index, $fname = __METHOD__ );
764 
772  public function tableExists( $table, $fname = __METHOD__ );
773 
782  public function indexUnique( $table, $index );
783 
817  public function insert( $table, $a, $fname = __METHOD__, $options = [] );
818 
837  public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] );
838 
853  public function makeList( $a, $mode = LIST_COMMA );
854 
865  public function makeWhereFrom2d( $data, $baseKey, $subKey );
866 
871  public function bitNot( $field );
872 
878  public function bitAnd( $fieldLeft, $fieldRight );
879 
885  public function bitOr( $fieldLeft, $fieldRight );
886 
893  public function buildConcat( $stringList );
894 
911  public function buildGroupConcatField(
912  $delim, $table, $field, $conds = '', $join_conds = []
913  );
914 
921  public function selectDB( $db );
922 
927  public function getDBname();
928 
933  public function getServer();
934 
941  public function addQuotes( $s );
942 
959  public function buildLike();
960 
966  public function anyChar();
967 
973  public function anyString();
974 
986  public function nextSequenceValue( $seqName );
987 
1010  public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ );
1011 
1046  public function upsert(
1047  $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
1048  );
1049 
1070  public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
1071  $fname = __METHOD__
1072  );
1073 
1084  public function delete( $table, $conds, $fname = __METHOD__ );
1085 
1112  public function insertSelect( $destTable, $srcTable, $varMap, $conds,
1113  $fname = __METHOD__,
1114  $insertOptions = [], $selectOptions = []
1115  );
1116 
1122  public function unionSupportsOrderAndLimit();
1123 
1132  public function unionQueries( $sqls, $all );
1133 
1143  public function conditional( $cond, $trueVal, $falseVal );
1144 
1155  public function strreplace( $orig, $old, $new );
1156 
1163  public function getServerUptime();
1164 
1171  public function wasDeadlock();
1172 
1179  public function wasLockTimeout();
1180 
1188  public function wasErrorReissuable();
1189 
1196  public function wasReadOnlyError();
1197 
1207  public function masterPosWait( DBMasterPos $pos, $timeout );
1208 
1214  public function getSlavePos();
1215 
1221  public function getMasterPos();
1222 
1227  public function serverIsReadOnly();
1228 
1244  public function onTransactionResolution( callable $callback );
1245 
1265  public function onTransactionIdle( callable $callback );
1266 
1281  public function onTransactionPreCommitOrIdle( callable $callback );
1282 
1307  public function startAtomic( $fname = __METHOD__ );
1308 
1320  public function endAtomic( $fname = __METHOD__ );
1321 
1348  public function doAtomicSection( $fname, callable $callback );
1349 
1365  public function begin( $fname = __METHOD__ );
1366 
1385  public function commit( $fname = __METHOD__, $flush = '' );
1386 
1401  public function rollback( $fname = __METHOD__, $flush = '' );
1402 
1411  public function listTables( $prefix = null, $fname = __METHOD__ );
1412 
1424  public function timestamp( $ts = 0 );
1425 
1439  public function timestampOrNull( $ts = null );
1440 
1446  public function ping();
1447 
1457  public function getLag();
1458 
1472  public function getSessionLagStatus();
1473 
1479  public function maxListLen();
1480 
1490  public function encodeBlob( $b );
1491 
1500  public function decodeBlob( $b );
1501 
1512  public function setSessionOptions( array $options );
1513 
1521  public function setSchemaVars( $vars );
1522 
1531  public function lockIsFree( $lockName, $method );
1532 
1543  public function lock( $lockName, $method, $timeout = 5 );
1544 
1557  public function unlock( $lockName, $method );
1558 
1576  public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1577 
1584  public function namedLocksEnqueue();
1585 
1593  public function getInfinity();
1594 
1601  public function encodeExpiry( $expiry );
1602 
1610  public function decodeExpiry( $expiry, $format = TS_MW );
1611 
1621  public function setBigSelects( $value = true );
1622 
1627  public function isReadOnly();
1628 }
lastDoneWrites()
Returns the last time the connection may have been used for write queries.
setSchemaVars($vars)
Set variables to be used in sourceFile/sourceStream, in preference to the ones in $GLOBALS...
anyString()
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
insert($table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
selectRow($table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Single row SELECT wrapper.
const TRIGGER_COMMIT
Definition: IDatabase.php:38
the array() calling protocol came about after MediaWiki 1.4rc1.
wasErrorReissuable()
Determines if the last query error was something that should be dealt with by pinging the connection ...
dbSchema($schema=null)
Get/set the db schema.
getDBname()
Get the current DB name.
lastQuery()
Return the last query that went through IDatabase::query()
makeList($a, $mode=LIST_COMMA)
Makes an encoded list of strings from an array.
indexExists($table, $index, $fname=__METHOD__)
Determines whether an index exists Usually throws a DBQueryError on failure If errors are explicitly ...
begin($fname=__METHOD__)
Begin a transaction.
close()
Closes a database connection.
open($server, $user, $password, $dbName)
Open a connection to the database.
isOpen()
Is a connection to the database open?
query($sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
getMasterPos()
Get the position of this master.
unionQueries($sqls, $all)
Construct a UNION query This is used for providing overload point for other DB abstractions not compa...
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way...
lock($lockName, $method, $timeout=5)
Acquire a named lock.
$value
onTransactionResolution(callable $callback)
Run a callback as soon as the current transaction commits or rolls back.
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
fieldName($res, $n)
Get a field name in a result object.
bitAnd($fieldLeft, $fieldRight)
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
tableExists($table, $fname=__METHOD__)
Query whether a given table exists.
lastError()
Get a description of the last error.
selectDB($db)
Change the current database.
An object representing a master or slave position in a replicated setup.
upsert($table, array $rows, array $uniqueIndexes, array $set, $fname=__METHOD__)
INSERT ON DUPLICATE KEY UPDATE wrapper, upserts an array into a table.
fieldInfo($table, $field)
mysql_fetch_field() wrapper Returns false if the field doesn't exist
timestamp($ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
const TRIGGER_ROLLBACK
Definition: IDatabase.php:39
ping()
Ping the server and try to reconnect if it there is no connection.
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
lastErrno()
Get the last error number.
getInfinity()
Find out when 'infinity' is.
masterPosWait(DBMasterPos $pos, $timeout)
Wait for the slave to catch up to a given master position.
const TRIGGER_IDLE
Definition: IDatabase.php:37
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:981
trxLevel()
Gets the current transaction level.
estimateRowCount($table, $vars= '*', $conds= '', $fname=__METHOD__, $options=[])
Estimate the number of rows in dataset.
maxListLen()
Return the maximum number of items allowed in a list, or 0 for unlimited.
affectedRows()
Get the number of rows affected by the last write query.
setLBInfo($name, $value=null)
Set the LB info array, or a member of it.
dataSeek($res, $row)
Change the position of the cursor in a result object.
lockIsFree($lockName, $method)
Check to see if a named lock is available (non-blocking)
makeWhereFrom2d($data, $baseKey, $subKey)
Build a partial where clause from a 2-d array such as used for LinkBatch.
reportConnectionError($error= 'Unknown error')
wasLockTimeout()
Determines if the last failure was due to a lock timeout STUB.
getSessionLagStatus()
Get the slave lag when the current transaction started or a general lag estimate if not transaction i...
listTables($prefix=null, $fname=__METHOD__)
List all tables on the database.
pendingWriteQueryDuration()
Get the time spend running write queries for this transaction.
onTransactionIdle(callable $callback)
Run a callback as soon as there is no transaction pending.
getLag()
Get slave lag.
selectSQLText($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
The equivalent of IDatabase::select() except that the constructed SQL is returned, instead of being immediately executed.
timestampOrNull($ts=null)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
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:1020
selectFieldValues($table, $var, $cond= '', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a list of single field values from result rows.
fetchObject($res)
Fetch the next row from the given result object, in object form.
const LIST_COMMA
Definition: Defines.php:193
freeResult($res)
Free a result object returned by query() or select().
unlock($lockName, $method)
Release a lock.
$res
Definition: database.txt:21
setFlag($flag)
Set a flag for this connection.
namedLocksEnqueue()
Check to see if a named lock used by lock() use blocking queues.
buildGroupConcatField($delim, $table, $field, $conds= '', $join_conds=[])
Build a GROUP_CONCAT or equivalent statement for a query.
bufferResults($buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
writesOrCallbacksPending()
Returns true if there is a transaction open with possible write queries or transaction pre-commit/idl...
onTransactionPreCommitOrIdle(callable $callback)
Run a callback before the current transaction commits or now if there is none.
selectField($table, $var, $cond= '', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a single field from a single result row.
clearFlag($flag)
Clear a flag for this connection.
$buffer
selectRowCount($tables, $vars= '*', $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
Get the number of rows in dataset.
endAtomic($fname=__METHOD__)
Ends an atomic section of SQL statements.
bitOr($fieldLeft, $fieldRight)
getFlag($flag)
Returns a boolean whether the flag $flag is set for this connection.
deleteJoin($delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
DELETE where the condition is a join.
serverIsReadOnly()
wasDeadlock()
Determines if the last failure was due to a deadlock STUB.
fieldExists($table, $field, $fname=__METHOD__)
Determines whether a field exists in a table.
decodeExpiry($expiry, $format=TS_MW)
Decode an expiry time into a DBMS independent format.
buildConcat($stringList)
Build a concatenation list to feed into a SQL query.
replace($table, $uniqueIndexes, $rows, $fname=__METHOD__)
REPLACE query wrapper.
startAtomic($fname=__METHOD__)
Begin an atomic section of statements.
fetchRow($res)
Fetch the next row from the given result object, in associative array form.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
numRows($res)
Get the number of rows in a result object.
getServerUptime()
Determines how long the server has been up STUB.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
commit($fname=__METHOD__, $flush= '')
Commits a transaction previously started using begin().
strreplace($orig, $old, $new)
Returns a comand for str_replace function in SQL query.
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:35
anyChar()
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
buildLike()
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match conta...
doneWrites()
Returns true if the connection may have been used for write queries.
implicitOrderby()
Returns true if this database does an implicit order by when the column has an index For example: SEL...
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:36
nextSequenceValue($seqName)
Returns an appropriately quoted sequence value for inserting a new row.
getSoftwareLink()
Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at ...
bitNot($field)
pendingWriteCallers()
Get the list of method names that did write queries for this transaction.
insertId()
Get the inserted value of an auto-increment row.
doAtomicSection($fname, callable $callback)
Run a callback to do an atomic set of updates for this database.
insertSelect($destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[])
INSERT SELECT wrapper.
getServer()
Get the server hostname or IP address.
unionSupportsOrderAndLimit()
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within th...
encodeExpiry($expiry)
Encode an expiry time into the DBMS dependent format.
tablePrefix($prefix=null)
Get/set the table prefix.
getLBInfo($name=null)
Get properties passed down from the server info array of the load balancer.
encodeBlob($b)
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strin...
addQuotes($s)
Adds quotes and backslashes.
rollback($fname=__METHOD__, $flush= '')
Rollback a transaction previously started using begin().
decodeBlob($b)
Some DBMSs return a special placeholder object representing blob fields in result objects...
setBigSelects($value=true)
Allow or deny "big selects" for this session only.
select($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
getSlavePos()
Get the replication position of this slave.
indexUnique($table, $index)
Determines if a given index is unique.
reportQueryError($error, $errno, $sql, $fname, $tempIgnore=false)
Report a query error.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2044
conditional($cond, $trueVal, $falseVal)
Returns an SQL expression for a simple conditional.
numFields($res)
Get the number of fields in a result object.
getProperty($name)
General read-only accessor.
implicitGroupby()
Returns true if this database does an implicit sort when doing GROUP BY.
getScopedLockAndFlush($lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
update($table, $values, $conds, $fname=__METHOD__, $options=[])
UPDATE wrapper.
wasReadOnlyError()
Determines if the last failure was due to the database being read-only.
Basic database interface for live and lazy-loaded DB handles.
Definition: IDatabase.php:35
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310
setSessionOptions(array $options)
Override database's default behavior.