*
* @param $wiki String
* @param $bits String
+ *
+ * @return array
*/
function wfSplitWikiID( $wiki ) {
$bits = explode( '-', $wiki, 2 );
protected $mDefaultBigSelects = null;
protected $mSchemaVars = false;
+ protected $preparedArgs;
+
# ------------------------------------------------------------------------------
# Accessors
# ------------------------------------------------------------------------------
* code should use lastErrno() and lastError() to handle the
* situation as appropriate.
*
- * @param $ignoreErrors
+ * @param $ignoreErrors bool|null
*
* @return The previous value of the flag.
*/
/**
* 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
+ *
+ * @return bool
*/
function implicitOrderby() {
return true;
/**
* General read-only accessor
+ *
+ * @param $name string
+ *
+ * @return string
*/
function getProperty( $name ) {
return $this->$name;
* The DBMS-dependent part of query()
*
* @param $sql String: SQL query.
- * @return Result object to feed to fetchObject, fetchRow, ...; or false on failure
+ * @return ResultWrapper Result object to feed to fetchObject, fetchRow, ...; or false on failure
*/
protected abstract function doQuery( $sql );
* @param $options Array Query options
* @param $join_conds Array Join conditions
*
- *
* @param $table string|array
*
* May be either an array of table names, or a single string holding a table
* Takes the same arguments as DatabaseBase::select().
*
* @param $table String: table name
- * @param $vars Array: unused
- * @param $conds Array: filters on the table
+ * @param Array|string $vars : unused
+ * @param Array|string $conds : filters on the table
* @param $fname String: function name for profiling
* @param $options Array: options for select
* @return Integer: row count
return false;
}
+ /**
+ * @param $key
+ * @param $fallback
+ * @return string
+ */
function msg( $key, $fallback /*[, params...] */ ) {
global $wgLang;
* @see Database
*/
class DatabaseMysql extends DatabaseBase {
+
+ /**
+ * @return string
+ */
function getType() {
return 'mysql';
}
return $success;
}
+ /**
+ * @return bool
+ */
function close() {
$this->mOpened = false;
if ( $this->mConn ) {
return $row;
}
+ /**
+ * @throws DBUnexpectedError
+ * @param $res
+ * @return int
+ */
function numRows( $res ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return $n;
}
+ /**
+ * @param $res
+ * @return int
+ */
function numFields( $res ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return mysql_num_fields( $res );
}
+ /**
+ * @param $res
+ * @param $n
+ * @return string
+ */
function fieldName( $res, $n ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return mysql_field_name( $res, $n );
}
- function insertId() { return mysql_insert_id( $this->mConn ); }
+ /**
+ * @return int
+ */
+ function insertId() {
+ return mysql_insert_id( $this->mConn );
+ }
function dataSeek( $res, $row ) {
if ( $res instanceof ResultWrapper ) {
return $error;
}
- function affectedRows() { return mysql_affected_rows( $this->mConn ); }
+ /**
+ * @return int
+ */
+ function affectedRows() {
+ return mysql_affected_rows( $this->mConn );
+ }
function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseMysql::replace' ) {
return $this->nativeReplace( $table, $rows, $fname );
* Estimate rows in dataset
* Returns estimated count, based on EXPLAIN output
* Takes same arguments as Database::select()
+ *
+ * @return int
*/
public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseMysql::estimateRowCount', $options = array() ) {
$options['EXPLAIN'] = true;
return $rows;
}
+ /**
+ * @param $table string
+ * @param $field string
+ * @return bool|MySQLField
+ */
function fieldInfo( $table, $field ) {
$table = $this->tableName( $table );
$res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true );
/**
* Get information about an index into an object
* Returns false if the index does not exist
+ *
+ * @return false|array
*/
function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
# SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
return empty( $result ) ? false : $result;
}
+ /**
+ * @param $db
+ * @return bool
+ */
function selectDB( $db ) {
$this->mDBname = $db;
return mysql_select_db( $db, $this->mConn );
}
+ /**
+ * @param $s string
+ *
+ * @return string
+ */
function strencode( $s ) {
$sQuoted = mysql_real_escape_string( $s, $this->mConn );
/**
* MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
+ *
+ * @param $s string
+ *
+ * @return string
*/
public function addIdentifierQuotes( $s ) {
return "`" . $this->strencode( $s ) . "`";
}
+ /**
+ * @param $name string
+ * @return bool
+ */
public function isQuotedIdentifier( $name ) {
- return strlen($name) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
+ return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
}
+ /**
+ * @return bool
+ */
function ping() {
$ping = mysql_ping( $this->mConn );
if ( $ping ) {
}
}
+ /**
+ * @return string
+ */
function getServerVersion() {
return mysql_get_server_info( $this->mConn );
}
+ /**
+ * @param $index
+ * @return string
+ */
function useIndexClause( $index ) {
return "FORCE INDEX (" . $this->indexName( $index ) . ")";
}
+ /**
+ * @return string
+ */
function lowPriorityOption() {
return 'LOW_PRIORITY';
}
+ /**
+ * @return string
+ */
public static function getSoftwareLink() {
return '[http://www.mysql.com/ MySQL]';
}
/**
* Determines if the last failure was due to a deadlock
+ *
+ * @return bool
*/
function wasDeadlock() {
return $this->lastErrno() == 1213;
/**
* Determines if the last query error was something that should be dealt
* with by pinging the connection and reissuing the query
+ *
+ * @return bool
*/
function wasErrorReissuable() {
return $this->lastErrno() == 2013 || $this->lastErrno() == 2006;
/**
* Determines if the last failure was due to the database being read-only.
+ *
+ * @return bool
*/
function wasReadOnlyError() {
return $this->lastErrno() == 1223 ||
return $endArray;
}
+ /**
+ * @param $tableName
+ * @param $fName string
+ * @return bool|ResultWrapper
+ */
public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
if( !$this->tableExists( $tableName ) ) {
return false;
/**
* Legacy support: Database == DatabaseMysql
+ *
+ * @deprecated in 1.16
*/
class Database extends DatabaseMysql {}
$this->type = $info->type;
}
+ /**
+ * @return string
+ */
function name() {
return $this->name;
}
+ /**
+ * @return string
+ */
function tableName() {
return $this->tableName;
}
return $this->type;
}
+ /**
+ * @return bool
+ */
function isNullable() {
return $this->nullable;
}
return $this->default;
}
+ /**
+ * @return bool
+ */
function isKey() {
return $this->is_key;
}
+ /**
+ * @return bool
+ */
function isMultipleKey() {
return $this->is_multiple;
}
+ /**
+ * @return int
+ */
function maxLength() {
return $this->max_length;
}
$this->currentRow = null;
}
+ /**
+ * @return int
+ */
function current() {
if ( is_null( $this->currentRow ) ) {
$this->next();
return $this->currentRow;
}
+ /**
+ * @return int
+ */
function key() {
return $this->pos;
}
+ /**
+ * @return int
+ */
function next() {
$this->pos++;
$this->currentRow = $this->fetchObject();
return $this->currentRow;
}
+ /**
+ * @return bool
+ */
function valid() {
return $this->current() !== false;
}
$required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
$optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
- 'templateOverridesByCluster', 'masterTemplateOverrides',
+ 'templateOverridesByCluster', 'masterTemplateOverrides',
'readOnlyBySection' );
foreach ( $required as $key ) {
}
}
+ /**
+ * @param $wiki bool|string
+ * @return string
+ */
function getSectionForWiki( $wiki = false ) {
if ( $this->lastWiki === $wiki ) {
return $this->lastSection;
}
/**
- * @param $wiki string
+ * @param $wiki bool|string
* @return LoadBalancer
*/
function newMainLB( $wiki = false ) {
}
/**
- * @param $wiki
+ * @param $wiki bool|string
* @return LoadBalancer
*/
function getMainLB( $wiki = false ) {
$servers = $this->makeServerArray( $template, $loads, $groupLoads );
$lb = new LoadBalancer( array(
'servers' => $servers,
- 'masterWaitTimeout' => $wgMasterWaitTimeout
+ 'masterWaitTimeout' => $wgMasterWaitTimeout
));
return $lb;
}
/**
* Make a server array as expected by LoadBalancer::__construct, using a template and load array
*
+ * @param $template
+ * @param $loads
+ * @param $groupLoads
* @return array
*/
function makeServerArray( $template, $loads, $groupLoads ) {
/**
* Take a group load array indexed by group then server, and reindex it by server then group
+ * @param $groupLoads
+ * @return array
*/
function reindexGroupLoads( $groupLoads ) {
$reindexed = array();
/**
* Get the database name and prefix based on the wiki ID
+ * @param bool $wiki
+ * @return array
*/
function getDBNameAndPrefix( $wiki = false ) {
if ( $wiki === false ) {
* Execute a function for each tracked load balancer
* The callback is called with the load balancer as the first parameter,
* and $params passed as the subsequent parameters.
+ * @param $callback
+ * @param $params array
*/
function forEachLB( $callback, $params = array() ) {
foreach ( $this->mainLBs as $lb ) {
}
/**
- * @param $wiki
+ * @param $wiki bool|string
*
* @return LoadBalancer_Single
*/
}
/**
- * @param $wiki
+ * @param $wiki bool|string
*
* @return LoadBalancer_Single
*/
/**
* @param $cluster
- * @param $wiki
+ * @param $wiki bool|string
*
* @return LoadBalancer_Single
*/
/**
* @param $cluster
- * @param $wiki
+ * @param $wiki bool|string
*
* @return LoadBalancer_Single
*/
/**
* Wait for a given slave to catch up to the master pos stored in $this
+ * @param $index
+ * @param $open bool
+ * @return bool
*/
function doWait( $index, $open = false ) {
# Find a connection to wait on
function reallyOpenConnection( $server, $dbNameOverride = false ) {
if( !is_array( $server ) ) {
throw new MWException( 'You must update your load-balancing configuration. ' .
- 'See DefaultSettings.php entry for $wgDBservers.' );
+ 'See DefaultSettings.php entry for $wgDBservers.' );
}
$host = $server['host'];
* Close a connection
* Using this function makes sure the LoadBalancer knows the connection is closed.
* If you use $conn->close() directly, the load balancer won't update its state.
- * @param $conn
- * @return void
+ * @param $conn DatabaseBase
*/
function closeConnection( $conn ) {
$done = false;
}
}
+ /**
+ * @param $value null
+ * @return Mixed
+ */
function waitTimeout( $value = null ) {
return wfSetVar( $this->mWaitTimeout, $value );
}
+ /**
+ * @return bool
+ */
function getLaggedSlaveMode() {
return $this->mLaggedSlaveMode;
}
$this->mAllowLagged = $mode;
}
+ /**
+ * @return bool
+ */
function pingAll() {
$success = true;
foreach ( $this->mConns as $conns2 ) {
* potentially restricted queries such as SHOW SLAVE STATUS. Using this
* function instead of Database::getLag() avoids a fatal error in this
* case on many installations.
+ *
+ * @param $conn DatabaseBase
+ *
+ * @return int
*/
function safeGetLag( $conn ) {
if ( $this->getServerCount() == 1 ) {