From b5473957961bb2bd63311035d6723698e7535dc1 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 20 Nov 2013 11:13:51 +0100 Subject: [PATCH] Break long lines and formatting updates for includes/db/ Fix all line length related CodeSniffer warnings. Change-Id: Id0fd8f4c7276185f51489659ee3cd06962fbc16d --- includes/db/CloneDatabase.php | 4 +- includes/db/Database.php | 64 +++++++++------ includes/db/DatabaseError.php | 29 +++++-- includes/db/DatabaseMssql.php | 125 ++++++++++++++++++++---------- includes/db/DatabaseMysql.php | 5 +- includes/db/DatabaseMysqlBase.php | 27 +++++-- includes/db/DatabaseOracle.php | 121 +++++++++++++++++++++-------- includes/db/DatabasePostgres.php | 50 ++++++++---- includes/db/DatabaseSqlite.php | 26 +++++-- includes/db/DatabaseUtility.php | 5 +- includes/db/IORMTable.php | 11 ++- includes/db/LBFactory.php | 3 +- includes/db/LBFactory_Multi.php | 44 ++++++++--- includes/db/LoadBalancer.php | 12 ++- includes/db/ORMRow.php | 5 +- includes/db/ORMTable.php | 17 ++-- 16 files changed, 391 insertions(+), 157 deletions(-) diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index d197a9c50e..1e01d29762 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -97,7 +97,9 @@ class CloneDatabase { self::changePrefix( $this->newTablePrefix ); $newTableName = $this->db->tableName( $tbl, 'raw' ); - if ( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) { + if ( $this->dropCurrentTables + && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) + ) { $this->db->dropTable( $tbl, __METHOD__ ); wfDebug( __METHOD__ . " dropping {$newTableName}\n", true ); //Dropping the oldTable because the prefix was changed diff --git a/includes/db/Database.php b/includes/db/Database.php index 4d02af424f..9ba1851632 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -759,7 +759,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * not restored on unserialize. */ public function __sleep() { - throw new MWException( 'Database serialization may cause problems, since the connection is not restored on wakeup.' ); + throw new MWException( 'Database serialization may cause problems, since ' . + 'the connection is not restored on wakeup.' ); } /** @@ -1202,9 +1203,15 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { return $arg; case '&': # return $this->addQuotes( file_get_contents( $arg ) ); - throw new DBUnexpectedError( $this, '& mode is not implemented. If it\'s really needed, uncomment the line above.' ); + throw new DBUnexpectedError( + $this, + '& mode is not implemented. If it\'s really needed, uncomment the line above.' + ); default: - throw new DBUnexpectedError( $this, 'Received invalid match. This should never happen!' ); + throw new DBUnexpectedError( + $this, + 'Received invalid match. This should never happen!' + ); } } @@ -2192,7 +2199,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { list( $table ) = $dbDetails; if ( $wgSharedDB !== null # We have a shared database && $this->mForeign == false # We're not working on a foreign database - && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`' + && !$this->isQuotedIdentifier( $table ) # Prevent shared tables listing '`table`' && in_array( $table, $wgSharedTables ) # A shared table is selected ) { $database = $wgSharedDB; @@ -2473,13 +2480,17 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { } /** - * LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match - * containing either string literals that will be escaped or tokens returned by anyChar() or anyString(). - * Alternatively, the function could be provided with an array of aforementioned parameters. + * LIKE statement wrapper, receives a variable-length argument list with + * parts of pattern to match containing either string literals that will be + * escaped or tokens returned by anyChar() or anyString(). Alternatively, + * the function could be provided with an array of aforementioned + * parameters. * - * Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches - * for subpages of 'My page title'. - * Alternatively: $pattern = array( 'My_page_title/', $dbr->anyString() ); $query .= $dbr->buildLike( $pattern ); + * Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns + * a LIKE clause that searches for subpages of 'My page title'. + * Alternatively: + * $pattern = array( 'My_page_title/', $dbr->anyString() ); + * $query .= $dbr->buildLike( $pattern ); * * @since 1.16 * @return String: fully built LIKE statement @@ -3331,14 +3342,16 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { } /** - * Begin a transaction. If a transaction is already in progress, that transaction will be committed before the - * new transaction is started. + * Begin a transaction. If a transaction is already in progress, + * that transaction will be committed before the new transaction is started. * - * Note that when the DBO_TRX flag is set (which is usually the case for web requests, but not for maintenance scripts), - * any previous database query will have started a transaction automatically. + * Note that when the DBO_TRX flag is set (which is usually the case for web + * requests, but not for maintenance scripts), any previous database query + * will have started a transaction automatically. * - * Nesting of transactions is not supported. Attempts to nest transactions will cause a warning, unless the current - * transaction was started automatically because of the DBO_TRX flag. + * Nesting of transactions is not supported. Attempts to nest transactions + * will cause a warning, unless the current transaction was started + * automatically because of the DBO_TRX flag. * * @param $fname string * @throws DBError @@ -3406,15 +3419,19 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * Nesting of transactions is not supported. * * @param $fname string - * @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. + * @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. */ final public function commit( $fname = __METHOD__, $flush = '' ) { if ( !$this->mTrxAtomicLevels->isEmpty() ) { // There are still atomic sections open. This cannot be ignored - throw new DBUnexpectedError( $this, "Attempted to commit transaction while atomic sections are still open" ); + throw new DBUnexpectedError( + $this, + "Attempted to commit transaction while atomic sections are still open" + ); } if ( $flush != 'flush' ) { @@ -3695,8 +3712,9 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @param bool|callable $lineCallback Optional function called before reading each line * @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 + * generated dynamically using $filename + * @param bool|callable $inputCallback Callback: Optional function called + * for each complete line sent * @throws MWException * @throws Exception|MWException * @return bool|string diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 36b82f4640..8be8530c6b 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -146,8 +146,14 @@ class DBConnectionError extends DBError { function getHTML() { global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors; - $sorry = htmlspecialchars( $this->msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) ); - $again = htmlspecialchars( $this->msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) ); + $sorry = htmlspecialchars( $this->msg( + 'dberr-problems', + 'Sorry! This site is experiencing technical difficulties.' + ) ); + $again = htmlspecialchars( $this->msg( + 'dberr-again', + 'Try waiting a few minutes and reloading.' + ) ); if ( $wgShowHostnames || $wgShowSQLErrors ) { $info = str_replace( @@ -155,7 +161,10 @@ class DBConnectionError extends DBError { htmlspecialchars( $this->msg( 'dberr-info', '(Cannot contact the database server: $1)' ) ) ); } else { - $info = htmlspecialchars( $this->msg( 'dberr-info-hidden', '(Cannot contact the database server)' ) ); + $info = htmlspecialchars( $this->msg( + 'dberr-info-hidden', + '(Cannot contact the database server)' + ) ); } # No database access @@ -220,8 +229,14 @@ class DBConnectionError extends DBError { function searchForm() { global $wgSitename, $wgCanonicalServer, $wgRequest; - $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) ); - $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) ); + $usegoogle = htmlspecialchars( $this->msg( + 'dberr-usegoogle', + 'You can try searching via Google in the meantime.' + ) ); + $outofdate = htmlspecialchars( $this->msg( + 'dberr-outofdate', + 'Note that their indexes of our content may be out of date.' + ) ); $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) ); $search = htmlspecialchars( $wgRequest->getVal( 'search' ) ); @@ -299,7 +314,9 @@ class DBQueryError extends DBError { * @param $fname string */ function __construct( DatabaseBase $db, $error, $errno, $sql, $fname ) { - $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . + $message = "A database error has occurred. Did you forget to run " . + "maintenance/update.php after upgrading? See: " . + "https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . "Query: $sql\n" . "Function: $fname\n" . "Error: $errno $error\n"; diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index a087f8277a..5a5eab14e9 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -78,12 +78,16 @@ class DatabaseMssql extends DatabaseBase { function open( $server, $user, $password, $dbName ) { # Test for driver support, to avoid suppressed fatal error if ( !function_exists( 'sqlsrv_connect' ) ) { - throw new DBConnectionError( $this, "MS Sql Server Native (sqlsrv) functions missing. You can download the driver from: http://go.microsoft.com/fwlink/?LinkId=123470\n" ); + throw new DBConnectionError( + $this, + "MS Sql Server Native (sqlsrv) functions missing. You can download " . + "the driver from: http://go.microsoft.com/fwlink/?LinkId=123470\n" ); } global $wgDBport; - if ( !strlen( $user ) ) { # e.g. the class is being loaded + # e.g. the class is being loaded + if ( !strlen( $user ) ) { return; } @@ -102,9 +106,11 @@ class DatabaseMssql extends DatabaseBase { // Start NT Auth Hack // Quick and dirty work around to provide NT Auth designation support. - // Current solution requires installer to know to input 'ntauth' for both username and password - // to trigger connection via NT Auth. - ugly, ugly, ugly - // TO-DO: Make this better and add NT Auth choice to MW installer when SQL Server option is chosen. + // Current solution requires installer to know to input 'ntauth' for + // both username and password to trigger connection via NT Auth. Ugly, + // ugly, ugly! + // @todo Make this better and add NT Auth choice to MW installer when + // SQL Server option is chosen. $ntAuthUserTest = strtolower( $user ); $ntAuthPassTest = strtolower( $password ); @@ -123,7 +129,8 @@ class DatabaseMssql extends DatabaseBase { if ( $this->mConn === false ) { wfDebug( "DB connection error\n" ); - wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); + wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . + substr( $password, 0, 3 ) . "...\n" ); wfDebug( $this->lastError() . "\n" ); return false; @@ -147,10 +154,11 @@ class DatabaseMssql extends DatabaseBase { wfDebug( "SQL: [$sql]\n" ); $this->offset = 0; - // several extensions seem to think that all databases support limits via LIMIT N after the WHERE clause - // well, MSSQL uses SELECT TOP N, so to catch any of those extensions we'll do a quick check for a LIMIT - // clause and pass $sql through $this->LimitToTopN() which parses the limit clause and passes the result to - // $this->limitResult(); + // several extensions seem to think that all databases support limits + // via LIMIT N after the WHERE clause well, MSSQL uses SELECT TOP N, + // so to catch any of those extensions we'll do a quick check for a + // LIMIT clause and pass $sql through $this->LimitToTopN() which parses + // the limit clause and passes the result to $this->limitResult(); if ( preg_match( '/\bLIMIT\s*/i', $sql ) ) { // massage LIMIT -> TopN $sql = $this->LimitToTopN( $sql ); @@ -165,7 +173,9 @@ class DatabaseMssql extends DatabaseBase { // perform query $stmt = sqlsrv_query( $this->mConn, $sql ); if ( $stmt == false ) { - $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . + $message = "A database error has occurred. Did you forget " . + "to run maintenance/update.php after upgrading? See: " . + "http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . "Query: " . htmlentities( $sql ) . "\n" . "Function: " . __METHOD__ . "\n"; // process each error (our driver will give us an array of errors unlike other providers) @@ -178,7 +188,8 @@ class DatabaseMssql extends DatabaseBase { // remember number of rows affected $this->mAffectedRows = sqlsrv_rows_affected( $stmt ); - // if it is a SELECT statement, or an insert with a request to output something we want to return a row. + // if it is a SELECT statement, or an insert with a request to output + // something we want to return a row. if ( ( preg_match( '#\bSELECT\s#i', $sql ) ) || ( preg_match( '#\bINSERT\s#i', $sql ) && preg_match( '#\bOUTPUT\s+INSERTED\b#i', $sql ) ) ) { @@ -302,13 +313,17 @@ class DatabaseMssql extends DatabaseBase { * @param $vars Mixed: array or string, field name(s) to be retrieved * @param $conds Mixed: array or string, condition(s) for WHERE * @param $fname String: calling function name (use __METHOD__) for logs/profiling - * @param array $options associative array of options (e.g. array('GROUP BY' => 'page_title')), - * see Database::makeSelectOptions code for list of supported stuff - * @param $join_conds Array: Associative array of table join conditions (optional) - * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) - * @return Mixed: database result resource (feed to Database::fetchObject or whatever), or false on failure + * @param array $options associative array of options (e.g. + * array('GROUP BY' => 'page_title')), see Database::makeSelectOptions + * code for list of supported stuff + * @param $join_conds Array: Associative array of table join conditions + * (optional) (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) + * @return Mixed: database result resource (feed to Database::fetchObject + * or whatever), or false on failure */ - function select( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() ) { + function select( $table, $vars, $conds = '', $fname = __METHOD__, + $options = array(), $join_conds = array() + ) { $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds ); if ( isset( $options['EXPLAIN'] ) ) { sqlsrv_query( $this->mConn, "SET SHOWPLAN_ALL ON;" ); @@ -334,7 +349,9 @@ class DatabaseMssql extends DatabaseBase { * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) * @return string, the SQL text */ - function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() ) { + function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, + $options = array(), $join_conds = array() + ) { if ( isset( $options['EXPLAIN'] ) ) { unset( $options['EXPLAIN'] ); } @@ -350,7 +367,9 @@ class DatabaseMssql extends DatabaseBase { * Takes same arguments as Database::select() * @return int */ - function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) { + function estimateRowCount( $table, $vars = '*', $conds = '', + $fname = __METHOD__, $options = array() + ) { // http://msdn2.microsoft.com/en-us/library/aa259203.aspx $options['EXPLAIN'] = true; $res = $this->select( $table, $vars, $conds, $fname, $options ); @@ -372,8 +391,9 @@ class DatabaseMssql extends DatabaseBase { * @return array|bool|null */ function indexInfo( $table, $index, $fname = __METHOD__ ) { - # This does not return the same info as MYSQL would, but that's OK because MediaWiki never uses the - # returned value except to check for the existance of indexes. + # This does not return the same info as MYSQL would, but that's OK + # because MediaWiki never uses the returned value except to check for + # the existance of indexes. $sql = "sp_helpindex '" . $table . "'"; $res = $this->query( $sql, $fname ); if ( !$res ) { @@ -437,8 +457,12 @@ class DatabaseMssql extends DatabaseBase { // We know the table we're inserting into, get its identity column $identity = null; - $tableRaw = preg_replace( '#\[([^\]]*)\]#', '$1', $table ); // strip matching square brackets from table name - $res = $this->doQuery( "SELECT NAME AS idColumn FROM SYS.IDENTITY_COLUMNS WHERE OBJECT_NAME(OBJECT_ID)='{$tableRaw}'" ); + // strip matching square brackets from table name + $tableRaw = preg_replace( '#\[([^\]]*)\]#', '$1', $table ); + $res = $this->doQuery( + "SELECT NAME AS idColumn FROM SYS.IDENTITY_COLUMNS " . + "WHERE OBJECT_NAME(OBJECT_ID)='{$tableRaw}'" + ); if ( $res && $res->numrows() ) { // There is an identity for this table. $identity = array_pop( $res->fetch( SQLSRV_FETCH_ASSOC ) ); @@ -446,7 +470,8 @@ class DatabaseMssql extends DatabaseBase { unset( $res ); foreach ( $arrToInsert as $a ) { - // start out with empty identity column, this is so we can return it as a result of the insert logic + // start out with empty identity column, this is so we can return + // it as a result of the insert logic $sqlPre = ''; $sqlPost = ''; $identityClause = ''; @@ -466,7 +491,9 @@ class DatabaseMssql extends DatabaseBase { } } } - $identityClause = "OUTPUT INSERTED.$identity "; // we want to output an identity column as result + + // we want to output an identity column as result + $identityClause = "OUTPUT INSERTED.$identity "; } $keys = array_keys( $a ); @@ -484,7 +511,8 @@ class DatabaseMssql extends DatabaseBase { // translate MySQL INSERT IGNORE to something SQL Server can use // example: // MySQL: INSERT IGNORE INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') - // MSSQL: IF NOT EXISTS (SELECT * FROM user_groups WHERE ug_user = '1') INSERT INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') + // MSSQL: IF NOT EXISTS (SELECT * FROM user_groups WHERE ug_user = '1') + // INSERT INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') if ( $ignoreClause ) { $prival = $a[$keys[0]]; $sqlPre .= "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = '$prival')"; @@ -542,13 +570,12 @@ class DatabaseMssql extends DatabaseBase { /** * INSERT SELECT wrapper * $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 Database::addQuotes() - * $conds may be "*" to copy the whole table - * srcTable may be an array of tables. + * Source items may be literals rather than field names, but strings should + * be quoted with Database::addQuotes(). * @param string $destTable - * @param array|string $srcTable + * @param array|string $srcTable May be an array of tables. * @param array $varMap - * @param array $conds + * @param array $conds May be "*" to copy the whole table. * @param string $fname * @param array $insertOptions * @param array $selectOptions @@ -557,7 +584,15 @@ class DatabaseMssql extends DatabaseBase { */ function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__, $insertOptions = array(), $selectOptions = array() ) { - $ret = parent::insertSelect( $destTable, $srcTable, $varMap, $conds, $fname, $insertOptions, $selectOptions ); + $ret = parent::insertSelect( + $destTable, + $srcTable, + $varMap, + $conds, + $fname, + $insertOptions, + $selectOptions + ); if ( $ret === false ) { throw new DBQueryError( $this, $this->getErrors(), $this->lastErrno(), /*$sql*/ '', $fname ); @@ -577,11 +612,15 @@ class DatabaseMssql extends DatabaseBase { */ function nextSequenceValue( $seqName ) { if ( !$this->tableExists( 'sequence_' . $seqName ) ) { - sqlsrv_query( $this->mConn, "CREATE TABLE [sequence_$seqName] (id INT NOT NULL IDENTITY PRIMARY KEY, junk varchar(10) NULL)" ); + sqlsrv_query( + $this->mConn, + "CREATE TABLE [sequence_$seqName] (id INT NOT NULL IDENTITY PRIMARY KEY, junk varchar(10) NULL)" + ); } sqlsrv_query( $this->mConn, "INSERT INTO [sequence_$seqName] (junk) VALUES ('')" ); $ret = sqlsrv_query( $this->mConn, "SELECT TOP 1 id FROM [sequence_$seqName] ORDER BY id DESC" ); - $row = sqlsrv_fetch_array( $ret, SQLSRV_FETCH_ASSOC ); // KEEP ASSOC THERE, weird weird bug dealing with the return value if you don't + // KEEP ASSOC THERE, weird weird bug dealing with the return value if you don't + $row = sqlsrv_fetch_array( $ret, SQLSRV_FETCH_ASSOC ); sqlsrv_free_stmt( $ret ); $this->mInsertId = $row['id']; @@ -648,9 +687,11 @@ class DatabaseMssql extends DatabaseBase { } } - // If there is a limit clause, parse it, strip it, and pass the remaining sql through limitResult() - // with the appropriate parameters. Not the prettiest solution, but better than building a whole new parser. - // This exists becase there are still too many extensions that don't use dynamic sql generation. + // If there is a limit clause, parse it, strip it, and pass the remaining + // SQL through limitResult() with the appropriate parameters. Not the + // prettiest solution, but better than building a whole new parser. This + // exists becase there are still too many extensions that don't use dynamic + // sql generation. function LimitToTopN( $sql ) { // Matches: LIMIT {[offset,] row_count | row_count OFFSET offset} $pattern = '/\bLIMIT\s+((([0-9]+)\s*,\s*)?([0-9]+)(\s+OFFSET\s+([0-9]+))?)/i'; @@ -788,7 +829,8 @@ class DatabaseMssql extends DatabaseBase { throw new MWException( "The identifier '$identifier' is too long (max. 128)" ); } if ( ( strpos( $identifier, '[' ) !== false ) || ( strpos( $identifier, ']' ) !== false ) ) { - // It may be allowed if you quoted with double quotation marks, but that would break if QUOTED_IDENTIFIER is OFF + // It may be allowed if you quoted with double quotation marks, but + // that would break if QUOTED_IDENTIFIER is OFF throw new MWException( "You can't use square brackers in the identifier '$identifier'" ); } @@ -1027,8 +1069,9 @@ class MssqlField implements Field { } /** - * The MSSQL PHP driver doesn't support sqlsrv_num_rows, so we recall all rows into an array and maintain our - * own cursor index into that array...This is similar to the way the Oracle driver handles this same issue + * The MSSQL PHP driver doesn't support sqlsrv_num_rows, so we recall all rows + * into an array and maintain our own cursor index into that array... This is + * similar to the way the Oracle driver handles this same issue * * @ingroup Database */ diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 1821e205bd..e253f91dd9 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -46,7 +46,10 @@ class DatabaseMysql extends DatabaseMysqlBase { # Fail now # Otherwise we get a suppressed fatal error, which is very hard to track down if ( !extension_loaded( 'mysql' ) ) { - throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" ); + throw new DBConnectionError( + $this, + "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" + ); } $connFlags = 0; diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 590b40b491..e0ad0032e0 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -192,7 +192,10 @@ abstract class DatabaseMysqlBase extends DatabaseBase { // these are the only errors mysql_fetch_object can cause. // See http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html. if ( $errno == 2000 || $errno == 2013 ) { - throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); + throw new DBUnexpectedError( + $this, + 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) + ); } return $row; @@ -225,7 +228,10 @@ abstract class DatabaseMysqlBase extends DatabaseBase { // these are the only errors mysql_fetch_array can cause. // See http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html. if ( $errno == 2000 || $errno == 2013 ) { - throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); + throw new DBUnexpectedError( + $this, + 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) + ); } return $row; @@ -385,7 +391,9 @@ abstract class DatabaseMysqlBase extends DatabaseBase { * @param $options string|array * @return int */ - public function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) { + public function estimateRowCount( $table, $vars = '*', $conds = '', + $fname = __METHOD__, $options = array() + ) { $options['EXPLAIN'] = true; $res = $this->select( $table, $vars, $conds, $fname, $options ); if ( $res === false ) { @@ -663,7 +671,9 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $row = $this->fetchObject( $res ); if ( $row ) { - $pos = isset( $row->Exec_master_log_pos ) ? $row->Exec_master_log_pos : $row->Exec_Master_Log_Pos; + $pos = isset( $row->Exec_master_log_pos ) + ? $row->Exec_master_log_pos + : $row->Exec_Master_Log_Pos; return new MySQLMasterPos( $row->Relay_Master_Log_File, $pos ); } else { @@ -771,7 +781,8 @@ abstract class DatabaseMysqlBase extends DatabaseBase { } /** - * FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock + * FROM MYSQL DOCS: + * http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock * @param $lockName string * @param $method string * @return bool @@ -1012,7 +1023,11 @@ abstract class DatabaseMysqlBase extends DatabaseBase { protected function getDefaultSchemaVars() { $vars = parent::getDefaultSchemaVars(); $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] ); - $vars['wgDBTableOptions'] = str_replace( 'CHARSET=mysql4', 'CHARSET=binary', $vars['wgDBTableOptions'] ); + $vars['wgDBTableOptions'] = str_replace( + 'CHARSET=mysql4', + 'CHARSET=binary', + $vars['wgDBTableOptions'] + ); return $vars; } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index c90f508622..13bb8ea26d 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -57,7 +57,8 @@ class ORAResult { function __construct( &$db, $stmt, $unique = false ) { $this->db =& $db; - if ( ( $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ) ) === false ) { + $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ); + if ( $this->nrows === false ) { $e = oci_error( $stmt ); $db->reportQueryError( $e['message'], $e['code'], '', __METHOD__ ); $this->free(); @@ -274,7 +275,11 @@ class DatabaseOracle extends DatabaseBase { function open( $server, $user, $password, $dbName ) { global $wgDBOracleDRCP; if ( !function_exists( 'oci_connect' ) ) { - throw new DBConnectionError( $this, "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n" ); + throw new DBConnectionError( + $this, + "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n " . + "(Note: if you recently installed PHP, you may need to restart your webserver\n " . + "and database)\n" ); } $this->close(); @@ -308,11 +313,29 @@ class DatabaseOracle extends DatabaseBase { wfSuppressWarnings(); if ( $this->mFlags & DBO_PERSISTENT ) { - $this->mConn = oci_pconnect( $this->mUser, $this->mPassword, $this->mServer, $this->defaultCharset, $session_mode ); + $this->mConn = oci_pconnect( + $this->mUser, + $this->mPassword, + $this->mServer, + $this->defaultCharset, + $session_mode + ); } elseif ( $this->mFlags & DBO_DEFAULT ) { - $this->mConn = oci_new_connect( $this->mUser, $this->mPassword, $this->mServer, $this->defaultCharset, $session_mode ); + $this->mConn = oci_new_connect( + $this->mUser, + $this->mPassword, + $this->mServer, + $this->defaultCharset, + $session_mode + ); } else { - $this->mConn = oci_connect( $this->mUser, $this->mPassword, $this->mServer, $this->defaultCharset, $session_mode ); + $this->mConn = oci_connect( + $this->mUser, + $this->mPassword, + $this->mServer, + $this->defaultCharset, + $session_mode + ); } wfRestoreWarnings(); @@ -367,7 +390,13 @@ class DatabaseOracle extends DatabaseBase { // you have to select data from plan table after explain $explain_id = MWTimestamp::getLocalInstance()->format( 'dmYHis' ); - $sql = preg_replace( '/^EXPLAIN /', 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR', $sql, 1, $explain_count ); + $sql = preg_replace( + '/^EXPLAIN /', + 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR', + $sql, + 1, + $explain_count + ); wfSuppressWarnings(); @@ -390,7 +419,8 @@ class DatabaseOracle extends DatabaseBase { wfRestoreWarnings(); if ( $explain_count > 0 ) { - return $this->doQuery( 'SELECT id, cardinality "ROWS" FROM plan_table WHERE statement_id = \'' . $explain_id . '\'' ); + return $this->doQuery( 'SELECT id, cardinality "ROWS" FROM plan_table ' . + 'WHERE statement_id = \'' . $explain_id . '\'' ); } elseif ( oci_statement_type( $stmt ) == 'SELECT' ) { return new ORAResult( $this, $stmt, $union_unique ); } else { @@ -755,13 +785,18 @@ class DatabaseOracle extends DatabaseBase { private function getSequenceData( $table ) { if ( $this->sequenceData == null ) { $result = $this->doQuery( "SELECT lower(asq.sequence_name), - lower(atc.table_name), - lower(atc.column_name) - FROM all_sequences asq, all_tab_columns atc - WHERE decode(atc.table_name, '{$this->mTablePrefix}MWUSER', '{$this->mTablePrefix}USER', atc.table_name) || '_' || - atc.column_name || '_SEQ' = '{$this->mTablePrefix}' || asq.sequence_name - AND asq.sequence_owner = upper('{$this->mDBname}') - AND atc.owner = upper('{$this->mDBname}')" ); + lower(atc.table_name), + lower(atc.column_name) + FROM all_sequences asq, all_tab_columns atc + WHERE decode( + atc.table_name, + '{$this->mTablePrefix}MWUSER', + '{$this->mTablePrefix}USER', + atc.table_name + ) || '_' || + atc.column_name || '_SEQ' = '{$this->mTablePrefix}' || asq.sequence_name + AND asq.sequence_owner = upper('{$this->mDBname}') + AND atc.owner = upper('{$this->mDBname}')" ); while ( ( $row = $result->fetchRow() ) !== false ) { $this->sequenceData[$row[1]] = array( @@ -805,14 +840,17 @@ class DatabaseOracle extends DatabaseBase { function unionQueries( $sqls, $all ) { $glue = ' UNION ALL '; - return 'SELECT * ' . ( $all ? '' : '/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')'; + return 'SELECT * ' . ( $all ? '' : '/* UNION_UNIQUE */ ' ) . + 'FROM (' . implode( $glue, $sqls ) . ')'; } function wasDeadlock() { return $this->lastErrno() == 'OCI-00060'; } - function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { + function duplicateTableStructure( $oldName, $newName, $temporary = false, + $fname = __METHOD__ + ) { $temporary = $temporary ? 'TRUE' : 'FALSE'; $newName = strtoupper( $newName ); @@ -822,7 +860,8 @@ class DatabaseOracle extends DatabaseBase { $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) ); $newPrefix = strtoupper( $this->mTablePrefix ); - return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', '$oldPrefix', '$newPrefix', $temporary ); END;" ); + return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', " . + "'$oldPrefix', '$newPrefix', $temporary ); END;" ); } function listTables( $prefix = null, $fname = __METHOD__ ) { @@ -832,7 +871,8 @@ class DatabaseOracle extends DatabaseBase { } $owner = strtoupper( $this->mDBname ); - $result = $this->doQuery( "SELECT table_name FROM all_tables WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" ); + $result = $this->doQuery( "SELECT table_name FROM all_tables " . + "WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" ); // dirty code ... i know $endArray = array(); @@ -895,7 +935,10 @@ class DatabaseOracle extends DatabaseBase { */ function getServerVersion() { //better version number, fallback on driver - $rset = $this->doQuery( 'SELECT version FROM product_component_version WHERE UPPER(product) LIKE \'ORACLE DATABASE%\'' ); + $rset = $this->doQuery( + 'SELECT version FROM product_component_version ' . + 'WHERE UPPER(product) LIKE \'ORACLE DATABASE%\'' + ); if ( !( $row = $rset->fetchRow() ) ) { return oci_server_version( $this->mConn ); } @@ -976,7 +1019,11 @@ class DatabaseOracle extends DatabaseBase { $tableWhere = '= \'' . $table . '\''; } - $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = \'' . $field . '\'' ); + $fieldInfoStmt = oci_parse( + $this->mConn, + 'SELECT * FROM wiki_field_info_full WHERE table_name ' . + $tableWhere . ' and column_name = \'' . $field . '\'' + ); if ( oci_execute( $fieldInfoStmt, $this->execFlags() ) === false ) { $e = oci_error( $fieldInfoStmt ); $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ ); @@ -1202,7 +1249,9 @@ class DatabaseOracle extends DatabaseBase { return $conds2; } - function selectRow( $table, $vars, $conds, $fname = __METHOD__, $options = array(), $join_conds = array() ) { + function selectRow( $table, $vars, $conds, $fname = __METHOD__, + $options = array(), $join_conds = array() + ) { if ( is_array( $conds ) ) { $conds = $this->wrapConditionsForWhere( $table, $conds ); } @@ -1260,17 +1309,27 @@ class DatabaseOracle extends DatabaseBase { // all deletions on these tables have transactions so final failure rollbacks these updates $table = $this->tableName( $table ); if ( $table == $this->tableName( 'user' ) ) { - $this->update( 'archive', array( 'ar_user' => 0 ), array( 'ar_user' => $conds['user_id'] ), $fname ); - $this->update( 'ipblocks', array( 'ipb_user' => 0 ), array( 'ipb_user' => $conds['user_id'] ), $fname ); - $this->update( 'image', array( 'img_user' => 0 ), array( 'img_user' => $conds['user_id'] ), $fname ); - $this->update( 'oldimage', array( 'oi_user' => 0 ), array( 'oi_user' => $conds['user_id'] ), $fname ); - $this->update( 'filearchive', array( 'fa_deleted_user' => 0 ), array( 'fa_deleted_user' => $conds['user_id'] ), $fname ); - $this->update( 'filearchive', array( 'fa_user' => 0 ), array( 'fa_user' => $conds['user_id'] ), $fname ); - $this->update( 'uploadstash', array( 'us_user' => 0 ), array( 'us_user' => $conds['user_id'] ), $fname ); - $this->update( 'recentchanges', array( 'rc_user' => 0 ), array( 'rc_user' => $conds['user_id'] ), $fname ); - $this->update( 'logging', array( 'log_user' => 0 ), array( 'log_user' => $conds['user_id'] ), $fname ); + $this->update( 'archive', array( 'ar_user' => 0 ), + array( 'ar_user' => $conds['user_id'] ), $fname ); + $this->update( 'ipblocks', array( 'ipb_user' => 0 ), + array( 'ipb_user' => $conds['user_id'] ), $fname ); + $this->update( 'image', array( 'img_user' => 0 ), + array( 'img_user' => $conds['user_id'] ), $fname ); + $this->update( 'oldimage', array( 'oi_user' => 0 ), + array( 'oi_user' => $conds['user_id'] ), $fname ); + $this->update( 'filearchive', array( 'fa_deleted_user' => 0 ), + array( 'fa_deleted_user' => $conds['user_id'] ), $fname ); + $this->update( 'filearchive', array( 'fa_user' => 0 ), + array( 'fa_user' => $conds['user_id'] ), $fname ); + $this->update( 'uploadstash', array( 'us_user' => 0 ), + array( 'us_user' => $conds['user_id'] ), $fname ); + $this->update( 'recentchanges', array( 'rc_user' => 0 ), + array( 'rc_user' => $conds['user_id'] ), $fname ); + $this->update( 'logging', array( 'log_user' => 0 ), + array( 'log_user' => $conds['user_id'] ), $fname ); } elseif ( $table == $this->tableName( 'image' ) ) { - $this->update( 'oldimage', array( 'oi_name' => 0 ), array( 'oi_name' => $conds['img_name'] ), $fname ); + $this->update( 'oldimage', array( 'oi_name' => 0 ), + array( 'oi_name' => $conds['img_name'] ), $fname ); } return parent::delete( $table, $conds, $fname ); diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 2f34799c81..cfa2074b78 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -326,8 +326,10 @@ class DatabasePostgres extends DatabaseBase { } function hasConstraint( $name ) { - $SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" . - pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->getCoreSchema() ) . "'"; + $SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n " . + "WHERE c.connamespace = n.oid AND conname = '" . + pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . + pg_escape_string( $this->mConn, $this->getCoreSchema() ) . "'"; $res = $this->doQuery( $SQL ); return $this->numRows( $res ); @@ -345,7 +347,12 @@ class DatabasePostgres extends DatabaseBase { function open( $server, $user, $password, $dbName ) { # Test for Postgres support, to avoid suppressed fatal error if ( !function_exists( 'pg_connect' ) ) { - throw new DBConnectionError( $this, "Postgres functions missing, have you compiled PHP with the --with-pgsql option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n" ); + throw new DBConnectionError( + $this, + "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" . + "option? (Note: if you recently installed PHP, you may need to restart your\n" . + "webserver and database)\n" + ); } global $wgDBport; @@ -390,7 +397,8 @@ class DatabasePostgres extends DatabaseBase { if ( !$this->mConn ) { wfDebug( "DB connection error\n" ); - wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); + wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . + substr( $password, 0, 3 ) . "...\n" ); wfDebug( $this->lastError() . "\n" ); throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) ); } @@ -483,7 +491,8 @@ class DatabasePostgres extends DatabaseBase { PGSQL_DIAG_SOURCE_FUNCTION ); foreach ( $diags as $d ) { - wfDebug( sprintf( "PgSQL ERROR(%d): %s\n", $d, pg_result_error_field( $this->mLastResult, $d ) ) ); + wfDebug( sprintf( "PgSQL ERROR(%d): %s\n", + $d, pg_result_error_field( $this->mLastResult, $d ) ) ); } } @@ -530,7 +539,10 @@ class DatabasePostgres extends DatabaseBase { # @todo hashar: not sure if the following test really trigger if the object # fetching failed. if ( pg_last_error( $this->mConn ) ) { - throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); + throw new DBUnexpectedError( + $this, + 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) + ); } return $row; @@ -544,7 +556,10 @@ class DatabasePostgres extends DatabaseBase { $row = pg_fetch_array( $res ); wfRestoreWarnings(); if ( pg_last_error( $this->mConn ) ) { - throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); + throw new DBUnexpectedError( + $this, + 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) + ); } return $row; @@ -558,7 +573,10 @@ class DatabasePostgres extends DatabaseBase { $n = pg_num_rows( $res ); wfRestoreWarnings(); if ( pg_last_error( $this->mConn ) ) { - throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); + throw new DBUnexpectedError( + $this, + 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) + ); } return $n; @@ -638,7 +656,9 @@ class DatabasePostgres extends DatabaseBase { * Takes same arguments as Database::select() * @return int */ - function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) { + function estimateRowCount( $table, $vars = '*', $conds = '', + $fname = __METHOD__, $options = array() + ) { $options['EXPLAIN'] = true; $res = $this->select( $table, $vars, $conds, $fname, $options ); $rows = -1; @@ -876,7 +896,8 @@ __INDEXATTR__; /** * INSERT SELECT wrapper * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...) - * Source items may be literals rather then field names, but strings should be quoted with Database::addQuotes() + * Source items may be literals rather then field names, but strings should + * be quoted with Database::addQuotes() * $conds may be "*" to copy the whole table * srcTable may be an array of tables. * @todo FIXME: Implement this a little better (seperate select/insert)? @@ -1017,7 +1038,8 @@ __INDEXATTR__; $newName = $this->addIdentifierQuotes( $newName ); $oldName = $this->addIdentifierQuotes( $oldName ); - return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname ); + return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName " . + "(LIKE $oldName INCLUDING DEFAULTS)", $fname ); } function listTables( $prefix = null, $fname = __METHOD__ ) { @@ -1196,7 +1218,8 @@ __INDEXATTR__; } } else { $this->mCoreSchema = $this->getCurrentSchema(); - wfDebug( "Schema \"" . $desired_schema . "\" not found, using current \"" . $this->mCoreSchema . "\"\n" ); + wfDebug( "Schema \"" . $desired_schema . "\" not found, using current \"" . + $this->mCoreSchema . "\"\n" ); } /* Commit SET otherwise it will be rollbacked on error or IGNORE SELECT */ $this->commit( __METHOD__ ); @@ -1543,7 +1566,8 @@ SQL; } /** - * See http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKSFROM PG DOCS: http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS + * See http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKSFROM + * PG DOCS: http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS * @param $lockName string * @param $method string * @return bool diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 1dccc311fb..89f0818e5e 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -206,8 +206,10 @@ class DatabaseSqlite extends DatabaseBase { * Attaches external database to our connection, see http://sqlite.org/lang_attach.html * for details. * - * @param string $name database name to be used in queries like SELECT foo FROM dbname.table - * @param string $file database file name. If omitted, will be generated using $name and $wgSQLiteDataDir + * @param string $name database name to be used in queries like + * SELECT foo FROM dbname.table + * @param string $file database file name. If omitted, will be generated + * using $name and $wgSQLiteDataDir * @param string $fname calling function name * * @return ResultWrapper @@ -660,7 +662,9 @@ class DatabaseSqlite extends DatabaseBase { * @return string User-friendly database information */ public function getServerInfo() { - return wfMessage( self::getFulltextSearchModule() ? 'sqlite-has-fts' : 'sqlite-no-fts', $this->getServerVersion() )->text(); + return wfMessage( self::getFulltextSearchModule() + ? 'sqlite-has-fts' + : 'sqlite-no-fts', $this->getServerVersion() )->text(); } /** @@ -812,7 +816,11 @@ class DatabaseSqlite extends DatabaseBase { // INT -> INTEGER $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s ); // floating point types -> REAL - $s = preg_replace( '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i', 'REAL', $s ); + $s = preg_replace( + '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i', + 'REAL', + $s + ); // varchar -> TEXT $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s ); // TEXT normalization @@ -874,13 +882,19 @@ class DatabaseSqlite extends DatabaseBase { * @return bool|ResultWrapper */ function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { - $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname ); + $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . + $this->addQuotes( $oldName ) . " AND type='table'", $fname ); $obj = $this->fetchObject( $res ); if ( !$obj ) { throw new MWException( "Couldn't retrieve structure for table $oldName" ); } $sql = $obj->sql; - $sql = preg_replace( '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/', $this->addIdentifierQuotes( $newName ), $sql, 1 ); + $sql = preg_replace( + '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/', + $this->addIdentifierQuotes( $newName ), + $sql, + 1 + ); if ( $temporary ) { if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) { wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" ); diff --git a/includes/db/DatabaseUtility.php b/includes/db/DatabaseUtility.php index ed57cb7a8b..de5be08811 100644 --- a/includes/db/DatabaseUtility.php +++ b/includes/db/DatabaseUtility.php @@ -279,8 +279,9 @@ class FakeResultWrapper extends ResultWrapper { } /** - * Used by DatabaseBase::buildLike() to represent characters that have special meaning in SQL LIKE clauses - * and thus need no escaping. Don't instantiate it manually, use DatabaseBase::anyChar() and anyString() instead. + * Used by DatabaseBase::buildLike() to represent characters that have special + * meaning in SQL LIKE clauses and thus need no escaping. Don't instantiate it + * manually, use DatabaseBase::anyChar() and anyString() instead. */ class LikeMatch { private $str; diff --git a/includes/db/IORMTable.php b/includes/db/IORMTable.php index d38ec9750b..9e9c526c17 100644 --- a/includes/db/IORMTable.php +++ b/includes/db/IORMTable.php @@ -62,8 +62,9 @@ interface IORMTable { * * array * * blob * - * TODO: get rid of the id field. Every row instance needs to have - * one so this is just causing hassle at various locations by requiring an extra check for field name. + * @todo Get rid of the id field. Every row instance needs to have one so + * this is just causing hassle at various locations by requiring an extra + * check for field name. * * @since 1.20 * @@ -315,14 +316,16 @@ interface IORMTable { * * @since 1.20 * - * @return String|bool The target wiki, in a form that LBFactory understands (or false if the local wiki is used) + * @return String|bool The target wiki, in a form that LBFactory + * understands (or false if the local wiki is used) */ public function getTargetWiki(); /** * Set the ID of the any foreign wiki to use as a target for database operations * - * @param string|bool $wiki The target wiki, in a form that LBFactory understands (or false if the local wiki shall be used) + * @param string|bool $wiki The target wiki, in a form that LBFactory + * understands (or false if the local wiki shall be used) * * @since 1.20 */ diff --git a/includes/db/LBFactory.php b/includes/db/LBFactory.php index 36cccdae45..6e377ff7be 100644 --- a/includes/db/LBFactory.php +++ b/includes/db/LBFactory.php @@ -328,6 +328,7 @@ class LBFactory_Fake extends LBFactory { */ class DBAccessError extends MWException { function __construct() { - parent::__construct( "Mediawiki tried to access the database via wfGetDB(). This is not allowed." ); + parent::__construct( "Mediawiki tried to access the database via wfGetDB(). " . + "This is not allowed." ); } } diff --git a/includes/db/LBFactory_Multi.php b/includes/db/LBFactory_Multi.php index b9239ce69a..a37a560505 100644 --- a/includes/db/LBFactory_Multi.php +++ b/includes/db/LBFactory_Multi.php @@ -28,14 +28,28 @@ * Configuration: * sectionsByDB A map of database names to section names * - * sectionLoads A 2-d map. For each section, gives a map of server names to load ratios. - * For example: array( 'section1' => array( 'db1' => 100, 'db2' => 100 ) ) + * sectionLoads A 2-d map. For each section, gives a map of server names to + * load ratios. For example: + * array( + * 'section1' => array( + * 'db1' => 100, + * 'db2' => 100 + * ) + * ) * - * serverTemplate A server info associative array as documented for $wgDBservers. The host, - * hostName and load entries will be overridden. + * serverTemplate A server info associative array as documented for $wgDBservers. + * The host, hostName and load entries will be overridden. * - * groupLoadsBySection A 3-d map giving server load ratios for each section and group. For example: - * array( 'section1' => array( 'group1' => array( 'db1' => 100, 'db2' => 100 ) ) ) + * groupLoadsBySection A 3-d map giving server load ratios for each section and group. + * For example: + * array( + * 'section1' => array( + * 'group1' => array( + * 'db1' => 100, + * 'db2' => 100 + * ) + * ) + * ) * * groupLoadsByDB A 3-d map giving server load ratios by DB name. * @@ -43,16 +57,19 @@ * * externalLoads A map of external storage cluster name to server load map * - * externalTemplateOverrides A set of server info keys overriding serverTemplate for external storage + * externalTemplateOverrides A set of server info keys overriding serverTemplate for external + * storage * - * templateOverridesByServer A 2-d map overriding serverTemplate and externalTemplateOverrides on a - * server-by-server basis. Applies to both core and external storage. + * templateOverridesByServer A 2-d map overriding serverTemplate and + * externalTemplateOverrides on a server-by-server basis. Applies + * to both core and external storage. * * templateOverridesByCluster A 2-d map overriding the server info by external storage cluster * * masterTemplateOverrides An override array for all master servers. * - * readOnlyBySection A map of section name to read-only message. Missing or false for read/write. + * readOnlyBySection A map of section name to read-only message. + * Missing or false for read/write. * * @ingroup Database */ @@ -132,11 +149,16 @@ class LBFactory_Multi extends LBFactory { if ( isset( $this->groupLoadsByDB[$dbName] ) ) { $groupLoads = $this->groupLoadsByDB[$dbName]; } + if ( isset( $this->groupLoadsBySection[$section] ) ) { $groupLoads = array_merge_recursive( $groupLoads, $this->groupLoadsBySection[$section] ); } - return $this->newLoadBalancer( $this->serverTemplate, $this->sectionLoads[$section], $groupLoads ); + return $this->newLoadBalancer( + $this->serverTemplate, + $this->sectionLoads[$section], + $groupLoads + ); } /** diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 0a218abd51..fa3dbc004a 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -457,10 +457,12 @@ class LoadBalancer { if ( $i == DB_LAST ) { wfProfileOut( __METHOD__ ); - throw new MWException( 'Attempt to call ' . __METHOD__ . ' with deprecated server index DB_LAST' ); + throw new MWException( 'Attempt to call ' . __METHOD__ . + ' with deprecated server index DB_LAST' ); } elseif ( $i === null || $i === false ) { wfProfileOut( __METHOD__ ); - throw new MWException( 'Attempt to call ' . __METHOD__ . ' with invalid server index' ); + throw new MWException( 'Attempt to call ' . __METHOD__ . + ' with invalid server index' ); } if ( $wiki === wfWikiID() ) { @@ -550,7 +552,8 @@ class LoadBalancer { return; } if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) { - throw new MWException( __METHOD__ . ": connection not found, has the connection been freed already?" ); + throw new MWException( __METHOD__ . ": connection not found, has " . + "the connection been freed already?" ); } $conn->setLBInfo( 'foreignPoolRefCount', --$refCount ); if ( $refCount <= 0 ) { @@ -854,7 +857,8 @@ class LoadBalancer { } /** - * Sets the server info structure for the given index. Entry at index $i is created if it doesn't exist + * Sets the server info structure for the given index. Entry at index $i + * is created if it doesn't exist * @param $i * @param $serverInfo */ diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php index 5f0f4f5691..1d1120293a 100644 --- a/includes/db/ORMRow.php +++ b/includes/db/ORMRow.php @@ -456,8 +456,9 @@ class ORMRow implements IORMRow { /** * Before removal of an object happens, @see beforeRemove gets called. - * This method loads the fields of which the names have been returned by this one (or all fields if null is returned). - * This allows for loading info needed after removal to get rid of linked data and the like. + * This method loads the fields of which the names have been returned by + * this one (or all fields if null is returned). This allows for loading + * info needed after removal to get rid of linked data and the like. * * @since 1.20 * diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php index 8026e31e68..cdc905bb13 100644 --- a/includes/db/ORMTable.php +++ b/includes/db/ORMTable.php @@ -95,7 +95,9 @@ class ORMTable extends DBAccessBase implements IORMTable { * @param string|null $rowClass * @param string $fieldPrefix */ - public function __construct( $tableName = '', array $fields = array(), array $defaults = array(), $rowClass = null, $fieldPrefix = '' ) { + public function __construct( $tableName = '', array $fields = array(), + array $defaults = array(), $rowClass = null, $fieldPrefix = '' + ) { $this->tableName = $tableName; $this->fields = $fields; $this->defaults = $defaults; @@ -542,7 +544,9 @@ class ORMTable extends DBAccessBase implements IORMTable { } if ( $setDefaults && $hasDefault ) { - $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field]; + $default = is_array( $defaults[$field] ) + ? implode( '|', $defaults[$field] ) + : $defaults[$field]; $params[$field][ApiBase::PARAM_DFLT] = $default; } } @@ -575,7 +579,8 @@ class ORMTable extends DBAccessBase implements IORMTable { } /** - * Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup. + * Set the database ID to use for read operations, use DB_XXX constants or + * an index to the load balancer setup. * * @param integer $db * @@ -590,7 +595,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * * @since 1.20 * - * @return String|bool The target wiki, in a form that LBFactory understands (or false if the local wiki is used) + * @return String|bool The target wiki, in a form that LBFactory understands + * (or false if the local wiki is used) */ public function getTargetWiki() { return $this->wiki; @@ -599,7 +605,8 @@ class ORMTable extends DBAccessBase implements IORMTable { /** * Set the ID of the any foreign wiki to use as a target for database operations * - * @param string|bool $wiki The target wiki, in a form that LBFactory understands (or false if the local wiki shall be used) + * @param string|bool $wiki The target wiki, in a form that LBFactory + * understands (or false if the local wiki shall be used) * * @since 1.20 */ -- 2.20.1