MediaWiki REL1_39
|
Advanced database interface for IDatabase handles that include maintenance methods. More...
Public Member Functions | |
deadlockLoop (... $args) | |
Perform a deadlock-prone transaction. | |
dropTable ( $table, $fname=__METHOD__) | |
Delete a table. | |
duplicateTableStructure ( $oldName, $newName, $temporary=false, $fname=__METHOD__) | |
Creates a new table with structure copied from existing table. | |
fieldExists ( $table, $field, $fname=__METHOD__) | |
Determines whether a field exists in a table. | |
fieldInfo ( $table, $field) | |
Get information about a field Returns false if the field doesn't exist. | |
indexExists ( $table, $index, $fname=__METHOD__) | |
Determines whether an index exists. | |
indexUnique ( $table, $index, $fname=__METHOD__) | |
Determines if a given index is unique. | |
listTables ( $prefix=null, $fname=__METHOD__) | |
List all tables on the database. | |
listViews ( $prefix=null, $fname=__METHOD__) | |
Lists all the VIEWs in the database. | |
sourceFile ( $filename, callable $lineCallback=null, callable $resultCallback=null, $fname=false, callable $inputCallback=null) | |
Read and execute SQL commands from a file. | |
sourceStream ( $fp, callable $lineCallback=null, callable $resultCallback=null, $fname=__METHOD__, callable $inputCallback=null) | |
Read and execute commands from an open file handle. | |
streamStatementEnd (&$sql, &$newLine) | |
Called by sourceStream() to check if we've reached a statement end. | |
tableExists ( $table, $fname=__METHOD__) | |
Query whether a given table exists. | |
textFieldSize ( $table, $field) | |
Returns the size of a text field, or -1 for "unlimited". | |
truncate ( $tables, $fname=__METHOD__) | |
Delete all data in a table(s) and reset any sequences owned by that table(s) | |
Public Member Functions inherited from Wikimedia\Rdbms\IDatabase | |
__toString () | |
Get a debugging string that mentions the database type, the ID of this instance, and the ID of any underlying connection resource or driver object if one is present. | |
affectedRows () | |
Get the number of rows affected by the last write query. | |
begin ( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT) | |
Begin a transaction. | |
cancelAtomic ( $fname=__METHOD__, AtomicSectionIdentifier $sectionId=null) | |
Cancel an atomic section of SQL statements. | |
clearFlag ( $flag, $remember=self::REMEMBER_NOTHING) | |
Clear a flag for this connection. | |
close ( $fname=__METHOD__) | |
Close the database connection. | |
commit ( $fname=__METHOD__, $flush=self::FLUSHING_ONE) | |
Commits a transaction previously started using begin() | |
databasesAreIndependent () | |
Returns true if DBs are assumed to be on potentially different servers. | |
dbSchema ( $schema=null) | |
Get/set the db schema. | |
decodeBlob ( $b) | |
Some DBMSs return a special placeholder object representing blob fields in result objects. | |
delete ( $table, $conds, $fname=__METHOD__) | |
Delete all rows in a table that match a condition. | |
deleteJoin ( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__) | |
Delete all rows in a table that match a condition which includes a join. | |
doAtomicSection ( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE) | |
Perform an atomic section of reversible SQL statements from a callback. | |
encodeBlob ( $b) | |
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted. | |
endAtomic ( $fname=__METHOD__) | |
Ends an atomic section of SQL statements. | |
estimateRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Estimate the number of rows in dataset. | |
explicitTrxActive () | |
Check whether there is a transaction open at the specific request of a caller. | |
flushSession ( $fname=__METHOD__, $flush=self::FLUSHING_ONE) | |
Release important session-level state (named lock, table locks) as post-rollback cleanup. | |
flushSnapshot ( $fname=__METHOD__, $flush=self::FLUSHING_ONE) | |
Commit any transaction but error out if writes or callbacks are pending. | |
getDBname () | |
Get the current database name; null if there isn't one. | |
getDomainID () | |
Return the currently selected domain ID. | |
getFlag ( $flag) | |
Returns a boolean whether the flag $flag is set for this connection. | |
getLag () | |
Get the amount of replication lag for this database server. | |
getLBInfo ( $name=null) | |
Get properties passed down from the server info array of the load balancer. | |
getPrimaryPos () | |
Get the position of this primary DB. | |
getReplicaPos () | |
Get the replication position of this replica DB. | |
getScopedLockAndFlush ( $lockKey, $fname, $timeout) | |
Acquire a named lock, flush any transaction, and return an RAII style unlocker object. | |
getServer () | |
Get the hostname or IP address of the server. | |
getServerInfo () | |
Get a human-readable string describing the current software version. | |
getServerName () | |
Get the readable name for the server. | |
getServerVersion () | |
A string describing the current software version, like from mysql_get_server_info() | |
getSessionLagStatus () | |
Get the replica DB lag when the current transaction started or a general lag estimate if not transaction is active. | |
getSoftwareLink () | |
Returns a wikitext style link to the DB's website (e.g. | |
getTopologyBasedServerId () | |
Get a non-recycled ID that uniquely identifies this server within the replication topology. | |
getTopologyRole () | |
Get the replication topology role of this server. | |
getType () | |
Get the RDBMS type of the server (e.g. | |
insert ( $table, $rows, $fname=__METHOD__, $options=[]) | |
Insert row(s) into a table, in the provided order. | |
insertId () | |
Get the inserted value of an auto-increment row. | |
insertSelect ( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[]) | |
INSERT SELECT wrapper. | |
isOpen () | |
isReadOnly () | |
lastDoneWrites () | |
Get the last time the connection may have been used for a write query. | |
lastErrno () | |
Get the RDBMS-specific error code from the last query statement. | |
lastError () | |
Get the RDBMS-specific error description from the last query statement. | |
lastQuery () | |
Get the last query that sent on account of IDatabase::query() | |
lock ( $lockName, $method, $timeout=5, $flags=0) | |
Acquire a named lock. | |
lockForUpdate ( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Lock all rows meeting the given conditions/options FOR UPDATE. | |
lockIsFree ( $lockName, $method) | |
Check to see if a named lock is not locked by any thread (non-blocking) | |
namedLocksEnqueue () | |
Check to see if a named lock used by lock() use blocking queues. | |
newSelectQueryBuilder () | |
Create an empty SelectQueryBuilder which can be used to run queries against this connection. | |
nextSequenceValue ( $seqName) | |
Deprecated method, calls should be removed. | |
onAtomicSectionCancel (callable $callback, $fname=__METHOD__) | |
Run a callback when the atomic section is cancelled. | |
onTransactionCommitOrIdle (callable $callback, $fname=__METHOD__) | |
Run a callback when the current transaction commits or now if there is none. | |
onTransactionPreCommitOrIdle (callable $callback, $fname=__METHOD__) | |
Run a callback before the current transaction commits or now if there is none. | |
onTransactionResolution (callable $callback, $fname=__METHOD__) | |
Run a callback when the current transaction commits or rolls back. | |
pendingWriteCallers () | |
Get the list of method names that did write queries for this transaction. | |
pendingWriteQueryDuration ( $type=self::ESTIMATE_TOTAL) | |
Get the time spend running write queries for this transaction. | |
ping (&$rtt=null) | |
Ping the server and try to reconnect if it there is no connection. | |
primaryPosWait (DBPrimaryPos $pos, $timeout) | |
Wait for the replica DB to catch up to a given primary DB position. | |
query ( $sql, $fname=__METHOD__, $flags=0) | |
Run an SQL query statement and return the result. | |
queryMulti (array $sqls, string $fname=__METHOD__, int $flags=0, ?string $summarySql=null) | |
Run a batch of SQL query statements and return the results. | |
replace ( $table, $uniqueKeys, $rows, $fname=__METHOD__) | |
Insert row(s) into a table, in the provided order, while deleting conflicting rows. | |
restoreFlags ( $state=self::RESTORE_PRIOR) | |
Restore the flags to their prior state before the last setFlag/clearFlag call. | |
rollback ( $fname=__METHOD__, $flush=self::FLUSHING_ONE) | |
Rollback a transaction previously started using begin() | |
select ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Execute a SELECT query constructed using the various parameters provided. | |
selectDB ( $db) | |
Change the current database. | |
selectDomain ( $domain) | |
Set the current domain (database, schema, and table prefix) | |
selectField ( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
A SELECT wrapper which returns a single field from a single result row. | |
selectFieldValues ( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
A SELECT wrapper which returns a list of single field values from result rows. | |
selectRow ( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[]) | |
Wrapper to IDatabase::select() that only fetches one row (via LIMIT) | |
selectRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Get the number of rows in dataset. | |
serverIsReadOnly () | |
setBigSelects ( $value=true) | |
Allow or deny "big selects" for this session only. | |
setFlag ( $flag, $remember=self::REMEMBER_NOTHING) | |
Set a flag for this connection. | |
setLBInfo ( $nameOrArray, $value=null) | |
Set the entire array or a particular key of the managing load balancer info array. | |
setSessionOptions (array $options) | |
Override database's default behavior. | |
setTransactionListener ( $name, callable $callback=null) | |
Run a callback after each time any transaction commits or rolls back. | |
startAtomic ( $fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE) | |
Begin an atomic section of SQL statements. | |
tablePrefix ( $prefix=null) | |
Get/set the table prefix. | |
trxLevel () | |
Gets the current transaction level. | |
trxTimestamp () | |
Get the UNIX timestamp of the time that the transaction was established. | |
unlock ( $lockName, $method) | |
Release a lock. | |
update ( $table, $set, $conds, $fname=__METHOD__, $options=[]) | |
Update all rows in a table that match a given condition. | |
upsert ( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__) | |
Upsert row(s) into a table, in the provided order, while updating conflicting rows. | |
wasConnectionLoss () | |
Determines if the last query error was due to a dropped connection. | |
wasDeadlock () | |
Determines if the last failure was due to a deadlock. | |
wasErrorReissuable () | |
Determines if the last query error was due to something outside of the query itself. | |
wasLockTimeout () | |
Determines if the last failure was due to a lock timeout. | |
wasReadOnlyError () | |
Determines if the last failure was due to the database being read-only. | |
writesOrCallbacksPending () | |
Whether there is a transaction open with either possible write queries or unresolved pre-commit/commit/resolution callbacks pending. | |
writesPending () | |
Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform | |
addIdentifierQuotes ( $s) | |
Escape a SQL identifier (e.g. | |
anyChar () | |
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query. | |
anyString () | |
Returns a token for buildLike() that denotes a '' to be used in a LIKE query. | |
bitAnd ( $fieldLeft, $fieldRight) | |
bitNot ( $field) | |
bitOr ( $fieldLeft, $fieldRight) | |
buildConcat ( $stringList) | |
Build a concatenation list to feed into a SQL query. | |
buildExcludedValue ( $column) | |
Build a reference to a column value from the conflicting proposed upsert() row. | |
buildGreatest ( $fields, $values) | |
Build a GREATEST function statement comparing columns/values. | |
buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[]) | |
Build a GROUP_CONCAT or equivalent statement for a query. | |
buildIntegerCast ( $field) | |
buildLeast ( $fields, $values) | |
Build a LEAST function statement comparing columns/values. | |
buildLike ( $param,... $params) | |
LIKE statement wrapper. | |
buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery. | |
buildStringCast ( $field) | |
buildSubString ( $input, $startPosition, $length=null) | |
Build a SUBSTRING function. | |
conditional ( $cond, $caseTrueExpression, $caseFalseExpression) | |
Returns an SQL expression for a simple conditional. | |
decodeExpiry ( $expiry, $format=TS_MW) | |
Decode an expiry time into a DBMS independent format. | |
encodeExpiry ( $expiry) | |
Encode an expiry time into the DBMS dependent format. | |
factorConds ( $condsArray) | |
Given an array of condition arrays representing an OR list of AND lists, for example: | |
getInfinity () | |
Find out when 'infinity' is. | |
getTableAliases () | |
Return current table aliases. | |
implicitOrderby () | |
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1. | |
limitResult ( $sql, $limit, $offset=false) | |
Construct a LIMIT query with optional offset. | |
makeList (array $a, $mode=self::LIST_COMMA) | |
Makes an encoded list of strings from an array. | |
makeWhereFrom2d ( $data, $baseKey, $subKey) | |
Build a partial where clause from a 2-d array such as used for LinkBatch. | |
selectSQLText ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Take the same arguments as IDatabase::select() and return the SQL it would use. | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. | |
setSchemaVars ( $vars) | |
Set schema variables to be used when streaming commands from SQL files or stdin. | |
setTableAliases (array $aliases) | |
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name. | |
strreplace ( $orig, $old, $new) | |
Returns a SQL expression for simple string replacement (e.g. | |
tableName ( $name, $format='quoted') | |
Format a table name ready for use in constructing an SQL query. | |
tableNames (... $tables) | |
Fetch a number of table names into an associative array. | |
tableNamesN (... $tables) | |
Fetch a number of table names into a zero-indexed numerical array. | |
timestamp ( $ts=0) | |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS. | |
timestampOrNull ( $ts=null) | |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS. | |
unionConditionPermutations ( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Construct a UNION query for permutations of conditions. | |
unionQueries ( $sqls, $all) | |
Construct a UNION query. | |
unionSupportsOrderAndLimit () | |
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION. | |
Public Member Functions inherited from Wikimedia\Rdbms\Database\DbQuoter | |
addQuotes ( $s) | |
Escape and quote a raw value string for use in a SQL query. | |
Additional Inherited Members | |
Public Attributes inherited from Wikimedia\Rdbms\IDatabase | |
const | LOCK_TIMESTAMP = 1 |
Flag to return the lock acquisition timestamp (null if not acquired) | |
Public Attributes inherited from Wikimedia\Rdbms\Platform\ISQLPlatform | |
const | QUERY_PSEUDO_PERMANENT = 2 |
Track a TEMPORARY table CREATE as if it was for a permanent table (for testing) | |
Advanced database interface for IDatabase handles that include maintenance methods.
This is useful for type-hints used by installer, upgrader, and background scripts that will make use of lower-level and longer-running queries, including schema changes.
Definition at line 34 of file IMaintainableDatabase.php.
Wikimedia\Rdbms\IMaintainableDatabase::deadlockLoop | ( | $args | ) |
Perform a deadlock-prone transaction.
This function invokes a callback function to perform a set of write queries. If a deadlock occurs during the processing, the transaction will be rolled back and the callback function will be called again.
Avoid using this method outside of Job or Maintenance classes.
Usage: $dbw->deadlockLoop( callback, ... );
Extra arguments are passed through to the specified callback function. This method requires that no transactions are already active to avoid causing premature commits or exceptions.
Returns whatever the callback function returned on its successful, iteration, or false on error, for example if the retry limit was reached.
mixed | ...$args |
DBUnexpectedError | |
Exception |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::dropTable | ( | $table, | |
$fname = __METHOD__ ) |
Delete a table.
string | $table | |
string | $fname |
DBError | If an error occurs |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::duplicateTableStructure | ( | $oldName, | |
$newName, | |||
$temporary = false, | |||
$fname = __METHOD__ ) |
Creates a new table with structure copied from existing table.
Note that unlike most database abstraction functions, this function does not automatically append database prefix, because it works at a lower abstraction level. The table names passed to this function shall not be quoted (this function calls addIdentifierQuotes() when needed).
string | $oldName | Name of table whose structure should be copied |
string | $newName | Name of table to be created |
bool | $temporary | Whether the new table should be temporary |
string | $fname | Calling function name |
RuntimeException |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::fieldExists | ( | $table, | |
$field, | |||
$fname = __METHOD__ ) |
Determines whether a field exists in a table.
string | $table | Table name |
string | $field | Field to check on that table |
string | $fname | Calling function name (optional) |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::fieldInfo | ( | $table, | |
$field ) |
Get information about a field Returns false if the field doesn't exist.
string | $table | Table name |
string | $field | Field name |
Implemented in Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::indexExists | ( | $table, | |
$index, | |||
$fname = __METHOD__ ) |
Determines whether an index exists.
string | $table | |
string | $index | |
string | $fname |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::indexUnique | ( | $table, | |
$index, | |||
$fname = __METHOD__ ) |
Determines if a given index is unique.
string | $table | |
string | $index | |
string | $fname | Calling function name |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::listTables | ( | $prefix = null, | |
$fname = __METHOD__ ) |
List all tables on the database.
string | null | $prefix | Only show tables with this prefix, e.g. mw_ |
string | $fname | Calling function name |
DBError |
Implemented in Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::listViews | ( | $prefix = null, | |
$fname = __METHOD__ ) |
Lists all the VIEWs in the database.
string | null | $prefix | Only show VIEWs with this prefix, eg. unit_test_ |
string | $fname | Name of calling function |
RuntimeException |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::sourceFile | ( | $filename, | |
callable | $lineCallback = null, | ||
callable | $resultCallback = null, | ||
$fname = false, | |||
callable | $inputCallback = null ) |
Read and execute SQL commands from a file.
Returns true on success, error string or exception on failure (depending on object's error ignore settings).
string | $filename | File name to open |
callable | null | $lineCallback | Optional function called before reading each line |
callable | null | $resultCallback | Optional function called for each MySQL result |
string | false | $fname | Calling function name or false if name should be generated dynamically using $filename |
callable | null | $inputCallback | Optional function called for each complete line sent |
Exception |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::sourceStream | ( | $fp, | |
callable | $lineCallback = null, | ||
callable | $resultCallback = null, | ||
$fname = __METHOD__, | |||
callable | $inputCallback = null ) |
Read and execute commands from an open file handle.
Returns true on success, error string or exception on failure (depending on object's error ignore settings).
resource | $fp | File handle |
callable | null | $lineCallback | Optional function called before reading each query |
callable | null | $resultCallback | Optional function called for each MySQL result |
string | $fname | Calling function name |
callable | null | $inputCallback | Optional function called for each complete query sent |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::streamStatementEnd | ( | & | $sql, |
& | $newLine ) |
Called by sourceStream() to check if we've reached a statement end.
string | &$sql | SQL assembled so far |
string | &$newLine | New line about to be added to $sql |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::tableExists | ( | $table, | |
$fname = __METHOD__ ) |
Query whether a given table exists.
string | $table | |
string | $fname |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::textFieldSize | ( | $table, | |
$field ) |
Returns the size of a text field, or -1 for "unlimited".
string | $table | |
string | $field |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IMaintainableDatabase::truncate | ( | $tables, | |
$fname = __METHOD__ ) |
Delete all data in a table(s) and reset any sequences owned by that table(s)
string | string[] | $tables | |
string | $fname |
DBError | If an error occurs |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.