* member variables.
* If no more rows are available, false is returned.
*
- * @param $res ResultWrapper|object as returned from DatabaseBase::query(), etc.
- * @return object|bool
+ * @param ResultWrapper|stdClass $res Object as returned from DatabaseBase::query(), etc.
+ * @return stdClass|bool
* @throws DBUnexpectedError Thrown if the database returns an error
*/
function fetchObject( $res );
/**
* Fetch the next row from the given result object, in associative array
- * form. Fields are retrieved with $row['fieldname'].
+ * form. Fields are retrieved with $row['fieldname'].
* If no more rows are available, false is returned.
*
- * @param $res ResultWrapper result object as returned from DatabaseBase::query(), etc.
+ * @param ResultWrapper $res Result object as returned from DatabaseBase::query(), etc.
* @return array|bool
* @throws DBUnexpectedError Thrown if the database returns an error
*/
/**
* Get the number of rows in a result object
*
- * @param $res Mixed: A SQL result
+ * @param mixed $res A SQL result
* @return int
*/
function numRows( $res );
* Get the number of fields in a result object
* @see http://www.php.net/mysql_num_fields
*
- * @param $res Mixed: A SQL result
+ * @param mixed $res A SQL result
* @return int
*/
function numFields( $res );
* Get a field name in a result object
* @see http://www.php.net/mysql_field_name
*
- * @param $res Mixed: A SQL result
- * @param $n Integer
+ * @param mixed $res A SQL result
+ * @param int $n
* @return string
*/
function fieldName( $res, $n );
* Change the position of the cursor in a result object
* @see http://www.php.net/mysql_data_seek
*
- * @param $res Mixed: A SQL result
- * @param $row Mixed: Either MySQL row or ResultWrapper
+ * @param mixed $res A SQL result
+ * @param int $row
*/
function dataSeek( $res, $row );
* mysql_fetch_field() wrapper
* Returns false if the field doesn't exist
*
- * @param string $table table name
- * @param string $field field name
+ * @param string $table Table name
+ * @param string $field Field name
*
* @return Field
*/
* @param string $table Table name
* @param string $index Index name
* @param string $fname Calling function name
- * @return Mixed: Database-specific index description class or false if the index does not exist
+ * @return mixed Database-specific index description class or false if the index does not exist
*/
function indexInfo( $table, $index, $fname = __METHOD__ );
/**
* Wrapper for addslashes()
*
- * @param string $s to be slashed.
- * @return string: slashed string.
+ * @param string $s String to be slashed.
+ * @return string Slashed string.
*/
function strencode( $s );
/**
* Returns a wikitext link to the DB's website, e.g.,
- * return "[http://www.mysql.com/ MySQL]";
+ * return "[http://www.mysql.com/ MySQL]";
* Should at least contain plain text, if for some reason
* your database has no website.
*
- * @return string: wikitext of a link to the server software's web site
+ * @return string Wikitext of a link to the server software's web site
*/
function getSoftwareLink();
* A string describing the current software version, like from
* mysql_get_server_info().
*
- * @return string: Version information from the database server.
+ * @return string Version information from the database server.
*/
function getServerVersion();
/**
* A string describing the current software version, and possibly
- * other details in a user-friendly way. Will be listed on Special:Version, etc.
+ * other details in a user-friendly way. Will be listed on Special:Version, etc.
* Use getServerVersion() to get machine-friendly information.
*
- * @return string: Version information from the database server
+ * @return string Version information from the database server
*/
function getServerInfo();
}
abstract class DatabaseBase implements IDatabase, DatabaseType {
/** Number of times to re-try an operation in case of deadlock */
const DEADLOCK_TRIES = 4;
+
/** Minimum time to wait before retry, in microseconds */
const DEADLOCK_DELAY_MIN = 500000;
+
/** Maximum time to wait before retry */
const DEADLOCK_DELAY_MAX = 1500000;
protected $mServer, $mUser, $mPassword, $mDBname;
+ /** @var resource Database connection */
protected $mConn = null;
protected $mOpened = false;
protected $mForeign;
protected $mErrorCount = 0;
protected $mLBInfo = array();
- protected $mFakeSlaveLag = null, $mFakeMaster = false;
protected $mDefaultBigSelects = null;
protected $mSchemaVars = false;
* Remembers the function name given for starting the most recent transaction via begin().
* Used to provide additional context for error reporting.
*
- * @var String
+ * @var string
* @see DatabaseBase::mTrxLevel
*/
private $mTrxFname = null;
/**
* Record if possible write queries were done in the last transaction started
*
- * @var Bool
+ * @var bool
* @see DatabaseBase::mTrxLevel
*/
private $mTrxDoneWrites = false;
/**
* Record if the current transaction was started implicitly due to DBO_TRX being set.
*
- * @var Bool
+ * @var bool
* @see DatabaseBase::mTrxLevel
*/
private $mTrxAutomatic = false;
/**
* Record if the current transaction was started implicitly by DatabaseBase::startAtomic
*
- * @var Bool
+ * @var bool
*/
private $mTrxAutomaticAtomic = false;
/**
* @since 1.21
- * @var file handle for upgrade
+ * @var resource File handle for upgrade
*/
protected $fileHandle = null;
/**
* @since 1.22
- * @var Process cache of VIEWs names in the database
+ * @var string[] Process cache of VIEWs names in the database
*/
protected $allViews = null;
/**
* A string describing the current software version, and possibly
- * other details in a user-friendly way. Will be listed on Special:Version, etc.
+ * other details in a user-friendly way. Will be listed on Special:Version, etc.
* Use getServerVersion() to get machine-friendly information.
*
- * @return string: Version information from the database server
+ * @return string Version information from the database server
*/
public function getServerInfo() {
return $this->getServerVersion();
}
/**
- * @return string: command delimiter used by this database engine
+ * @return string command delimiter used by this database engine
*/
public function getDelimiter() {
return $this->delimiter;
/**
* Boolean, controls output of large amounts of debug information.
- * @param $debug bool|null
+ * @param bool|null $debug
* - true to enable debugging
* - false to disable debugging
* - omitted or null to do nothing
* split up queries into batches using a LIMIT clause than to switch off
* buffering.
*
- * @param $buffer null|bool
- *
+ * @param null|bool $buffer
* @return null|bool The previous value of the flag
*/
public function bufferResults( $buffer = null ) {
*
* Do not use this function outside of the Database classes.
*
- * @param $ignoreErrors bool|null
- *
+ * @param null|bool $ignoreErrors
* @return bool The previous value of the flag.
*/
public function ignoreErrors( $ignoreErrors = null ) {
/**
* Set the filehandle to copy write statements to.
*
- * @param $fh filehandle
+ * @param resource $fh File handle
*/
public function setFileHandle( $fh ) {
$this->fileHandle = $fh;
* @param string $name The entry of the info array to get, or null to get the
* whole array
*
- * @return LoadBalancer|null
+ * @return array|mixed|null
*/
public function getLBInfo( $name = null ) {
if ( is_null( $name ) ) {
* the LB info array is set to that parameter. If it is called with two
* parameters, the member with the given name is set to the given value.
*
- * @param $name
+ * @param string $name
* @param $value
*/
public function setLBInfo( $name, $value = null ) {
/**
* Set lag time in seconds for a fake slave
*
- * @param $lag int
+ * @param mixed $lag Valid values for this parameter are determined by the
+ * subclass, but should be a PHP scalar or array that would be sensible
+ * as part of $wgLBFactoryConf.
*/
public function setFakeSlaveLag( $lag ) {
- $this->mFakeSlaveLag = $lag;
}
/**
* Make this connection a fake master
*
- * @param $enabled bool
+ * @param bool $enabled
*/
public function setFakeMaster( $enabled = true ) {
- $this->mFakeMaster = $enabled;
}
/**
/**
* Return the last query that went through DatabaseBase::query()
- * @return String
+ * @return string
*/
public function lastQuery() {
return $this->mLastQuery;
/**
* Is a connection to the database open?
- * @return Boolean
+ * @return bool
*/
public function isOpen() {
return $this->mOpened;
/**
* Set a flag for this connection
*
- * @param $flag Integer: DBO_* constants from Defines.php:
+ * @param int $flag DBO_* constants from Defines.php:
* - DBO_DEBUG: output some debug info (same as debug())
* - DBO_NOBUFFER: don't buffer results (inverse of bufferResults())
* - DBO_TRX: automatically start transactions
global $wgDebugDBTransactions;
$this->mFlags |= $flag;
if ( ( $flag & DBO_TRX ) & $wgDebugDBTransactions ) {
- wfDebug( "Implicit transactions are now disabled.\n" );
+ wfDebug( "Implicit transactions are now disabled.\n" );
}
}
/**
* Clear a flag for this connection
*
- * @param $flag : same as setFlag()'s $flag param
+ * @param int $flag DBO_* constants from Defines.php:
+ * - DBO_DEBUG: output some debug info (same as debug())
+ * - DBO_NOBUFFER: don't buffer results (inverse of bufferResults())
+ * - DBO_TRX: automatically start transactions
+ * - DBO_DEFAULT: automatically sets DBO_TRX if not in command line mode
+ * and removes it in command line mode
+ * - DBO_PERSISTENT: use persistant database connection
*/
public function clearFlag( $flag ) {
global $wgDebugDBTransactions;
/**
* Returns a boolean whether the flag $flag is set for this connection
*
- * @param $flag : same as setFlag()'s $flag param
- * @return Boolean
+ * @param int $flag DBO_* constants from Defines.php:
+ * - DBO_DEBUG: output some debug info (same as debug())
+ * - DBO_NOBUFFER: don't buffer results (inverse of bufferResults())
+ * - DBO_TRX: automatically start transactions
+ * - DBO_DEFAULT: automatically sets DBO_TRX if not in command line mode
+ * and removes it in command line mode
+ * - DBO_PERSISTENT: use persistant database connection
+ * @return bool
*/
public function getFlag( $flag ) {
return !!( $this->mFlags & $flag );
/**
* General read-only accessor
*
- * @param $name string
- *
+ * @param string $name
* @return string
*/
public function getProperty( $name ) {
* DatabaseBase subclasses should not be constructed directly in external
* code. DatabaseBase::factory() should be used instead.
*
- * @param array Parameters passed from DatabaseBase::factory()
+ * @param array $params Parameters passed from DatabaseBase::factory()
*/
function __construct( $params = null ) {
global $wgDBprefix, $wgCommandLineMode, $wgDebugDBTransactions;
* @param string $dbType A possible DB type
* @param array $p An array of options to pass to the constructor.
* Valid options are: host, user, password, dbname, flags, tablePrefix, driver
- * @return DatabaseBase subclass or null
+ * @throws MWException If the database driver or extension cannot be found
+ * @return DatabaseBase|null DatabaseBase subclass or null
*/
final public static function factory( $dbType, $p = array() ) {
$canonicalDBTypes = array(
/**
* @param $errno
- * @param $errstr
- * @access private
+ * @param string $errstr
*/
public function connectionErrorHandler( $errno, $errstr ) {
$this->mPHPError = $errstr;
* if it is open : commits any open transactions
*
* @throws MWException
- * @return Bool operation success. true if already closed.
+ * @return bool Operation success. true if already closed.
*/
public function close() {
if ( count( $this->mTrxIdleCallbacks ) ) { // sanity
/**
* Closes underlying database connection
* @since 1.20
- * @return bool: Whether connection was closed successfully
+ * @return bool Whether connection was closed successfully
*/
abstract protected function closeConnection();
/**
- * @param string $error fallback error message, used if none is given by DB
+ * @param string $error Fallback error message, used if none is given by DB
* @throws DBConnectionError
*/
function reportConnectionError( $error = 'Unknown error' ) {
/**
* The DBMS-dependent part of query()
*
- * @param $sql String: SQL query.
- * @return ResultWrapper Result object to feed to fetchObject, fetchRow, ...; or false on failure
+ * @param string $sql SQL query.
+ * @return ResultWrapper|bool Result object to feed to fetchObject,
+ * fetchRow, ...; or false on failure
*/
abstract protected function doQuery( $sql );
* Determine whether a query writes to the DB.
* Should return true if unsure.
*
- * @param $sql string
- *
+ * @param string $sql
* @return bool
*/
public function isWriteQuery( $sql ) {
*
* However, the query wrappers themselves should call this function.
*
- * @param $sql String: SQL query
- * @param $fname String: Name of the calling function, for profiling/SHOW PROCESSLIST
+ * @param string $sql SQL query
+ * @param string $fname Name of the calling function, for profiling/SHOW PROCESSLIST
* comment (you can use __METHOD__ or add some extra info)
- * @param $tempIgnore Boolean: Whether to avoid throwing an exception on errors...
+ * @param bool $tempIgnore Whether to avoid throwing an exception on errors...
* maybe best to catch the exception instead?
* @throws MWException
- * @return boolean|ResultWrapper. true for a successful write query, ResultWrapper object
+ * @return bool|ResultWrapper True for a successful write query, ResultWrapper object
* for a successful read query, or false on failure if $tempIgnore set
*/
public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
Profiler::instance()->transactionWritingIn( $this->mServer, $this->mDBname );
}
+ $queryProf = '';
+ $totalProf = '';
$isMaster = !is_null( $this->getLBInfo( 'master' ) );
+
if ( !Profiler::instance()->isStub() ) {
# generalizeSQL will probably cut down the query to reasonable
# logging size most of the time. The substr is really just a sanity check.
* Report a query error. Log the error, and if neither the object ignore
* flag nor the $tempIgnore flag is set, throw a DBQueryError.
*
- * @param $error String
- * @param $errno Integer
- * @param $sql String
- * @param $fname String
- * @param $tempIgnore Boolean
+ * @param string $error
+ * @param int $errno
+ * @param string $sql
+ * @param string $fname
+ * @param bool $tempIgnore
* @throws DBQueryError
*/
public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
* & = filename; reads the file and inserts as a blob
* (we don't use this though...)
*
- * @param $sql string
- * @param $func string
+ * @param string $sql
+ * @param string $func
*
* @return array
*/
protected function prepare( $sql, $func = 'DatabaseBase::prepare' ) {
/* MySQL doesn't support prepared statements (yet), so just
- pack up the query for reference. We'll manually replace
- the bits later. */
+ * pack up the query for reference. We'll manually replace
+ * the bits later.
+ */
return array( 'query' => $sql, 'func' => $func );
}
/**
* Free a prepared query, generated by prepare().
- * @param $prepared
+ * @param string $prepared
*/
protected function freePrepared( $prepared ) {
/* No-op by default */
/**
* Execute a prepared query with the various arguments
* @param string $prepared the prepared sql
- * @param $args Mixed: Either an array here, or put scalars as varargs
+ * @param mixed $args Either an array here, or put scalars as varargs
*
* @return ResultWrapper
*/
/**
* For faking prepared SQL statements on DBs that don't support it directly.
*
- * @param string $preparedQuery a 'preparable' SQL statement
- * @param array $args of arguments to fill it with
- * @return string executable SQL
+ * @param string $preparedQuery A 'preparable' SQL statement
+ * @param array $args of Arguments to fill it with
+ * @return string Executable SQL
*/
public function fillPrepared( $preparedQuery, $args ) {
reset( $args );
* The arguments should be in $this->preparedArgs and must not be touched
* while we're doing this.
*
- * @param $matches Array
+ * @param array $matches
* @throws DBUnexpectedError
- * @return String
+ * @return string
*/
protected function fillPreparedArg( $matches ) {
switch ( $matches[1] ) {
* necessary to call this, just use unset() or let the variable holding
* the result object go out of scope.
*
- * @param $res Mixed: A SQL result
+ * @param mixed $res A SQL result
*/
public function freeResult( $res ) {
}
* Returns an optional USE INDEX clause to go after the table, and a
* string to go at the end of the query.
*
- * @param array $options associative array of options to be turned into
- * an SQL query, valid keys are listed in the function.
- * @return Array
+ * @param array $options Associative array of options to be turned into
+ * an SQL query, valid keys are listed in the function.
+ * @return array
* @see DatabaseBase::select()
*/
public function makeSelectOptions( $options ) {
/**
* Returns an optional GROUP BY with an optional HAVING
*
- * @param array $options associative array of options
+ * @param array $options Associative array of options
* @return string
* @see DatabaseBase::select()
* @since 1.21
/**
* Returns an optional ORDER BY
*
- * @param array $options associative array of options
+ * @param array $options Associative array of options
* @return string
* @see DatabaseBase::select()
* @since 1.21
* @param string|array $conds Conditions
* @param string $fname Caller function name
* @param array $options Query options
- * @param $join_conds Array Join conditions
+ * @param array $join_conds Join conditions
*
- * @param $table string|array
+ * @param string|array $table
*
* May be either an array of table names, or a single string holding a table
* name. If an array is given, table aliases can be specified, for example:
* added, and various other table name mappings to be performed.
*
*
- * @param $vars string|array
+ * @param string|array $vars
*
* May be either a field name or an array of field names. The field names
* can be complete fragments of SQL, for direct inclusion into the SELECT
* DBMS-independent.
*
*
- * @param $conds string|array
+ * @param string|array $conds
*
* May be either a string containing a single condition, or an array of
* conditions. If an array is given, the conditions constructed from each
* - DatabaseBase::conditional()
*
*
- * @param $options string|array
+ * @param string|array $options
*
* Optional: Array of query options. Boolean options are specified by
* including them in the array as a string value with a numeric key, for
* - SQL_NO_CACHE
*
*
- * @param $join_conds string|array
+ * @param string|array $join_conds
*
* Optional associative array of table-specific join conditions. In the
* most common case, this is unnecessary, since the join condition can be
*
* array( 'page' => array( 'LEFT JOIN', 'page_latest=rev_id' ) )
*
- * @return ResultWrapper. If the query returned no rows, a ResultWrapper
+ * @return ResultWrapper|bool If the query returned no rows, a ResultWrapper
* with no rows in it will be returned. If there was a query error, a
* DBQueryError exception will be thrown, except if the "ignore errors"
* option was set, in which case false will be returned.
* @param string|array $conds Conditions
* @param string $fname Caller function name
* @param string|array $options Query options
- * @param $join_conds string|array Join conditions
+ * @param string|array $join_conds Join conditions
*
* @return string SQL query string.
* @see DatabaseBase::select()
* @param array $conds Conditions
* @param string $fname Caller function name
* @param string|array $options Query options
- * @param $join_conds array|string Join conditions
+ * @param array|string $join_conds Join conditions
*
* @return stdClass|bool
*/
*
* Takes the same arguments as DatabaseBase::select().
*
- * @param string $table table name
- * @param array|string $vars : unused
- * @param array|string $conds : filters on the table
- * @param string $fname function name for profiling
- * @param array $options options for select
- * @return Integer: row count
+ * @param string $table Table name
+ * @param string $vars Unused
+ * @param array|string $conds Filters on the table
+ * @param string $fname Function name for profiling
+ * @param array $options Options for select
+ * @return int Row count
*/
public function estimateRowCount( $table, $vars = '*', $conds = '',
$fname = __METHOD__, $options = array()
/**
* Determines whether a field exists in a table
*
- * @param string $table table name
- * @param string $field filed to check on that table
- * @param string $fname calling function name (optional)
- * @return Boolean: whether $table has filed $field
+ * @param string $table Table name
+ * @param string $field Filed to check on that table
+ * @param string $fname Calling function name (optional)
+ * @return bool Whether $table has filed $field
*/
public function fieldExists( $table, $field, $fname = __METHOD__ ) {
$info = $this->fieldInfo( $table, $field );
* Usually throws a DBQueryError on failure
* If errors are explicitly ignored, returns NULL on failure
*
- * @param $table
- * @param $index
- * @param $fname string
- *
+ * @param string $table
+ * @param string $index
+ * @param string $fname
* @return bool|null
*/
public function indexExists( $table, $index, $fname = __METHOD__ ) {
/**
* Query whether a given table exists
*
- * @param $table string
- * @param $fname string
- *
+ * @param string $table
+ * @param string $fname
* @return bool
*/
public function tableExists( $table, $fname = __METHOD__ ) {
return (bool)$res;
}
- /**
- * mysql_field_type() wrapper
- * @param $res
- * @param $index
- * @return string
- */
- public function fieldType( $res, $index ) {
- if ( $res instanceof ResultWrapper ) {
- $res = $res->result;
- }
-
- return mysql_field_type( $res, $index );
- }
-
/**
* Determines if a given index is unique
*
- * @param $table string
- * @param $index string
+ * @param string $table
+ * @param string $index
*
* @return bool
*/
/**
* Helper for DatabaseBase::insert().
*
- * @param $options array
+ * @param array $options
* @return string
*/
protected function makeInsertOptions( $options ) {
* possible to determine how many rows were successfully inserted using
* DatabaseBase::affectedRows().
*
- * @param $table String Table name. This will be passed through
- * DatabaseBase::tableName().
- * @param $a Array of rows to insert
- * @param $fname String Calling function name (use __METHOD__) for logs/profiling
+ * @param string $table Table name. This will be passed through
+ * DatabaseBase::tableName().
+ * @param array $a Array of rows to insert
+ * @param string $fname Calling function name (use __METHOD__) for logs/profiling
* @param array $options of options
*
* @return bool
/**
* UPDATE wrapper. Takes a condition array and a SET array.
*
- * @param $table String name of the table to UPDATE. This will be passed through
- * DatabaseBase::tableName().
- *
+ * @param string $table Name of the table to UPDATE. This will be passed through
+ * DatabaseBase::tableName().
* @param array $values An array of values to SET. For each array element,
- * the key gives the field name, and the value gives the data
- * to set that field to. The data will be quoted by
- * DatabaseBase::addQuotes().
- *
- * @param $conds Array: An array of conditions (WHERE). See
- * DatabaseBase::select() for the details of the format of
- * condition arrays. Use '*' to update all rows.
- *
- * @param $fname String: The function name of the caller (from __METHOD__),
- * for logging and profiling.
- *
+ * the key gives the field name, and the value gives the data to set
+ * that field to. The data will be quoted by DatabaseBase::addQuotes().
+ * @param array $conds An array of conditions (WHERE). See
+ * DatabaseBase::select() for the details of the format of condition
+ * arrays. Use '*' to update all rows.
+ * @param string $fname The function name of the caller (from __METHOD__),
+ * for logging and profiling.
* @param array $options An array of UPDATE options, can be:
- * - IGNORE: Ignore unique key conflicts
- * - LOW_PRIORITY: MySQL-specific, see MySQL manual.
- * @return Boolean
+ * - IGNORE: Ignore unique key conflicts
+ * - LOW_PRIORITY: MySQL-specific, see MySQL manual.
+ * @return bool
*/
function update( $table, $values, $conds, $fname = __METHOD__, $options = array() ) {
$table = $this->tableName( $table );
/**
* Makes an encoded list of strings from an array
- * @param array $a containing the data
- * @param int $mode Constant
- * - LIST_COMMA: comma separated, no field names
- * - LIST_AND: ANDed WHERE clause (without the WHERE). See
- * the documentation for $conds in DatabaseBase::select().
- * - LIST_OR: ORed WHERE clause (without the WHERE)
- * - LIST_SET: comma separated with field names, like a SET clause
- * - LIST_NAMES: comma separated field names
*
+ * @param array $a Containing the data
+ * @param int $mode Constant
+ * - LIST_COMMA: Comma separated, no field names
+ * - LIST_AND: ANDed WHERE clause (without the WHERE). See the
+ * documentation for $conds in DatabaseBase::select().
+ * - LIST_OR: ORed WHERE clause (without the WHERE)
+ * - LIST_SET: Comma separated with field names, like a SET clause
+ * - LIST_NAMES: Comma separated field names
* @throws MWException|DBUnexpectedError
* @return string
*/
* The keys on each level may be either integers or strings.
*
* @param array $data organized as 2-d
- * array(baseKeyVal => array(subKeyVal => [ignored], ...), ...)
- * @param string $baseKey field name to match the base-level keys to (eg 'pl_namespace')
- * @param string $subKey field name to match the sub-level keys to (eg 'pl_title')
+ * array(baseKeyVal => array(subKeyVal => [ignored], ...), ...)
+ * @param string $baseKey Field name to match the base-level keys to (eg 'pl_namespace')
+ * @param string $subKey Field name to match the sub-level keys to (eg 'pl_title')
* @return Mixed: string SQL fragment, or false if no items in array.
*/
public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
* Return aggregated value alias
*
* @param $valuedata
- * @param $valuename string
+ * @param string $valuename
*
* @return string
*/
}
/**
- * @param $field
+ * @param string $field
* @return string
*/
public function bitNot( $field ) {
}
/**
- * @param $fieldLeft
- * @param $fieldRight
+ * @param string $fieldLeft
+ * @param string $fieldRight
* @return string
*/
public function bitAnd( $fieldLeft, $fieldRight ) {
}
/**
- * @param $fieldLeft
- * @param $fieldRight
+ * @param string $fieldLeft
+ * @param string $fieldRight
* @return string
*/
public function bitOr( $fieldLeft, $fieldRight ) {
/**
* Build a concatenation list to feed into a SQL query
- * @param array $stringList list of raw SQL expressions; caller is responsible for any quoting
- * @return String
+ * @param array $stringList List of raw SQL expressions; caller is
+ * responsible for any quoting
+ * @return string
*/
public function buildConcat( $stringList ) {
return 'CONCAT(' . implode( ',', $stringList ) . ')';
* @param string $field Field name
* @param string|array $conds Conditions
* @param string|array $join_conds Join conditions
- * @return String SQL text
+ * @return string SQL text
* @since 1.23
*/
public function buildGroupConcatField(
* @return bool Success or failure
*/
public function selectDB( $db ) {
- # Stub. Shouldn't cause serious problems if it's not overridden, but
+ # Stub. Shouldn't cause serious problems if it's not overridden, but
# if your database engine supports a concept similar to MySQL's
# databases you may as well.
$this->mDBname = $db;
* themselves. Pass the canonical name to such functions. This is only needed
* when calling query() directly.
*
- * @param string $name database table name
+ * @param string $name Database table name
* @param string $format One of:
* quoted - Automatically pass the table name through addIdentifierQuotes()
* so that it can be used in a query.
* raw - Do not add identifier quotes to the table name
- * @return String: full database name
+ * @return string Full database name
*/
public function tableName( $name, $format = 'quoted' ) {
global $wgSharedDB, $wgSharedPrefix, $wgSharedTables;
/**
* Gets an array of aliased table names
*
- * @param $tables array( [alias] => table )
- * @return array of strings, see tableNameWithAlias()
+ * @param array $tables array( [alias] => table )
+ * @return string[] See tableNameWithAlias()
*/
public function tableNamesWithAlias( $tables ) {
$retval = array();
/**
* Gets an array of aliased field names
*
- * @param $fields array( [alias] => field )
- * @return array of strings, see fieldNameWithAlias()
+ * @param array $fields array( [alias] => field )
+ * @return string[] See fieldNameWithAlias()
*/
public function fieldNamesWithAlias( $fields ) {
$retval = array();
* which might have a JOIN and/or USE INDEX clause
*
* @param array $tables ( [alias] => table )
- * @param $use_index array Same as for select()
- * @param $join_conds array Same as for select()
+ * @param array $use_index Same as for select()
+ * @param array $join_conds Same as for select()
* @return string
*/
protected function tableNamesWithUseIndexOrJOIN(
/**
* Get the name of an index in a given table
*
- * @param $index
- *
+ * @param string $index
* @return string
*/
protected function indexName( $index ) {
/**
* Adds quotes and backslashes.
*
- * @param $s string
- *
+ * @param string $s
* @return string
*/
public function addQuotes( $s ) {
* Since MySQL is the odd one out here the double quotes are our generic
* and we implement backticks in DatabaseMysql.
*
- * @param $s string
- *
+ * @param string $s
* @return string
*/
public function addIdentifierQuotes( $s ) {
* Returns if the given identifier looks quoted or not according to
* the database convention for quoting identifiers .
*
- * @param $name string
- *
- * @return boolean
+ * @param string $name
+ * @return bool
*/
public function isQuotedIdentifier( $name ) {
return $name[0] == '"' && substr( $name, -1, 1 ) == '"';
}
/**
- * @param $s string
+ * @param string $s
* @return string
*/
protected function escapeLikeInternal( $s ) {
* $query .= $dbr->buildLike( $pattern );
*
* @since 1.16
- * @return String: fully built LIKE statement
+ * @return string Fully built LIKE statement
*/
public function buildLike() {
$params = func_get_args();
* Any implementation of this function should *not* involve reusing
* sequence numbers created for rolled-back transactions.
* See http://bugs.mysql.com/bug.php?id=30767 for details.
- * @param $seqName string
- * @return null
+ * @param string $seqName
+ * @return null|int
*/
public function nextSequenceValue( $seqName ) {
return null;
}
/**
- * USE INDEX clause. Unlikely to be useful for anything but MySQL. This
+ * USE INDEX clause. Unlikely to be useful for anything but MySQL. This
* is only needed because a) MySQL must be as efficient as possible due to
* its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about
- * which index to pick. Anyway, other databases might have different
- * indexes on a given table. So don't bother overriding this unless you're
+ * which index to pick. Anyway, other databases might have different
+ * indexes on a given table. So don't bother overriding this unless you're
* MySQL.
- * @param $index
+ * @param string $index
* @return string
*/
public function useIndexClause( $index ) {
* errors which wouldn't have occurred in MySQL.
*
* @param string $table The table to replace the row(s) in.
+ * @param array $uniqueIndexes Is an array of indexes. Each element may be either
+ * a field name or an array of field names
* @param array $rows Can be either a single row to insert, or multiple rows,
* in the same format as for DatabaseBase::insert()
- * @param array $uniqueIndexes is an array of indexes. Each element may be either
- * a field name or an array of field names
* @param string $fname Calling function name (use __METHOD__) for logs/profiling
*/
public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
* statement.
*
* @param string $table Table name
- * @param array $rows Rows to insert
+ * @param array|string $rows Row(s) to insert
* @param string $fname Caller function name
*
* @return ResultWrapper
* Usually throws a DBQueryError on failure. If errors are explicitly ignored,
* returns success.
*
+ * @since 1.22
+ *
* @param string $table Table name. This will be passed through DatabaseBase::tableName().
* @param array $rows A single row or list of rows to insert
* @param array $uniqueIndexes List of single field names or field name tuples
- * @param array $set An array of values to SET. For each array element,
- * the key gives the field name, and the value gives the data
- * to set that field to. The data will be quoted by
- * DatabaseBase::addQuotes().
+ * @param array $set An array of values to SET. For each array element, the
+ * key gives the field name, and the value gives the data to set that
+ * field to. The data will be quoted by DatabaseBase::addQuotes().
* @param string $fname Calling function name (use __METHOD__) for logs/profiling
- * @param array $options of options
- *
+ * @throws Exception
* @return bool
- * @since 1.22
*/
- public function upsert(
- $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
+ public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
+ $fname = __METHOD__
) {
if ( !count( $rows ) ) {
return true; // nothing to do
*
* DO NOT put the join condition in $conds.
*
- * @param $delTable String: The table to delete from.
- * @param $joinTable String: The other table.
- * @param $delVar String: The variable to join on, in the first table.
- * @param $joinVar String: The variable to join on, in the second table.
- * @param $conds Array: Condition array of field names mapped to variables,
- * ANDed together in the WHERE clause
- * @param $fname String: Calling function name (use __METHOD__) for
- * logs/profiling
+ * @param string $delTable The table to delete from.
+ * @param string $joinTable The other table.
+ * @param string $delVar The variable to join on, in the first table.
+ * @param string$joinVar The variable to join on, in the second table.
+ * @param array $conds Condition array of field names mapped to variables,
+ * ANDed together in the WHERE clause
+ * @param string $fname Calling function name (use __METHOD__) for logs/profiling
* @throws DBUnexpectedError
*/
public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
/**
* Returns the size of a text field, or -1 for "unlimited"
*
- * @param $table string
- * @param $field string
- *
+ * @param string $table
+ * @param string $field
* @return int
*/
public function textFieldSize( $table, $field ) {
/**
* A string to insert into queries to show that they're low-priority, like
- * MySQL's LOW_PRIORITY. If no such feature exists, return an empty
+ * MySQL's LOW_PRIORITY. If no such feature exists, return an empty
* string and nothing bad should happen.
*
* @return string Returns the text of the low priority option if it is
* DELETE query wrapper.
*
* @param array $table Table name
- * @param string|array $conds of conditions. See $conds in DatabaseBase::select() for
- * the format. Use $conds == "*" to delete all rows
+ * @param string|array $conds of conditions. See $conds in DatabaseBase::select()
+ * for the format. Use $conds == "*" to delete all rows
* @param string $fname name of the calling function
- *
* @throws DBUnexpectedError
* @return bool|ResultWrapper
*/
* @param string|array $srcTable May be either a table name, or an array of table names
* to include in a join.
*
- * @param array $varMap must be an associative array of the form
+ * @param array $varMap Must be an associative array of the form
* array( 'dest1' => 'source1', ...). Source items may be literals
* rather than field names, but strings should be quoted with
* DatabaseBase::addQuotes()
) {
$destTable = $this->tableName( $destTable );
- if ( is_array( $insertOptions ) ) {
- $insertOptions = implode( ' ', $insertOptions );
+ if ( !is_array( $insertOptions ) ) {
+ $insertOptions = array( $insertOptions );
}
+ $insertOptions = $this->makeInsertOptions( $insertOptions );
+
if ( !is_array( $selectOptions ) ) {
$selectOptions = array( $selectOptions );
}
}
/**
- * Construct a LIMIT query with optional offset. This is used for query
- * pages. The SQL should be adjusted so that only the first $limit rows
- * are returned. If $offset is provided as well, then the first $offset
+ * Construct a LIMIT query with optional offset. This is used for query
+ * pages. The SQL should be adjusted so that only the first $limit rows
+ * are returned. If $offset is provided as well, then the first $offset
* rows should be discarded, and the next $limit rows should be returned.
* If the result of the query is not ordered, then the rows to be returned
* are theoretically arbitrary.
*
* $sql is expected to be a SELECT, if that makes a difference.
*
- * The version provided by default works in MySQL and SQLite. It will very
+ * The version provided by default works in MySQL and SQLite. It will very
* likely need to be overridden for most other DBMSes.
*
* @param string $sql SQL query we will append the limit too
- * @param $limit Integer the SQL limit
- * @param $offset Integer|bool the SQL offset (default false)
- *
+ * @param int $limit The SQL limit
+ * @param int|bool $offset The SQL offset (default false)
* @throws DBUnexpectedError
* @return string
*/
* This is used for providing overload point for other DB abstractions
* not compatible with the MySQL syntax.
* @param array $sqls SQL statements to combine
- * @param $all Boolean: use UNION ALL
- * @return String: SQL fragment
+ * @param bool $all Use UNION ALL
+ * @return string SQL fragment
*/
public function unionQueries( $sqls, $all ) {
$glue = $all ? ') UNION ALL (' : ') UNION (';
}
/**
- * Returns an SQL expression for a simple conditional. This doesn't need
+ * Returns an SQL expression for a simple conditional. This doesn't need
* to be overridden unless CASE isn't supported in your DBMS.
*
* @param string|array $cond SQL expression which will result in a boolean value
* @param string $trueVal SQL expression to return if true
* @param string $falseVal SQL expression to return if false
- * @return String: SQL fragment
+ * @return string SQL fragment
*/
public function conditional( $cond, $trueVal, $falseVal ) {
if ( is_array( $cond ) ) {
* Returns a comand for str_replace function in SQL query.
* Uses REPLACE() in MySQL
*
- * @param string $orig column to modify
- * @param string $old column to seek
- * @param string $new column to replace with
+ * @param string $orig Column to modify
+ * @param string $old Column to seek
+ * @param string $new Column to replace with
*
* @return string
*/
/**
* Wait for the slave to catch up to a given master position.
*
- * @param $pos DBMasterPos object
- * @param $timeout Integer: the maximum number of seconds to wait for
+ * @param DBMasterPos $pos
+ * @param int $timeout The maximum number of seconds to wait for
* synchronisation
- *
- * @return integer: zero if the slave was past that position already,
+ * @return int Zzero if the slave was past that position already,
* greater than zero if we waited for some period of time, less than
* zero if we timed out.
*/
public function masterPosWait( DBMasterPos $pos, $timeout ) {
- wfProfileIn( __METHOD__ );
-
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- $wait = intval( ( $pos->pos - microtime( true ) + $this->mFakeSlaveLag ) * 1e6 );
-
- if ( $wait > $timeout * 1e6 ) {
- wfDebug( "Fake slave timed out waiting for $pos ($wait us)\n" );
- wfProfileOut( __METHOD__ );
-
- return -1;
- } elseif ( $wait > 0 ) {
- wfDebug( "Fake slave waiting $wait us\n" );
- usleep( $wait );
- wfProfileOut( __METHOD__ );
-
- return 1;
- } else {
- wfDebug( "Fake slave up to date ($wait us)\n" );
- wfProfileOut( __METHOD__ );
-
- return 0;
- }
- }
-
- wfProfileOut( __METHOD__ );
-
# Real waits are implemented in the subclass.
return 0;
}
/**
* Get the replication position of this slave
*
- * @return DBMasterPos, or false if this is not a slave.
+ * @return DBMasterPos|bool False if this is not a slave.
*/
public function getSlavePos() {
- if ( !is_null( $this->mFakeSlaveLag ) ) {
- $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag );
- wfDebug( __METHOD__ . ": fake slave pos = $pos\n" );
-
- return $pos;
- } else {
- # Stub
- return false;
- }
+ # Stub
+ return false;
}
/**
* Get the position of this master
*
- * @return DBMasterPos, or false if this is not a master
+ * @return DBMasterPos|bool False if this is not a master
*/
public function getMasterPos() {
- if ( $this->mFakeMaster ) {
- return new MySQLMasterPos( 'fake', microtime( true ) );
- } else {
- return false;
- }
+ # Stub
+ return false;
}
/**
* will cause a warning, unless the current transaction was started
* automatically because of the DBO_TRX flag.
*
- * @param $fname string
+ * @param string $fname
* @throws DBError
*/
final public function begin( $fname = __METHOD__ ) {
* Issues the BEGIN command to the database server.
*
* @see DatabaseBase::begin()
- * @param type $fname
+ * @param string $fname
*/
protected function doBegin( $fname ) {
$this->query( 'BEGIN', $fname );
*
* Nesting of transactions is not supported.
*
- * @param $fname string
+ * @param string $fname
* @param string $flush Flush flag, set to 'flush' to disable warnings about
* explicitly committing implicit transactions, or calling commit when no
* transaction is in progress. This will silently break any ongoing
* explicit transaction. Only set the flush flag if you are sure that it
* is safe to ignore these warnings in your context.
+ * @throws DBUnexpectedError
*/
final public function commit( $fname = __METHOD__, $flush = '' ) {
if ( !$this->mTrxAtomicLevels->isEmpty() ) {
* Issues the COMMIT command to the database server.
*
* @see DatabaseBase::commit()
- * @param type $fname
+ * @param string $fname
*/
protected function doCommit( $fname ) {
if ( $this->mTrxLevel ) {
*
* No-op on non-transactional databases.
*
- * @param $fname string
+ * @param string $fname
*/
final public function rollback( $fname = __METHOD__ ) {
if ( !$this->mTrxLevel ) {
* Issues the ROLLBACK command to the database server.
*
* @see DatabaseBase::rollback()
- * @param type $fname
+ * @param string $fname
*/
protected function doRollback( $fname ) {
if ( $this->mTrxLevel ) {
* The table names passed to this function shall not be quoted (this
* function calls addIdentifierQuotes when needed).
*
- * @param string $oldName name of table whose structure should be copied
- * @param string $newName name of table to be created
- * @param $temporary Boolean: whether the new table should be temporary
- * @param string $fname calling function name
+ * @param string $oldName Name of table whose structure should be copied
+ * @param string $newName Name of table to be created
+ * @param bool $temporary Whether the new table should be temporary
+ * @param string $fname Calling function name
* @throws MWException
- * @return Boolean: true if operation was successful
+ * @return bool True if operation was successful
*/
public function duplicateTableStructure( $oldName, $newName, $temporary = false,
$fname = __METHOD__
* List all tables on the database
*
* @param string $prefix Only show tables with this prefix, e.g. mw_
- * @param string $fname calling function name
+ * @param string $fname Calling function name
* @throws MWException
*/
function listTables( $prefix = null, $fname = __METHOD__ ) {
/**
* Differentiates between a TABLE and a VIEW
*
- * @param $name string: Name of the database-structure to test.
+ * @param string $name Name of the database-structure to test.
* @throws MWException
* @since 1.22
*/
* The result is unquoted, and needs to be passed through addQuotes()
* before it can be included in raw SQL.
*
- * @param $ts string|int
+ * @param string|int $ts
*
* @return string
*/
* The result is unquoted, and needs to be passed through addQuotes()
* before it can be included in raw SQL.
*
- * @param $ts string|int
+ * @param string|int $ts
*
* @return string
*/
* callers, so this is unnecessary in external code. For compatibility with
* old code, ResultWrapper objects are passed through unaltered.
*
- * @param $result bool|ResultWrapper
- *
+ * @param bool|ResultWrapper|resource $result
* @return bool|ResultWrapper
*/
public function resultObject( $result ) {
* @return bool Success or failure
*/
public function ping() {
- # Stub. Not essential to override.
+ # Stub. Not essential to override.
return true;
}
* @return int Database replication lag in seconds
*/
public function getLag() {
- return intval( $this->mFakeSlaveLag );
+ return 0;
}
/**
* don't allow simple quoted strings to be inserted. To insert into such
* a field, pass the data through this function before passing it to
* DatabaseBase::insert().
- * @param $b string
+ *
+ * @param string $b
* @return string
*/
public function encodeBlob( $b ) {
* Some DBMSs return a special placeholder object representing blob fields
* in result objects. Pass the object through this function to return the
* original string.
- * @param $b string
+ *
+ * @param string $b
* @return string
*/
public function decodeBlob( $b ) {
* full-wiki dumps, where a single query reads out over
* hours or days.
*
- * @param $options Array
+ * @param array $options
* @return void
*/
public function setSessionOptions( array $options ) {
* @param bool|callable $resultCallback Optional function called for each MySQL result
* @param bool|string $fname Calling function name or false if name should be
* generated dynamically using $filename
- * @param bool|callable $inputCallback Callback: Optional function called
- * for each complete line sent
- * @throws MWException
+ * @param bool|callable $inputCallback Optional function called for each
+ * complete line sent
* @throws Exception|MWException
* @return bool|string
*/
* it fails back to MySQL if no DB-specific patch can be found
*
* @param string $patch The name of the patch, like patch-something.sql
- * @return String Full path to patch file
+ * @return string Full path to patch file
*/
public function patchPath( $patch ) {
global $IP;
* ones in $GLOBALS. If an array is set here, $GLOBALS will not be used at
* all. If it's set to false, $GLOBALS will be used.
*
- * @param bool|array $vars mapping variable name to value.
+ * @param bool|array $vars Mapping variable name to value.
*/
public function setSchemaVars( $vars ) {
$this->mSchemaVars = $vars;
* Returns true on success, error string or exception on failure (depending
* on object's error ignore settings).
*
- * @param $fp Resource: File handle
- * @param $lineCallback Callback: Optional function called before reading each query
- * @param $resultCallback Callback: Optional function called for each MySQL result
+ * @param resource $fp File handle
+ * @param bool|callable $lineCallback Optional function called before reading each query
+ * @param bool|callable $resultCallback Optional function called for each MySQL result
* @param string $fname Calling function name
- * @param $inputCallback Callback: Optional function called for each complete query sent
+ * @param bool|callable $inputCallback Optional function called for each complete query sent
* @return bool|string
*/
public function sourceStream( $fp, $lineCallback = false, $resultCallback = false,
*
* @param string $sql SQL assembled so far
* @param string $newLine New line about to be added to $sql
- * @return Bool Whether $newLine contains end of the statement
+ * @return bool Whether $newLine contains end of the statement
*/
public function streamStatementEnd( &$sql, &$newLine ) {
if ( $this->delimiter ) {
* table options its use should be avoided.
*
* @param string $ins SQL statement to replace variables in
- * @return String The new SQL statement with variables replaced
+ * @return string The new SQL statement with variables replaced
*/
protected function replaceSchemaVars( $ins ) {
$vars = $this->getSchemaVars();
/**
* Replace variables in sourced SQL
*
- * @param $ins string
- *
+ * @param string $ins
* @return string
*/
protected function replaceVars( $ins ) {
/**
* Table name callback
*
- * @param $matches array
- *
+ * @param array $matches
* @return string
*/
protected function tableNameCallback( $matches ) {
/**
* Index name callback
*
- * @param $matches array
- *
+ * @param array $matches
* @return string
*/
protected function indexNameCallback( $matches ) {
/**
* Check to see if a named lock is available. This is non-blocking.
*
- * @param string $lockName name of lock to poll
- * @param string $method name of method calling us
- * @return Boolean
+ * @param string $lockName Name of lock to poll
+ * @param string $method Name of method calling us
+ * @return bool
* @since 1.20
*/
public function lockIsFree( $lockName, $method ) {
* Abstracted from Filestore::lock() so child classes can implement for
* their own needs.
*
- * @param string $lockName name of lock to aquire
- * @param string $method name of method calling us
- * @param $timeout Integer: timeout
- * @return Boolean
+ * @param string $lockName Name of lock to aquire
+ * @param string $method Name of method calling us
+ * @param int $timeout
+ * @return bool
*/
public function lock( $lockName, $method, $timeout = 5 ) {
return true;
/**
* Lock specific tables
*
- * @param array $read of tables to lock for read access
- * @param array $write of tables to lock for write access
- * @param string $method name of caller
+ * @param array $read Array of tables to lock for read access
+ * @param array $write Array of tables to lock for write access
+ * @param string $method Name of caller
* @param bool $lowPriority Whether to indicate writes to be LOW PRIORITY
- *
* @return bool
*/
public function lockTables( $read, $write, $method, $lowPriority = true ) {
/**
* Unlock specific tables
*
- * @param string $method the caller
- *
+ * @param string $method The caller
* @return bool
*/
public function unlockTables( $method ) {
/**
* Delete a table
- * @param $tableName string
- * @param $fName string
+ * @param string $tableName
+ * @param string $fName
* @return bool|ResultWrapper
* @since 1.18
*/
* Get search engine class. All subclasses of this need to implement this
* if they wish to use searching.
*
- * @return String
+ * @return string
*/
public function getSearchEngine() {
return 'SearchEngineDummy';
* keyword for timestamps in PostgreSQL, and works with CHAR(14) as well
* because "i" sorts after all numbers.
*
- * @return String
+ * @return string
*/
public function getInfinity() {
return 'infinity';
* Encode an expiry time into the DBMS dependent format
*
* @param string $expiry timestamp for expiry, or the 'infinity' string
- * @return String
+ * @return string
*/
public function encodeExpiry( $expiry ) {
return ( $expiry == '' || $expiry == 'infinity' || $expiry == $this->getInfinity() )
* Decode an expiry time into a DBMS independent format
*
* @param string $expiry DB timestamp field value for expiry
- * @param $format integer: TS_* constant, defaults to TS_MW
- * @return String
+ * @param int $format TS_* constant, defaults to TS_MW
+ * @return string
*/
public function decodeExpiry( $expiry, $format = TS_MW ) {
return ( $expiry == '' || $expiry == $this->getInfinity() )
*
* This is a MySQL-specific feature.
*
- * @param $value Mixed: true for allow, false for deny, or "default" to
+ * @param bool|string $value True for allow, false for deny, or "default" to
* restore the initial value
*/
public function setBigSelects( $value = true ) {