From: Siebrand Mazeland Date: Wed, 20 Nov 2013 06:58:22 +0000 (+0100) Subject: Update formatting on database-related classes X-Git-Tag: 1.31.0-rc.0~17978^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=1e10dcd3aa3776c70dff407e5bb82361d9229af5;p=lhc%2Fweb%2Fwiklou.git Update formatting on database-related classes Change-Id: I91f83e28ae25f80ba9e36c612f1ad050ffa1573c --- diff --git a/includes/db/ChronologyProtector.php b/includes/db/ChronologyProtector.php index de5e72c372..3d1f453c30 100644 --- a/includes/db/ChronologyProtector.php +++ b/includes/db/ChronologyProtector.php @@ -83,6 +83,7 @@ class ChronologyProtector { $info = $lb->parentInfo(); if ( !$db || !$db->doneWrites() ) { wfDebug( __METHOD__ . ": LB {$info['id']}, no writes done\n" ); + return; } $pos = $db->getMasterPos(); diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index 819925cb24..d197a9c50e 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -25,7 +25,6 @@ */ class CloneDatabase { - /** * Table prefix for cloning * @var String @@ -66,8 +65,8 @@ class CloneDatabase { * @param $dropCurrentTables bool */ public function __construct( DatabaseBase $db, array $tablesToClone, - $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true ) - { + $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true + ) { $this->db = $db; $this->tablesToClone = $tablesToClone; $this->newTablePrefix = $newTablePrefix; diff --git a/includes/db/Database.php b/includes/db/Database.php index e2c59edb6b..4d02af424f 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -208,7 +208,8 @@ interface DatabaseType { * Interface for classes that implement or wrap DatabaseBase * @ingroup Database */ -interface IDatabase {} +interface IDatabase { +} /** * Database abstraction object @@ -626,7 +627,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { /** * Clear a flag for this connection * - * @param $flag: same as setFlag()'s $flag param + * @param $flag : same as setFlag()'s $flag param */ public function clearFlag( $flag ) { global $wgDebugDBTransactions; @@ -639,7 +640,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { /** * Returns a boolean whether the flag $flag is set for this connection * - * @param $flag: same as setFlag()'s $flag param + * @param $flag : same as setFlag()'s $flag param * @return Boolean */ public function getFlag( $flag ) { @@ -764,7 +765,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { /** * Given a DB type, construct the name of the appropriate child class of * DatabaseBase. This is designed to replace all of the manual stuff like: - * $class = 'Database' . ucfirst( strtolower( $dbType ) ); + * $class = 'Database' . ucfirst( strtolower( $dbType ) ); * as well as validate against the canonical list of DB types we have * * This factory function is mostly useful for when you need to connect to a @@ -784,11 +785,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { */ final public static function factory( $dbType, $p = array() ) { $canonicalDBTypes = array( - 'mysql' => array( 'mysqli', 'mysql' ), + 'mysql' => array( 'mysqli', 'mysql' ), 'postgres' => array(), - 'sqlite' => array(), - 'oracle' => array(), - 'mssql' => array(), + 'sqlite' => array(), + 'oracle' => array(), + 'mssql' => array(), ); $driver = false; @@ -829,6 +830,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { 'tablePrefix' => isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global', 'foreign' => isset( $p['foreign'] ) ? $p['foreign'] : false ); + return new $class( $params ); } else { return null; @@ -852,6 +854,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( $this->mPHPError ) { $error = preg_replace( '!\[\]!', '', $this->mPHPError ); $error = preg_replace( '!^.*?:\s?(.*)$!', '$1', $error ); + return $error; } else { return false; @@ -891,6 +894,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { $ret = $this->closeConnection(); $this->mConn = false; + return $ret; } else { return true; @@ -987,8 +991,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { # If DBO_TRX is set, start a transaction if ( ( $this->mFlags & DBO_TRX ) && !$this->mTrxLevel && - $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK' ) - { + $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK' + ) { # Avoid establishing transactions for SHOW and SET statements too - # that would delay transaction initializations to once connection # is really used by application @@ -1362,6 +1366,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { : $options['HAVING']; $sql .= ' HAVING ' . $having; } + return $sql; } @@ -1378,8 +1383,10 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { $ob = is_array( $options['ORDER BY'] ) ? implode( ',', $options['ORDER BY'] ) : $options['ORDER BY']; + return ' ORDER BY ' . $ob; } + return ''; } @@ -1546,8 +1553,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @see DatabaseBase::select() */ public function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, - $options = array(), $join_conds = array() ) - { + $options = array(), $join_conds = array() + ) { if ( is_array( $vars ) ) { $vars = implode( ',', $this->fieldNamesWithAlias( $vars ) ); } @@ -1611,8 +1618,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @return object|bool */ public function selectRow( $table, $vars, $conds, $fname = __METHOD__, - $options = array(), $join_conds = array() ) - { + $options = array(), $join_conds = array() + ) { $options = (array)$options; $options['LIMIT'] = 1; $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds ); @@ -1651,8 +1658,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @return Integer: row count */ public function estimateRowCount( $table, $vars = '*', $conds = '', - $fname = __METHOD__, $options = array() ) - { + $fname = __METHOD__, $options = array() + ) { $rows = 0; $res = $this->select( $table, array( 'rowcount' => 'COUNT(*)' ), $conds, $fname, $options ); @@ -1905,7 +1912,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @param $table String 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, + * @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(). @@ -2099,6 +2106,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { $delim, $table, $field, $conds = '', $join_conds = array() ) { $fld = "GROUP_CONCAT($field SEPARATOR " . $this->addQuotes( $delim ) . ')'; + return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')'; } @@ -2116,6 +2124,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { # if your database engine supports a concept similar to MySQL's # databases you may as well. $this->mDBname = $db; + return true; } @@ -2285,6 +2294,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { } $retval[] = $this->tableNameWithAlias( $table, $alias ); } + return $retval; } @@ -2318,6 +2328,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { } $retval[] = $this->fieldNameWithAlias( $field, $alias ); } + return $retval; } @@ -2751,8 +2762,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @throws DBUnexpectedError */ public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, - $fname = __METHOD__ ) - { + $fname = __METHOD__ + ) { if ( !$conds ) { throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' ); @@ -2863,8 +2874,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { */ public function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__, - $insertOptions = array(), $selectOptions = array() ) - { + $insertOptions = array(), $selectOptions = array() + ) { $destTable = $this->tableName( $destTable ); if ( is_array( $insertOptions ) ) { @@ -2923,6 +2934,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( !is_numeric( $limit ) ) { throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" ); } + return "$sql LIMIT " . ( ( is_numeric( $offset ) && $offset != 0 ) ? "{$offset}," : "" ) . "{$limit} "; @@ -2947,6 +2959,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { */ public function unionQueries( $sqls, $all ) { $glue = $all ? ') UNION ALL (' : ') UNION ('; + return '(' . implode( $glue, $sqls ) . ')'; } @@ -2963,6 +2976,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( is_array( $cond ) ) { $cond = $this->makeList( $cond, LIST_AND ); } + return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; } @@ -3083,9 +3097,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( $tries <= 0 ) { $this->rollback( __METHOD__ ); $this->reportQueryError( $error, $errno, $sql, $fname ); + return false; } else { $this->commit( __METHOD__ ); + return $retVal; } } @@ -3110,15 +3126,18 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { 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; } } @@ -3138,6 +3157,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( !is_null( $this->mFakeSlaveLag ) ) { $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag ); wfDebug( __METHOD__ . ": fake slave pos = $pos\n" ); + return $pos; } else { # Stub @@ -3216,7 +3236,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { $this->clearFlag( DBO_TRX ); // make each query its own transaction call_user_func( $phpCallback ); $this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin() - } catch ( Exception $e ) {} + } catch ( Exception $e ) { + } } } while ( count( $this->mTrxIdleCallbacks ) ); @@ -3239,7 +3260,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { try { list( $phpCallback ) = $callback; call_user_func( $phpCallback ); - } catch ( Exception $e ) {} + } catch ( Exception $e ) { + } } } while ( count( $this->mTrxPreCommitCallbacks ) ); @@ -3511,8 +3533,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * For caching purposes the list of all views should be stored in * $this->allViews. The process cache can be cleared with clearViewsCache() * - * @param string $prefix Only show VIEWs with this prefix, eg. unit_test_ - * @param string $fname Name of calling function + * @param string $prefix Only show VIEWs with this prefix, eg. unit_test_ + * @param string $fname Name of calling function * @throws MWException * @since 1.22 */ @@ -3696,8 +3718,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { try { $error = $this->sourceStream( $fp, $lineCallback, $resultCallback, $fname, $inputCallback ); - } - catch ( MWException $e ) { + } catch ( MWException $e ) { fclose( $fp ); throw $e; } @@ -3751,8 +3772,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { * @return bool|string */ public function sourceStream( $fp, $lineCallback = false, $resultCallback = false, - $fname = __METHOD__, $inputCallback = false ) - { + $fname = __METHOD__, $inputCallback = false + ) { $cmd = ''; while ( !feof( $fp ) ) { @@ -3790,6 +3811,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( false === $res ) { $err = $this->lastError(); + return "Query \"{$cmd}\" failed with error code \"$err\".\n"; } } @@ -3815,6 +3837,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { return true; } } + return false; } @@ -3845,6 +3868,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { // replace /*$var*/ $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $value ), $ins ); } + return $ins; } @@ -3998,6 +4022,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { if ( $this->cascadingDeletes() ) { $sql .= " CASCADE"; } + return $this->query( $sql, $fName ); } @@ -4078,7 +4103,6 @@ abstract class DatabaseBase implements IDatabase, DatabaseType { $callers = array(); foreach ( $this->mTrxIdleCallbacks as $callbackInfo ) { $callers[] = $callbackInfo[1]; - } $callers = implode( ', ', $callers ); trigger_error( "DB transaction callbacks still pending (from $callers)." ); diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index f14a5025e5..36b82f4640 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -26,7 +26,6 @@ * @ingroup Database */ class DBError extends MWException { - /** * @var DatabaseBase */ @@ -129,6 +128,7 @@ class DBConnectionError extends DBError { } else { $message = $fallback; } + return wfMsgReplaceArgs( $message, $args ); } @@ -202,6 +202,7 @@ class DBConnectionError extends DBError { // Output cached page with notices on bottom and re-close body echo "{$cache}
{$this->getHTML()}"; + return; } } catch ( MWException $e ) { @@ -246,6 +247,7 @@ class DBConnectionError extends DBError {

EOT; + return $trygoogle; } @@ -408,12 +410,13 @@ This may indicate a bug in the software.', 'databaseerror-function' => 'Function: $1', 'databaseerror-error' => 'Error: $1', ); + return $messages[$key]; } - } /** * @ingroup Database */ -class DBUnexpectedError extends DBError {} +class DBUnexpectedError extends DBError { +} diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 240a097ce2..a087f8277a 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -125,10 +125,12 @@ class DatabaseMssql extends DatabaseBase { wfDebug( "DB connection error\n" ); wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); wfDebug( $this->lastError() . "\n" ); + return false; } $this->mOpened = true; + return $this->mConn; } @@ -178,7 +180,8 @@ class DatabaseMssql extends DatabaseBase { // 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 ) ) ) { + ( preg_match( '#\bINSERT\s#i', $sql ) && preg_match( '#\bOUTPUT\s+INSERTED\b#i', $sql ) ) + ) { // this is essentially a rowset, but Mediawiki calls these 'result' // the rowset owns freeing the statement $res = new MssqlResult( $stmt ); @@ -186,6 +189,7 @@ class DatabaseMssql extends DatabaseBase { // otherwise we simply return it was successful, failure throws an exception $res = true; } + return $res; } @@ -201,6 +205,7 @@ class DatabaseMssql extends DatabaseBase { $res = $res->result; } $row = $res->fetch( 'OBJECT' ); + return $row; } @@ -216,6 +221,7 @@ class DatabaseMssql extends DatabaseBase { } else { $strRet = "No errors found"; } + return $strRet; } @@ -224,6 +230,7 @@ class DatabaseMssql extends DatabaseBase { $res = $res->result; } $row = $res->fetch( SQLSRV_FETCH_BOTH ); + return $row; } @@ -231,6 +238,7 @@ class DatabaseMssql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return ( $res ) ? $res->numrows() : 0; } @@ -238,6 +246,7 @@ class DatabaseMssql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return ( $res ) ? $res->numfields() : 0; } @@ -245,6 +254,7 @@ class DatabaseMssql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return ( $res ) ? $res->fieldname( $n ) : 0; } @@ -260,6 +270,7 @@ class DatabaseMssql extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return ( $res ) ? $res->seek( $row ) : false; } @@ -294,18 +305,19 @@ class DatabaseMssql extends DatabaseBase { * @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') ) + * (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;" ); $ret = $this->query( $sql, $fname ); sqlsrv_query( $this->mConn, "SET SHOWPLAN_ALL OFF;" ); + return $ret; } + return $this->query( $sql, $fname ); } @@ -316,7 +328,7 @@ 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')), + * @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') ) @@ -326,6 +338,7 @@ class DatabaseMssql extends DatabaseBase { if ( isset( $options['EXPLAIN'] ) ) { unset( $options['EXPLAIN'] ); } + return parent::selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds ); } @@ -338,7 +351,8 @@ class DatabaseMssql extends DatabaseBase { * @return int */ function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) { - $options['EXPLAIN'] = true;// http://msdn2.microsoft.com/en-us/library/aa259203.aspx + // http://msdn2.microsoft.com/en-us/library/aa259203.aspx + $options['EXPLAIN'] = true; $res = $this->select( $table, $vars, $conds, $fname, $options ); $rows = -1; @@ -348,6 +362,7 @@ class DatabaseMssql extends DatabaseBase { $rows = $row['EstimateRows']; } } + return $rows; } @@ -383,6 +398,7 @@ class DatabaseMssql extends DatabaseBase { } } } + return empty( $result ) ? false : $result; } @@ -413,8 +429,8 @@ class DatabaseMssql extends DatabaseBase { $table = $this->tableName( $table ); - if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) {// Not multi row - $arrToInsert = array( 0 => $arrToInsert );// make everything multi row compatible + if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) { // Not multi row + $arrToInsert = array( 0 => $arrToInsert ); // make everything multi row compatible } $allOk = true; @@ -444,7 +460,6 @@ class DatabaseMssql extends DatabaseBase { // there is a value being passed to us, we need to turn on and off inserted identity $sqlPre = "SET IDENTITY_INSERT $table ON;"; $sqlPost = ";SET IDENTITY_INSERT $table OFF;"; - } else { // we can't insert NULL into an identity column, so remove the column from the insert. unset( $a[$k] ); @@ -520,6 +535,7 @@ class DatabaseMssql extends DatabaseBase { } $allOk = false; } + return $allOk; } @@ -548,8 +564,10 @@ class DatabaseMssql extends DatabaseBase { } elseif ( $ret != null ) { // remember number of rows affected $this->mAffectedRows = sqlsrv_rows_affected( $ret ); + return $ret; } + return null; } @@ -563,10 +581,11 @@ class DatabaseMssql extends DatabaseBase { } 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 + $row = sqlsrv_fetch_array( $ret, SQLSRV_FETCH_ASSOC ); // KEEP ASSOC THERE, weird weird bug dealing with the return value if you don't sqlsrv_free_stmt( $ret ); $this->mInsertId = $row['id']; + return $row['id']; } @@ -579,6 +598,7 @@ class DatabaseMssql extends DatabaseBase { if ( $ret !== false ) { $row = sqlsrv_fetch_array( $ret ); sqlsrv_free_stmt( $ret ); + return $row['id']; } else { return $this->nextSequenceValue( $seqName ); @@ -596,6 +616,7 @@ class DatabaseMssql extends DatabaseBase { if ( strtolower( $row['DATA_TYPE'] ) != 'text' ) { $size = $row['CHARACTER_MAXIMUM_LENGTH']; } + return $size; } @@ -622,6 +643,7 @@ class DatabaseMssql extends DatabaseBase { ) as sub2 ) AS sub3 WHERE line3 BETWEEN ' . ( $offset + 1 ) . ' AND ' . ( $offset + $limit ); + return $sql; } } @@ -637,13 +659,15 @@ class DatabaseMssql extends DatabaseBase { $row_count = $matches[4]; // offset = $matches[3] OR $matches[6] $offset = $matches[3] or - $offset = $matches[6] or - $offset = false; + $offset = $matches[6] or + $offset = false; // strip the matching LIMIT clause out $sql = str_replace( $matches[0], '', $sql ); + return $this->limitResult( $sql, $row_count, $offset ); } + return $sql; } @@ -667,6 +691,7 @@ class DatabaseMssql extends DatabaseBase { if ( isset( $server_info['SQLServerVersion'] ) ) { $version = $server_info['SQLServerVersion']; } + return $version; } @@ -675,6 +700,7 @@ class DatabaseMssql extends DatabaseBase { WHERE table_type='BASE TABLE' AND table_name = '$table'" ); if ( $res === false ) { print "Error in tableExists query: " . $this->getErrors(); + return false; } if ( sqlsrv_fetch( $res ) ) { @@ -694,6 +720,7 @@ class DatabaseMssql extends DatabaseBase { WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" ); if ( $res === false ) { print "Error in fieldExists query: " . $this->getErrors(); + return false; } if ( sqlsrv_fetch( $res ) ) { @@ -709,12 +736,14 @@ class DatabaseMssql extends DatabaseBase { WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" ); if ( $res === false ) { print "Error in fieldInfo query: " . $this->getErrors(); + return false; } $meta = $this->fetchRow( $res ); if ( $meta ) { return new MssqlField( $meta ); } + return false; } @@ -762,6 +791,7 @@ class DatabaseMssql extends DatabaseBase { // 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'" ); } + return "[$identifier]"; } @@ -825,13 +855,13 @@ class DatabaseMssql extends DatabaseBase { } function encodeBlob( $b ) { - // we can't have zero's and such, this is a simple encoding to make sure we don't barf + // we can't have zero's and such, this is a simple encoding to make sure we don't barf return base64_encode( $b ); } function decodeBlob( $b ) { - // we can't have zero's and such, this is a simple encoding to make sure we don't barf - return base64_decode( $b ); + // we can't have zero's and such, this is a simple encoding to make sure we don't barf + return base64_decode( $b ); } /** @@ -868,6 +898,7 @@ class DatabaseMssql extends DatabaseBase { // We can't separate explicit JOIN clauses with ',', use ' ' for those $straightJoins = !empty( $ret ) ? implode( ',', $ret ) : ""; $otherJoins = !empty( $retJOIN ) ? implode( ' ', $retJOIN ) : ""; + // Compile our final table clause return implode( ' ', array( $straightJoins, $otherJoins ) ); } @@ -951,7 +982,6 @@ class DatabaseMssql extends DatabaseBase { public function getInfinity() { return '3000-01-31 00:00:00.000'; } - } // end DatabaseMssql class /** @@ -961,6 +991,7 @@ class DatabaseMssql extends DatabaseBase { */ class MssqlField implements Field { private $name, $tablename, $default, $max_length, $nullable, $type; + function __construct( $info ) { $this->name = $info['COLUMN_NAME']; $this->tablename = $info['TABLE_NAME']; @@ -1014,11 +1045,11 @@ class MssqlResult { foreach ( $rows as $row ) { if ( $row !== null ) { foreach ( $row as $k => $v ) { - if ( is_object( $v ) && method_exists( $v, 'format' ) ) {// DateTime Object + if ( is_object( $v ) && method_exists( $v, 'format' ) ) { // DateTime Object $row[$k] = $v->format( "Y-m-d\TH:i:s\Z" ); } } - $this->mRows[] = $row;// read results into memory, cursors are not supported + $this->mRows[] = $row; // read results into memory, cursors are not supported } } $this->mRowCount = count( $this->mRows ); @@ -1036,6 +1067,7 @@ class MssqlResult { } } } + return $obj; } @@ -1067,6 +1099,7 @@ class MssqlResult { } $this->mCursor++; + return $ret; } @@ -1088,6 +1121,7 @@ class MssqlResult { public function fieldname( $nr ) { $arrKeys = array_keys( $this->mRows[0] ); + return $arrKeys[$nr]; } @@ -1193,6 +1227,7 @@ class MssqlResult { default: $strType = $intType; } + return $strType; } diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 1314b122fb..1821e205bd 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -28,7 +28,6 @@ * @see Database */ class DatabaseMysql extends DatabaseMysqlBase { - /** * @param $sql string * @return resource @@ -39,6 +38,7 @@ class DatabaseMysql extends DatabaseMysqlBase { } else { $ret = mysql_unbuffered_query( $sql, $this->mConn ); } + return $ret; } @@ -129,6 +129,7 @@ class DatabaseMysql extends DatabaseMysqlBase { */ function selectDB( $db ) { $this->mDBname = $db; + return mysql_select_db( $db, $this->mConn ); } diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 6a3ebcb6cb..590b40b491 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -94,6 +94,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { substr( $password, 0, 3 ) . "..., error: " . $error . "\n" ); wfProfileOut( __METHOD__ ); + return $this->reportConnectionError( $error ); } @@ -107,6 +108,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { "from client host " . wfHostname() . "\n" ); wfProfileOut( __METHOD__ ); + return $this->reportConnectionError( "Error selecting database $dbName" ); } } @@ -126,6 +128,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $this->mOpened = true; wfProfileOut( __METHOD__ ); + return true; } @@ -191,6 +194,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $errno == 2000 || $errno == 2013 ) { throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); } + return $row; } @@ -223,6 +227,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $errno == 2000 || $errno == 2013 ) { throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); } + return $row; } @@ -246,6 +251,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { wfSuppressWarnings(); $n = $this->mysqlNumRows( $res ); wfRestoreWarnings(); + // Unfortunately, mysql_num_rows does not reset the last errno. // We are not checking for any errors here, since // these are no errors mysql_num_rows can cause. @@ -270,6 +276,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return $this->mysqlNumFields( $res ); } @@ -290,6 +297,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return $this->mysqlFieldName( $res, $n ); } @@ -311,6 +319,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return $this->mysqlDataSeek( $res, $row ); } @@ -341,6 +350,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $error ) { $error .= ' (' . $this->mServer . ')'; } + return $error; } @@ -389,6 +399,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { foreach ( $res as $plan ) { $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero } + return $rows; } @@ -410,6 +421,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { return new MySQLField( $meta ); } } + return false; } @@ -452,6 +464,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $result[] = $row; } } + return empty( $result ) ? false : $result; } @@ -467,6 +480,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $this->ping(); $sQuoted = $this->mysqlRealEscapeString( $s ); } + return $sQuoted; } @@ -504,6 +518,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $this->mOpened = false; $this->mConn = false; $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); + return true; } @@ -524,6 +539,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { function getLag() { if ( !is_null( $this->mFakeSlaveLag ) ) { wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" ); + return $this->mFakeSlaveLag; } @@ -577,7 +593,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $row->State != 'Waiting to reconnect after a failed master event read' && $row->State != 'Reconnecting after a failed master event read' && $row->State != 'Registering slave on master' - ) { + ) { # This is it, return the time (except -ve) if ( $row->Time > 0x7fffffff ) { return false; @@ -586,6 +602,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { } } } + return false; } @@ -609,6 +626,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( !is_null( $this->mFakeSlaveLag ) ) { $status = parent::masterPosWait( $pos, $timeout ); wfProfileOut( __METHOD__ ); + return $status; } @@ -627,6 +645,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { } wfProfileOut( __METHOD__ ); + return $status; } @@ -645,6 +664,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( $row ) { $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 { return false; @@ -710,6 +730,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $this->delimiter = $m[1]; $newLine = ''; } + return parent::streamStatementEnd( $sql, $newLine ); } @@ -725,6 +746,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $lockName = $this->addQuotes( $lockName ); $result = $this->query( "SELECT IS_FREE_LOCK($lockName) AS lockstatus", $method ); $row = $this->fetchObject( $result ); + return ( $row->lockstatus == 1 ); } @@ -743,6 +765,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { return true; } else { wfDebug( __METHOD__ . " failed to acquire lock\n" ); + return false; } } @@ -757,6 +780,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $lockName = $this->addQuotes( $lockName ); $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method ); $row = $this->fetchObject( $result ); + return ( $row->lockstatus == 1 ); } @@ -772,8 +796,8 @@ abstract class DatabaseMysqlBase extends DatabaseBase { foreach ( $write as $table ) { $tbl = $this->tableName( $table ) . - ( $lowPriority ? ' LOW_PRIORITY' : '' ) . - ' WRITE'; + ( $lowPriority ? ' LOW_PRIORITY' : '' ) . + ' WRITE'; $items[] = $tbl; } foreach ( $read as $table ) { @@ -781,6 +805,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { } $sql = "LOCK TABLES " . implode( ',', $items ); $this->query( $sql, $method ); + return true; } @@ -790,6 +815,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { */ public function unlockTables( $method ) { $this->query( "UNLOCK TABLES", $method ); + return true; } @@ -887,6 +913,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { */ function getServerUptime() { $vars = $this->getMysqlStatus( 'Uptime' ); + return (int)$vars['Uptime']; } @@ -975,6 +1002,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { if ( !$this->tableExists( $tableName, $fName ) ) { return false; } + return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName ); } @@ -985,6 +1013,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $vars = parent::getDefaultSchemaVars(); $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] ); $vars['wgDBTableOptions'] = str_replace( 'CHARSET=mysql4', 'CHARSET=binary', $vars['wgDBTableOptions'] ); + return $vars; } @@ -1008,9 +1037,9 @@ abstract class DatabaseMysqlBase extends DatabaseBase { /** * Lists VIEWs in the database * - * @param string $prefix Only show VIEWs with this prefix, eg. + * @param string $prefix Only show VIEWs with this prefix, eg. * unit_test_, or $wgDBprefix. Default: null, would return all views. - * @param string $fname Name of calling function + * @param string $fname Name of calling function * @return array * @since 1.22 */ @@ -1040,6 +1069,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { array_push( $filteredViews, $viewName ); } } + return $filteredViews; } @@ -1053,11 +1083,8 @@ abstract class DatabaseMysqlBase extends DatabaseBase { public function isView( $name, $prefix = null ) { return in_array( $name, $this->listViews( $prefix ) ); } - } - - /** * Utility class. * @ingroup Database @@ -1152,12 +1179,14 @@ class MySQLMasterPos implements DBMasterPos { if ( preg_match( '!\.(\d+)/(\d+)$!', (string)$this, $m ) ) { return array( (int)$m[1], (int)$m[2] ); } + return false; } function hasReached( MySQLMasterPos $pos ) { $thisPos = $this->getCoordinates(); $thatPos = $pos->getCoordinates(); + return ( $thisPos && $thatPos && $thisPos >= $thatPos ); } } diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php index a47c8042fd..9f18da3bbe 100644 --- a/includes/db/DatabaseMysqli.php +++ b/includes/db/DatabaseMysqli.php @@ -29,7 +29,6 @@ * @see Database */ class DatabaseMysqli extends DatabaseMysqlBase { - /** * @param $sql string * @return resource @@ -40,6 +39,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { } else { $ret = $this->mConn->query( $sql, MYSQLI_USE_RESULT ); } + return $ret; } @@ -70,8 +70,8 @@ class DatabaseMysqli extends DatabaseMysqlBase { usleep( 1000 ); } if ( $mysqli->real_connect( $realServer, $this->mUser, - $this->mPassword, $this->mDBname, null, null, $connFlags ) ) - { + $this->mPassword, $this->mDBname, null, null, $connFlags ) + ) { return $mysqli; } } @@ -128,6 +128,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { */ function selectDB( $db ) { $this->mDBname = $db; + return $this->mConn->select_db( $db ); } @@ -140,6 +141,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { protected function mysqlFreeResult( $res ) { $res->free_result(); + return true; } @@ -148,6 +150,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { if ( $object === null ) { return false; } + return $object; } @@ -156,6 +159,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { if ( $array === null ) { return false; } + return $array; } @@ -174,11 +178,13 @@ class DatabaseMysqli extends DatabaseMysqlBase { $field->unique_key = $field->flags & MYSQLI_UNIQUE_KEY_FLAG; $field->multiple_key = $field->flags & MYSQLI_MULTIPLE_KEY_FLAG; $field->binary = $field->flags & MYSQLI_BINARY_FLAG; + return $field; } protected function mysqlFieldName( $res, $n ) { $field = $res->fetch_field_direct( $n ); + return $field->name; } @@ -201,5 +207,4 @@ class DatabaseMysqli extends DatabaseMysqlBase { protected function mysqlPing() { return $this->mConn->ping(); } - } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 6b4113e9a1..c90f508622 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -57,10 +57,11 @@ 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 ) { + if ( ( $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ) ) === false ) { $e = oci_error( $stmt ); $db->reportQueryError( $e['message'], $e['code'], '', __METHOD__ ); $this->free(); + return; } @@ -121,6 +122,7 @@ class ORAResult { $ret[$lc] = $v; $ret[$k] = $v; } + return $ret; } } @@ -235,21 +237,27 @@ class DatabaseOracle extends DatabaseBase { function cascadingDeletes() { return true; } + function cleanupTriggers() { return true; } + function strictIPs() { return true; } + function realTimestamps() { return true; } + function implicitGroupby() { return false; } + function implicitOrderby() { return false; } + function searchableIPs() { return true; } @@ -323,6 +331,7 @@ class DatabaseOracle extends DatabaseBase { $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' ); $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' ); $this->doQuery( 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'' ); + return $this->mConn; } @@ -365,6 +374,7 @@ class DatabaseOracle extends DatabaseBase { if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } @@ -372,6 +382,7 @@ class DatabaseOracle extends DatabaseBase { $e = oci_error( $stmt ); if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) { $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } } @@ -384,6 +395,7 @@ class DatabaseOracle extends DatabaseBase { return new ORAResult( $this, $stmt, $union_unique ); } else { $this->mAffectedRows = oci_num_rows( $stmt ); + return true; } } @@ -458,6 +470,7 @@ class DatabaseOracle extends DatabaseBase { } else { $e = oci_error( $this->mConn ); } + return $e['message']; } @@ -467,6 +480,7 @@ class DatabaseOracle extends DatabaseBase { } else { $e = oci_error( $this->mConn ); } + return $e['code']; } @@ -524,6 +538,7 @@ class DatabaseOracle extends DatabaseBase { if ( is_numeric( $col ) ) { $bind = $val; $val = null; + return $bind; } elseif ( $includeCol ) { $bind = "$col = "; @@ -574,6 +589,7 @@ class DatabaseOracle extends DatabaseBase { if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } foreach ( $row as $col => &$val ) { @@ -596,6 +612,7 @@ class DatabaseOracle extends DatabaseBase { if ( oci_bind_by_name( $stmt, ":$col", $val, -1, SQLT_CHR ) === false ) { $e = oci_error( $stmt ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } } else { @@ -610,10 +627,10 @@ class DatabaseOracle extends DatabaseBase { if ( $col_type == 'BLOB' ) { $lob[$col]->writeTemporary( $val, OCI_TEMP_BLOB ); - oci_bind_by_name( $stmt, ":$col", $lob[$col], - 1, OCI_B_BLOB ); + oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_BLOB ); } else { $lob[$col]->writeTemporary( $val, OCI_TEMP_CLOB ); - oci_bind_by_name( $stmt, ":$col", $lob[$col], - 1, OCI_B_CLOB ); + oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_CLOB ); } } } @@ -624,6 +641,7 @@ class DatabaseOracle extends DatabaseBase { $e = oci_error( $stmt ); if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) { $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } else { $this->mAffectedRows = oci_num_rows( $stmt ); @@ -648,8 +666,8 @@ class DatabaseOracle extends DatabaseBase { } function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__, - $insertOptions = array(), $selectOptions = array() ) - { + $insertOptions = array(), $selectOptions = array() + ) { $destTable = $this->tableName( $destTable ); if ( !is_array( $selectOptions ) ) { $selectOptions = array( $selectOptions ); @@ -662,8 +680,8 @@ class DatabaseOracle extends DatabaseBase { } if ( ( $sequenceData = $this->getSequenceData( $destTable ) ) !== false && - !isset( $varMap[$sequenceData['column']] ) ) - { + !isset( $varMap[$sequenceData['column']] ) + ) { $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')'; } @@ -714,8 +732,10 @@ class DatabaseOracle extends DatabaseBase { function tableNameInternal( $name ) { $name = $this->tableName( $name ); + return preg_replace( '/.*\.(.*)/', '$1', $name ); } + /** * Return the next in a sequence, save the value for retrieval via insertId() * @return null @@ -724,6 +744,7 @@ class DatabaseOracle extends DatabaseBase { $res = $this->query( "SELECT $seqName.nextval FROM dual" ); $row = $this->fetchRow( $res ); $this->mInsertId = $row[0]; + return $this->mInsertId; } @@ -750,12 +771,14 @@ class DatabaseOracle extends DatabaseBase { } } $table = strtolower( $this->removeIdentifierQuotes( $this->tableName( $table ) ) ); + return ( isset( $this->sequenceData[$table] ) ) ? $this->sequenceData[$table] : false; } # Returns the size of a text field, or -1 for "unlimited" function textFieldSize( $table, $field ) { $fieldInfoData = $this->fieldInfo( $table, $field ); + return $fieldInfoData->maxLength(); } @@ -763,6 +786,7 @@ class DatabaseOracle extends DatabaseBase { if ( $offset === false ) { $offset = 0; } + return "SELECT * FROM ($sql) WHERE rownum >= (1 + $offset) AND rownum < (1 + $limit + $offset)"; } @@ -774,11 +798,13 @@ class DatabaseOracle extends DatabaseBase { if ( $b instanceof Blob ) { $b = $b->fetch(); } + return $b; } function unionQueries( $sqls, $all ) { $glue = ' UNION ALL '; + return 'SELECT * ' . ( $all ? '' : '/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')'; } @@ -873,6 +899,7 @@ class DatabaseOracle extends DatabaseBase { if ( !( $row = $rset->fetchRow() ) ) { return oci_server_version( $this->mConn ); } + return $row['version']; } @@ -893,6 +920,7 @@ class DatabaseOracle extends DatabaseBase { } else { $count = 0; } + return $count != 0; } @@ -913,6 +941,7 @@ class DatabaseOracle extends DatabaseBase { } $res->free(); + return $exists; } @@ -951,6 +980,7 @@ class DatabaseOracle extends DatabaseBase { if ( oci_execute( $fieldInfoStmt, $this->execFlags() ) === false ) { $e = oci_error( $fieldInfoStmt ); $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ ); + return false; } $res = new ORAResult( $this, $fieldInfoStmt ); @@ -969,6 +999,7 @@ class DatabaseOracle extends DatabaseBase { $this->mFieldInfoCache["$table.$field"] = $fieldInfoTemp; } $res->free(); + return $fieldInfoTemp; } @@ -982,6 +1013,7 @@ class DatabaseOracle extends DatabaseBase { if ( is_array( $table ) ) { throw new DBUnexpectedError( $this, 'DatabaseOracle::fieldInfo called with table array!' ); } + return $this->fieldInfoMulti( $table, $field ); } @@ -1018,7 +1050,7 @@ class DatabaseOracle extends DatabaseBase { $replacements = array(); - while ( ! feof( $fp ) ) { + while ( !feof( $fp ) ) { if ( $lineCallback ) { call_user_func( $lineCallback ); } @@ -1028,7 +1060,7 @@ class DatabaseOracle extends DatabaseBase { if ( $sl < 0 ) { continue; } - if ( '-' == $line { 0 } && '-' == $line { 1 } ) { + if ( '-' == $line{0} && '-' == $line{1} ) { continue; } @@ -1042,7 +1074,7 @@ class DatabaseOracle extends DatabaseBase { $dollarquote = true; } } elseif ( !$dollarquote ) { - if ( ';' == $line { $sl } && ( $sl < 2 || ';' != $line { $sl - 1 } ) ) { + if ( ';' == $line{$sl} && ( $sl < 2 || ';' != $line{$sl - 1} ) ) { $done = true; $line = substr( $line, 0, $sl ); } @@ -1075,6 +1107,7 @@ class DatabaseOracle extends DatabaseBase { if ( false === $res ) { $err = $this->lastError(); + return "Query \"{$cmd}\" failed with error code \"$err\".\n"; } } @@ -1083,6 +1116,7 @@ class DatabaseOracle extends DatabaseBase { $done = false; } } + return true; } @@ -1101,8 +1135,10 @@ class DatabaseOracle extends DatabaseBase { if ( $e['code'] != '1435' ) { $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); } + return false; } + return true; } @@ -1115,6 +1151,7 @@ class DatabaseOracle extends DatabaseBase { if ( isset( $wgContLang->mLoaded ) && $wgContLang->mLoaded ) { $s = $wgContLang->checkTitleEncoding( $s ); } + return "'" . $this->strencode( $s ) . "'"; } @@ -1122,6 +1159,7 @@ class DatabaseOracle extends DatabaseBase { if ( !$this->getFlag( DBO_DDLMODE ) ) { $s = '/*Q*/' . $s; } + return $s; } @@ -1160,6 +1198,7 @@ class DatabaseOracle extends DatabaseBase { $conds2[$col] = $val; } } + return $conds2; } @@ -1167,6 +1206,7 @@ class DatabaseOracle extends DatabaseBase { if ( is_array( $conds ) ) { $conds = $this->wrapConditionsForWhere( $table, $conds ); } + return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds ); } @@ -1203,7 +1243,7 @@ class DatabaseOracle extends DatabaseBase { $startOpts .= 'DISTINCT'; } - if ( isset( $options['USE INDEX'] ) && ! is_array( $options['USE INDEX'] ) ) { + if ( isset( $options['USE INDEX'] ) && !is_array( $options['USE INDEX'] ) ) { $useIndex = $this->useIndexClause( $options['USE INDEX'] ); } else { $useIndex = ''; @@ -1220,18 +1260,19 @@ 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 ); } @@ -1262,6 +1303,7 @@ class DatabaseOracle extends DatabaseBase { if ( ( $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ) ) === false ) { $e = oci_error( $this->mConn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } foreach ( $values as $col => &$val ) { @@ -1283,6 +1325,7 @@ class DatabaseOracle extends DatabaseBase { if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) { $e = oci_error( $stmt ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } } else { @@ -1293,10 +1336,10 @@ class DatabaseOracle extends DatabaseBase { if ( $col_type == 'BLOB' ) { $lob[$col]->writeTemporary( $val ); - oci_bind_by_name( $stmt, ":$col", $lob[$col], - 1, SQLT_BLOB ); + oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, SQLT_BLOB ); } else { $lob[$col]->writeTemporary( $val ); - oci_bind_by_name( $stmt, ":$col", $lob[$col], - 1, OCI_B_CLOB ); + oci_bind_by_name( $stmt, ":$col", $lob[$col], -1, OCI_B_CLOB ); } } } @@ -1307,6 +1350,7 @@ class DatabaseOracle extends DatabaseBase { $e = oci_error( $stmt ); if ( !$this->ignore_DUP_VAL_ON_INDEX || $e['code'] != '1' ) { $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); + return false; } else { $this->mAffectedRows = oci_num_rows( $stmt ); @@ -1358,6 +1402,7 @@ class DatabaseOracle extends DatabaseBase { $delim, $table, $field, $conds = '', $join_conds = array() ) { $fld = "LISTAGG($field," . $this->addQuotes( $delim ) . ") WITHIN GROUP (ORDER BY $field)"; + return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')'; } @@ -1368,5 +1413,4 @@ class DatabaseOracle extends DatabaseBase { public function getInfinity() { return '31-12-2030 12:00:00.000000'; } - } // end DatabaseOracle class diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 46880009cd..2f34799c81 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -79,6 +79,7 @@ SQL; $n->conname = $row->conname; $n->has_default = ( $row->atthasdef === 't' ); $n->default = $row->adsrc; + return $n; } @@ -113,6 +114,7 @@ SQL; function conname() { return $this->conname; } + /** * @since 1.19 */ @@ -123,7 +125,6 @@ SQL; return false; } } - } /** @@ -181,7 +182,6 @@ class PostgresTransactionState { } $old = next( $this->mCurrentState ); $new = next( $this->mNewState ); - } } } @@ -224,8 +224,8 @@ class SavepointPostgres { $this->didbegin = false; /* If we are not in a transaction, we need to be for savepoint trickery */ if ( !$dbw->trxLevel() ) { - $dbw->begin( "FOR SAVEPOINT" ); - $this->didbegin = true; + $dbw->begin( "FOR SAVEPOINT" ); + $this->didbegin = true; } } @@ -247,10 +247,10 @@ class SavepointPostgres { global $wgDebugDBTransactions; if ( $this->dbw->doQuery( $keyword . " " . $this->id ) !== false ) { if ( $wgDebugDBTransactions ) { - wfDebug( sprintf ( $msg_ok, $this->id ) ); + wfDebug( sprintf( $msg_ok, $this->id ) ); } } else { - wfDebug( sprintf ( $msg_failed, $this->id ) ); + wfDebug( sprintf( $msg_failed, $this->id ) ); } } @@ -296,32 +296,40 @@ class DatabasePostgres extends DatabaseBase { function cascadingDeletes() { return true; } + function cleanupTriggers() { return true; } + function strictIPs() { return true; } + function realTimestamps() { return true; } + function implicitGroupby() { return false; } + function implicitOrderby() { return false; } + function searchableIPs() { return true; } + function functionalIndexes() { return true; } 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() ) . "'"; + pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->getCoreSchema() ) . "'"; $res = $this->doQuery( $SQL ); + return $this->numRows( $res ); } @@ -428,6 +436,7 @@ class DatabasePostgres extends DatabaseBase { foreach ( $vars as $name => $value ) { $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' "; } + return $s; } @@ -454,22 +463,25 @@ class DatabasePostgres extends DatabaseBase { if ( pg_result_error( $this->mLastResult ) ) { return false; } + return $this->mLastResult; } protected function dumpError() { - $diags = array( PGSQL_DIAG_SEVERITY, - PGSQL_DIAG_SQLSTATE, - PGSQL_DIAG_MESSAGE_PRIMARY, - PGSQL_DIAG_MESSAGE_DETAIL, - PGSQL_DIAG_MESSAGE_HINT, - PGSQL_DIAG_STATEMENT_POSITION, - PGSQL_DIAG_INTERNAL_POSITION, - PGSQL_DIAG_INTERNAL_QUERY, - PGSQL_DIAG_CONTEXT, - PGSQL_DIAG_SOURCE_FILE, - PGSQL_DIAG_SOURCE_LINE, - PGSQL_DIAG_SOURCE_FUNCTION ); + $diags = array( + PGSQL_DIAG_SEVERITY, + PGSQL_DIAG_SQLSTATE, + PGSQL_DIAG_MESSAGE_PRIMARY, + PGSQL_DIAG_MESSAGE_DETAIL, + PGSQL_DIAG_MESSAGE_HINT, + PGSQL_DIAG_STATEMENT_POSITION, + PGSQL_DIAG_INTERNAL_POSITION, + PGSQL_DIAG_INTERNAL_QUERY, + PGSQL_DIAG_CONTEXT, + PGSQL_DIAG_SOURCE_FILE, + PGSQL_DIAG_SOURCE_LINE, + PGSQL_DIAG_SOURCE_FUNCTION + ); foreach ( $diags as $d ) { wfDebug( sprintf( "PgSQL ERROR(%d): %s\n", $d, pg_result_error_field( $this->mLastResult, $d ) ) ); } @@ -481,6 +493,7 @@ class DatabasePostgres extends DatabaseBase { /* Check for constraint violation */ if ( $errno === '23505' ) { parent::reportQueryError( $error, $errno, $sql, $fname, $tempIgnore ); + return; } } @@ -519,6 +532,7 @@ class DatabasePostgres extends DatabaseBase { if ( pg_last_error( $this->mConn ) ) { throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); } + return $row; } @@ -532,6 +546,7 @@ class DatabasePostgres extends DatabaseBase { if ( pg_last_error( $this->mConn ) ) { throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); } + return $row; } @@ -545,6 +560,7 @@ class DatabasePostgres extends DatabaseBase { if ( pg_last_error( $this->mConn ) ) { throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) ); } + return $n; } @@ -552,6 +568,7 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return pg_num_fields( $res ); } @@ -559,6 +576,7 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return pg_field_name( $res, $n ); } @@ -576,6 +594,7 @@ class DatabasePostgres extends DatabaseBase { if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return pg_result_seek( $res, $row ); } @@ -590,6 +609,7 @@ class DatabasePostgres extends DatabaseBase { return 'No database connection'; } } + function lastErrno() { if ( $this->mLastResult ) { return pg_result_error_field( $this->mLastResult, PGSQL_DIAG_SQLSTATE ); @@ -606,6 +626,7 @@ class DatabasePostgres extends DatabaseBase { if ( empty( $this->mLastResult ) ) { return 0; } + return pg_affected_rows( $this->mLastResult ); } @@ -628,6 +649,7 @@ class DatabasePostgres extends DatabaseBase { $rows = $count[1]; } } + return $rows; } @@ -647,6 +669,7 @@ class DatabasePostgres extends DatabaseBase { return $row; } } + return false; } @@ -709,6 +732,7 @@ __INDEXATTR__; } else { return null; } + return $a; } @@ -724,6 +748,7 @@ __INDEXATTR__; foreach ( $res as $row ) { return true; } + return false; } @@ -858,8 +883,7 @@ __INDEXATTR__; * @return bool */ function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__, - $insertOptions = array(), $selectOptions = array() ) - { + $insertOptions = array(), $selectOptions = array() ) { $destTable = $this->tableName( $destTable ); if ( !is_array( $insertOptions ) ) { @@ -889,8 +913,8 @@ __INDEXATTR__; } $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' . - " SELECT $startOpts " . implode( ',', $varMap ) . - " FROM $srcTable $useIndex"; + " SELECT $startOpts " . implode( ',', $varMap ) . + " FROM $srcTable $useIndex"; if ( $conds != '*' ) { $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); @@ -946,6 +970,7 @@ __INDEXATTR__; $res = $this->query( "SELECT nextval('$safeseq')" ); $row = $this->fetchRow( $res ); $this->mInsertId = $row[0]; + return $this->mInsertId; } @@ -958,6 +983,7 @@ __INDEXATTR__; $res = $this->query( "SELECT currval('$safeseq')" ); $row = $this->fetchRow( $res ); $currval = $row[0]; + return $currval; } @@ -975,6 +1001,7 @@ __INDEXATTR__; } else { $size = $row->size; } + return $size; } @@ -989,6 +1016,7 @@ __INDEXATTR__; function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { $newName = $this->addIdentifierQuotes( $newName ); $oldName = $this->addIdentifierQuotes( $oldName ); + return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname ); } @@ -1044,8 +1072,8 @@ __INDEXATTR__; $text, $match, 0, $offset ); $offset += strlen( $match[0] ); $output[] = ( '"' != $match[1][0] - ? $match[1] - : stripcslashes( substr( $match[1], 1, -1 ) ) ); + ? $match[1] + : stripcslashes( substr( $match[1], 1, -1 ) ) ); if ( '},' == $match[3] ) { return $output; } @@ -1053,6 +1081,7 @@ __INDEXATTR__; $offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 ); } } while ( $limit > $offset ); + return $output; } @@ -1080,6 +1109,7 @@ __INDEXATTR__; function getCurrentSchema() { $res = $this->query( "SELECT current_schema()", __METHOD__ ); $row = $this->fetchRow( $res ); + return $row[0]; } @@ -1097,7 +1127,9 @@ __INDEXATTR__; $res = $this->query( "SELECT current_schemas(false)", __METHOD__ ); $row = $this->fetchRow( $res ); $schemas = array(); + /* PHP pgsql support does not support array type, "{a,b}" string is returned */ + return $this->pg_array_parse( $row[0], $schemas ); } @@ -1113,7 +1145,9 @@ __INDEXATTR__; function getSearchPath() { $res = $this->query( "SHOW search_path", __METHOD__ ); $row = $this->fetchRow( $res ); + /* PostgreSQL returns SHOW values as strings */ + return explode( ",", $row[0] ); } @@ -1155,7 +1189,7 @@ __INDEXATTR__; */ $search_path = $this->getSearchPath(); array_unshift( $search_path, - $this->addIdentifierQuotes( $desired_schema )); + $this->addIdentifierQuotes( $desired_schema ) ); $this->setSearchPath( $search_path ); $this->mCoreSchema = $desired_schema; wfDebug( "Schema \"" . $desired_schema . "\" added to the search path\n" ); @@ -1195,6 +1229,7 @@ __INDEXATTR__; $this->numeric_version = pg_parameter_status( $this->mConn, 'server_version' ); } } + return $this->numeric_version; } @@ -1218,6 +1253,7 @@ __INDEXATTR__; . "AND c.relkind IN ('" . implode( "','", $types ) . "')"; $res = $this->query( $SQL ); $count = $res ? $res->numRows() : 0; + return (bool)$count; } @@ -1253,6 +1289,7 @@ SQL; return null; } $rows = $res->numRows(); + return $rows; } @@ -1264,12 +1301,13 @@ SQL; 'schemaname' => $this->getCoreSchema() ) ); + return $exists === $rule; } function constraintExists( $table, $constraint ) { $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints " . - "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s", + "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s", $this->addQuotes( $this->getCoreSchema() ), $this->addQuotes( $table ), $this->addQuotes( $constraint ) @@ -1279,6 +1317,7 @@ SQL; return null; } $rows = $res->numRows(); + return $rows; } @@ -1289,6 +1328,7 @@ SQL; function schemaExists( $schema ) { $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1, array( 'nspname' => $schema ), __METHOD__ ); + return (bool)$exists; } @@ -1299,6 +1339,7 @@ SQL; function roleExists( $roleName ) { $exists = $this->selectField( '"pg_catalog"."pg_roles"', 1, array( 'rolname' => $roleName ), __METHOD__ ); + return (bool)$exists; } @@ -1314,6 +1355,7 @@ SQL; if ( $res instanceof ResultWrapper ) { $res = $res->result; } + return pg_field_type( $res, $index ); } @@ -1329,6 +1371,7 @@ SQL; if ( $b instanceof Blob ) { $b = $b->fetch(); } + return pg_unescape_bytea( $b ); } @@ -1348,6 +1391,7 @@ SQL; } elseif ( $s instanceof Blob ) { return "'" . $s->fetch( $s ) . "'"; } + return "'" . pg_escape_string( $this->mConn, $s ) . "'"; } @@ -1435,6 +1479,7 @@ SQL; $delimiter, $table, $field, $conds = '', $options = array(), $join_conds = array() ) { $fld = "array_to_string(array_agg($field)," . $this->addQuotes( $delimiter ) . ')'; + return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')'; } @@ -1447,11 +1492,11 @@ SQL; if ( substr( $newLine, 0, 4 ) == '$mw$' ) { if ( $this->delimiter ) { $this->delimiter = false; - } - else { + } else { $this->delimiter = ';'; } } + return parent::streamStatementEnd( $sql, $newLine ); } @@ -1469,6 +1514,7 @@ SQL; $result = $this->query( "SELECT (CASE(pg_try_advisory_lock($key)) WHEN 'f' THEN 'f' ELSE pg_advisory_unlock($key) END) AS lockstatus", $method ); $row = $this->fetchObject( $result ); + return ( $row->lockstatus === 't' ); } @@ -1492,6 +1538,7 @@ SQL; } } wfDebug( __METHOD__ . " failed to acquire lock\n" ); + return false; } @@ -1505,6 +1552,7 @@ SQL; $key = $this->addQuotes( $this->bigintFromLockName( $lockName ) ); $result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method ); $row = $this->fetchObject( $result ); + return ( $row->lockstatus === 't' ); } diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 84f1bcf3b4..1dccc311fb 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -26,7 +26,6 @@ * @ingroup Database */ class DatabaseSqlite extends DatabaseBase { - private static $fulltextEnabled = null; var $mAffectedRows; @@ -104,6 +103,7 @@ class DatabaseSqlite extends DatabaseBase { throw new DBConnectionError( $this, "SQLite database not accessible" ); } $this->openFile( $fileName ); + return $this->mConn; } @@ -137,6 +137,7 @@ class DatabaseSqlite extends DatabaseBase { $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); # Enforce LIKE to be case sensitive, just like MySQL $this->query( 'PRAGMA case_sensitive_like = 1' ); + return true; } } @@ -147,6 +148,7 @@ class DatabaseSqlite extends DatabaseBase { */ protected function closeConnection() { $this->mConn = null; + return true; } @@ -174,6 +176,7 @@ class DatabaseSqlite extends DatabaseBase { self::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false; } } + return self::$fulltextEnabled; } @@ -195,6 +198,7 @@ class DatabaseSqlite extends DatabaseBase { $cachedResult = 'FTS3'; } $db->close(); + return $cachedResult; } @@ -214,6 +218,7 @@ class DatabaseSqlite extends DatabaseBase { $file = self::generateFileName( $wgSQLiteDataDir, $name ); } $file = $this->addQuotes( $file ); + return $this->query( "ATTACH DATABASE $file AS $name", $fname ); } @@ -244,6 +249,7 @@ class DatabaseSqlite extends DatabaseBase { $this->mAffectedRows = $r->rowCount(); $res = new ResultWrapper( $this, $r->fetchAll() ); } + return $res; } @@ -281,6 +287,7 @@ class DatabaseSqlite extends DatabaseBase { return $obj; } + return false; } @@ -297,8 +304,10 @@ class DatabaseSqlite extends DatabaseBase { $cur = current( $r ); if ( is_array( $cur ) ) { next( $r ); + return $cur; } + return false; } @@ -311,6 +320,7 @@ class DatabaseSqlite extends DatabaseBase { */ function numRows( $res ) { $r = $res instanceof ResultWrapper ? $res->result : $res; + return count( $r ); } @@ -320,6 +330,7 @@ class DatabaseSqlite extends DatabaseBase { */ function numFields( $res ) { $r = $res instanceof ResultWrapper ? $res->result : $res; + return is_array( $r ) ? count( $r[0] ) : 0; } @@ -332,8 +343,10 @@ class DatabaseSqlite extends DatabaseBase { $r = $res instanceof ResultWrapper ? $res->result : $res; if ( is_array( $r ) ) { $keys = array_keys( $r[0] ); + return $keys[$n]; } + return false; } @@ -349,6 +362,7 @@ class DatabaseSqlite extends DatabaseBase { if ( strpos( $name, 'sqlite_' ) === 0 ) { return $name; } + return str_replace( '"', '', parent::tableName( $name, $format ) ); } @@ -399,6 +413,7 @@ class DatabaseSqlite extends DatabaseBase { return "Cannot return last error, no db connection"; } $e = $this->mConn->errorInfo(); + return isset( $e[2] ) ? $e[2] : ''; } @@ -410,6 +425,7 @@ class DatabaseSqlite extends DatabaseBase { return "Cannot return last error, no db connection"; } else { $info = $this->mConn->errorInfo(); + return $info[1]; } } @@ -441,6 +457,7 @@ class DatabaseSqlite extends DatabaseBase { foreach ( $res as $row ) { $info[] = $row->name; } + return $info; } @@ -467,6 +484,7 @@ class DatabaseSqlite extends DatabaseBase { } $firstPart = substr( $row->sql, 0, $indexPos ); $options = explode( ' ', $firstPart ); + return in_array( 'UNIQUE', $options ); } @@ -483,6 +501,7 @@ class DatabaseSqlite extends DatabaseBase { $options[$k] = ''; } } + return parent::makeSelectOptions( $options ); } @@ -492,6 +511,7 @@ class DatabaseSqlite extends DatabaseBase { */ function makeUpdateOptions( $options ) { $options = self::fixIgnore( $options ); + return parent::makeUpdateOptions( $options ); } @@ -506,6 +526,7 @@ class DatabaseSqlite extends DatabaseBase { $options[$k] = 'OR IGNORE'; } } + return $options; } @@ -515,6 +536,7 @@ class DatabaseSqlite extends DatabaseBase { */ function makeInsertOptions( $options ) { $options = self::fixIgnore( $options ); + return parent::makeInsertOptions( $options ); } @@ -593,6 +615,7 @@ class DatabaseSqlite extends DatabaseBase { */ function unionQueries( $sqls, $all ) { $glue = $all ? ' UNION ALL ' : ' UNION '; + return implode( $glue, $sqls ); } @@ -629,6 +652,7 @@ class DatabaseSqlite extends DatabaseBase { */ function getServerVersion() { $ver = $this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + return $ver; } @@ -656,6 +680,7 @@ class DatabaseSqlite extends DatabaseBase { return new SQLiteField( $row, $tableName ); } } + return false; } @@ -696,7 +721,7 @@ class DatabaseSqlite extends DatabaseBase { * @return string */ function strencode( $s ) { - return substr( $this->addQuotes( $s ), 1, - 1 ); + return substr( $this->addQuotes( $s ), 1, -1 ); } /** @@ -715,6 +740,7 @@ class DatabaseSqlite extends DatabaseBase { if ( $b instanceof Blob ) { $b = $b->fetch(); } + return $b; } @@ -748,6 +774,7 @@ class DatabaseSqlite extends DatabaseBase { if ( count( $params ) > 0 && is_array( $params[0] ) ) { $params = $params[0]; } + return parent::buildLike( $params ) . "ESCAPE '\' "; } @@ -765,6 +792,7 @@ class DatabaseSqlite extends DatabaseBase { public function deadlockLoop( /*...*/ ) { $args = func_get_args(); $function = array_shift( $args ); + return call_user_func_array( $function, $args ); } @@ -814,6 +842,7 @@ class DatabaseSqlite extends DatabaseBase { // DROP INDEX is database-wide, not table-specific, so no ON clause. $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s ); } + return $s; } @@ -832,6 +861,7 @@ class DatabaseSqlite extends DatabaseBase { $delim, $table, $field, $conds = '', $join_conds = array() ) { $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')'; + return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')'; } @@ -858,6 +888,7 @@ class DatabaseSqlite extends DatabaseBase { $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql ); } } + return $this->query( $sql, $fname ); } @@ -886,13 +917,11 @@ class DatabaseSqlite extends DatabaseBase { if ( strpos( $table, 'sqlite_' ) !== 0 ) { $endArray[] = $table; } - } } return $endArray; } - } // end DatabaseSqlite class /** @@ -912,6 +941,7 @@ class DatabaseSqliteStandalone extends DatabaseSqlite { */ class SQLiteField implements Field { private $info, $tableName; + function __construct( $info, $tableName ) { $this->info = $info; $this->tableName = $tableName; @@ -932,6 +962,7 @@ class SQLiteField implements Field { return str_replace( "''", "'", $this->info->dflt_value ); } } + return $this->info->dflt_value; } @@ -945,5 +976,4 @@ class SQLiteField implements Field { function type() { return $this->info->type; } - } // end SQLiteField diff --git a/includes/db/DatabaseUtility.php b/includes/db/DatabaseUtility.php index de58bab64a..ed57cb7a8b 100644 --- a/includes/db/DatabaseUtility.php +++ b/includes/db/DatabaseUtility.php @@ -187,6 +187,7 @@ class ResultWrapper implements Iterator { if ( is_null( $this->currentRow ) ) { $this->next(); } + return $this->currentRow; } @@ -203,6 +204,7 @@ class ResultWrapper implements Iterator { function next() { $this->pos++; $this->currentRow = $this->fetchObject(); + return $this->currentRow; } diff --git a/includes/db/IORMRow.php b/includes/db/IORMRow.php index 39411791d9..21ae808eff 100644 --- a/includes/db/IORMRow.php +++ b/includes/db/IORMRow.php @@ -32,7 +32,6 @@ */ interface IORMRow { - /** * Load the specified fields from the database. * @@ -268,5 +267,4 @@ interface IORMRow { * @return IORMTable */ public function getTable(); - } diff --git a/includes/db/IORMTable.php b/includes/db/IORMTable.php index 36865655e4..d38ec9750b 100644 --- a/includes/db/IORMTable.php +++ b/includes/db/IORMTable.php @@ -28,7 +28,6 @@ */ interface IORMTable { - /** * Returns the name of the database table objects of this type are stored in. * @@ -110,7 +109,7 @@ interface IORMTable { * @throws DBQueryError if the query failed (even if the database was in ignoreErrors mode) */ public function select( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ); + array $options = array(), $functionName = null ); /** * Selects the the specified fields of the records matching the provided @@ -126,7 +125,7 @@ interface IORMTable { * @return array of self */ public function selectObjects( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ); + array $options = array(), $functionName = null ); /** * Do the actual select. @@ -142,7 +141,7 @@ interface IORMTable { * @throws DBQueryError if the query failed (even if the database was in ignoreErrors mode) */ public function rawSelect( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ); + array $options = array(), $functionName = null ); /** * Selects the the specified fields of the records matching the provided @@ -167,7 +166,7 @@ interface IORMTable { * @return array of array */ public function selectFields( $fields = null, array $conditions = array(), - array $options = array(), $collapse = true, $functionName = null ); + array $options = array(), $collapse = true, $functionName = null ); /** * Selects the the specified fields of the first matching record. @@ -183,7 +182,7 @@ interface IORMTable { * @return IORMRow|bool False on failure */ public function selectRow( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ); + array $options = array(), $functionName = null ); /** * Selects the the specified fields of the records matching the provided @@ -199,7 +198,7 @@ interface IORMTable { * @return ResultWrapper */ public function rawSelectRow( array $fields, array $conditions = array(), - array $options = array(), $functionName = null ); + array $options = array(), $functionName = null ); /** * Selects the the specified fields of the first record matching the provided @@ -219,7 +218,7 @@ interface IORMTable { * @return mixed|array|bool False on failure */ public function selectFieldsRow( $fields = null, array $conditions = array(), - array $options = array(), $collapse = true, $functionName = null ); + array $options = array(), $collapse = true, $functionName = null ); /** * Returns if there is at least one record matching the provided conditions. @@ -513,5 +512,4 @@ interface IORMTable { * @return boolean */ public function canHaveField( $name ); - } diff --git a/includes/db/LBFactory.php b/includes/db/LBFactory.php index 16c43a009f..36cccdae45 100644 --- a/includes/db/LBFactory.php +++ b/includes/db/LBFactory.php @@ -26,7 +26,6 @@ * @ingroup Database */ abstract class LBFactory { - /** * @var LBFactory */ @@ -52,6 +51,7 @@ abstract class LBFactory { $class = $wgLBFactoryConf['class']; self::$instance = new $class( $wgLBFactoryConf ); } + return self::$instance; } @@ -210,13 +210,13 @@ class LBFactory_Simple extends LBFactory { 'type' => $wgDBtype, 'load' => 1, 'flags' => $flags - )); + ) ); } return new LoadBalancer( array( 'servers' => $servers, 'masterWaitTimeout' => $wgMasterWaitTimeout - )); + ) ); } /** @@ -229,6 +229,7 @@ class LBFactory_Simple extends LBFactory { $this->mainLB->parentInfo( array( 'id' => 'main' ) ); $this->chronProt->initLB( $this->mainLB ); } + return $this->mainLB; } @@ -243,9 +244,10 @@ class LBFactory_Simple extends LBFactory { if ( !isset( $wgExternalServers[$cluster] ) ) { throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); } + return new LoadBalancer( array( 'servers' => $wgExternalServers[$cluster] - )); + ) ); } /** @@ -259,6 +261,7 @@ class LBFactory_Simple extends LBFactory { $this->extLBs[$cluster]->parentInfo( array( 'id' => "ext-$cluster" ) ); $this->chronProt->initLB( $this->extLBs[$cluster] ); } + return $this->extLBs[$cluster]; } diff --git a/includes/db/LBFactory_Multi.php b/includes/db/LBFactory_Multi.php index 3043946a6a..b9239ce69a 100644 --- a/includes/db/LBFactory_Multi.php +++ b/includes/db/LBFactory_Multi.php @@ -117,6 +117,7 @@ class LBFactory_Multi extends LBFactory { } $this->lastSection = $section; $this->lastWiki = $wiki; + return $section; } @@ -134,6 +135,7 @@ class LBFactory_Multi extends LBFactory { if ( isset( $this->groupLoadsBySection[$section] ) ) { $groupLoads = array_merge_recursive( $groupLoads, $this->groupLoadsBySection[$section] ); } + return $this->newLoadBalancer( $this->serverTemplate, $this->sectionLoads[$section], $groupLoads ); } @@ -149,6 +151,7 @@ class LBFactory_Multi extends LBFactory { $this->chronProt->initLB( $lb ); $this->mainLBs[$section] = $lb; } + return $this->mainLBs[$section]; } @@ -169,6 +172,7 @@ class LBFactory_Multi extends LBFactory { if ( isset( $this->templateOverridesByCluster[$cluster] ) ) { $template = $this->templateOverridesByCluster[$cluster] + $template; } + return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() ); } @@ -183,6 +187,7 @@ class LBFactory_Multi extends LBFactory { $this->extLBs[$cluster]->parentInfo( array( 'id' => "ext-$cluster" ) ); $this->chronProt->initLB( $this->extLBs[$cluster] ); } + return $this->extLBs[$cluster]; } @@ -200,7 +205,8 @@ class LBFactory_Multi extends LBFactory { $lb = new LoadBalancer( array( 'servers' => $servers, 'masterWaitTimeout' => $wgMasterWaitTimeout - )); + ) ); + return $lb; } @@ -245,6 +251,7 @@ class LBFactory_Multi extends LBFactory { $serverInfo['load'] = $load; $servers[] = $serverInfo; } + return $servers; } @@ -260,6 +267,7 @@ class LBFactory_Multi extends LBFactory { $reindexed[$server][$group] = $load; } } + return $reindexed; } @@ -271,6 +279,7 @@ class LBFactory_Multi extends LBFactory { function getDBNameAndPrefix( $wiki = false ) { if ( $wiki === false ) { global $wgDBname, $wgDBprefix; + return array( $wgDBname, $wgDBprefix ); } else { return wfSplitWikiID( $wiki ); diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 011c0831cc..0a218abd51 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -101,6 +101,7 @@ class LoadBalancer { $class = $this->mLoadMonitorClass; $this->mLoadMonitor = new $class( $this ); } + return $this->mLoadMonitor; } @@ -212,6 +213,7 @@ class LoadBalancer { # No loads for this group, return false and the caller can use some other group wfDebug( __METHOD__ . ": no loads for group $group\n" ); wfProfileOut( __METHOD__ ); + return false; } } else { @@ -255,6 +257,7 @@ class LoadBalancer { # wants us to return false. wfDebugLog( 'connect', __METHOD__ . ": pickRandom() returned false\n" ); wfProfileOut( __METHOD__ ); + return false; } @@ -329,6 +332,7 @@ class LoadBalancer { } } wfProfileOut( __METHOD__ ); + return $i; } @@ -342,6 +346,7 @@ class LoadBalancer { wfDebug( __METHOD__ . ": waiting $t us\n" ); usleep( $t ); wfProfileOut( __METHOD__ ); + return $t; } @@ -393,6 +398,7 @@ class LoadBalancer { return reset( $conns[$i] ); } } + return false; } @@ -408,11 +414,13 @@ class LoadBalancer { if ( !$conn ) { if ( !$open ) { wfDebug( __METHOD__ . ": no connection open\n" ); + return false; } else { $conn = $this->openConnection( $index, '' ); if ( !$conn ) { wfDebug( __METHOD__ . ": failed to open connection\n" ); + return false; } } @@ -424,9 +432,11 @@ class LoadBalancer { if ( $result == -1 || is_null( $result ) ) { # Timed out waiting for slave, use master instead wfDebug( __METHOD__ . ": Timed out waiting for slave #$index pos {$this->mWaitForPos}\n" ); + return false; } else { wfDebug( __METHOD__ . ": Done\n" ); + return true; } } @@ -487,6 +497,7 @@ class LoadBalancer { if ( $i === false ) { $this->mLastError = 'No working slave server: ' . $this->mLastError; wfProfileOut( __METHOD__ ); + return $this->reportConnectionError(); } } @@ -495,10 +506,12 @@ class LoadBalancer { $conn = $this->openConnection( $i, $wiki ); if ( !$conn ) { wfProfileOut( __METHOD__ ); + return $this->reportConnectionError(); } wfProfileOut( __METHOD__ ); + return $conn; } @@ -522,6 +535,7 @@ class LoadBalancer { } if ( $serverIndex === null || $refCount === null ) { wfDebug( __METHOD__ . ": this connection was not opened as a foreign connection\n" ); + /** * This can happen in code like: * foreach ( $dbs as $db ) { @@ -532,6 +546,7 @@ class LoadBalancer { * When a connection to the local DB is opened in this way, reuseConnection() * should be ignored */ + return; } if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) { @@ -598,6 +613,7 @@ class LoadBalancer { if ( $wiki !== false ) { $conn = $this->openForeignConnection( $i, $wiki ); wfProfileOut( __METHOD__ ); + return $conn; } if ( isset( $this->mConns['local'][$i][0] ) ) { @@ -616,6 +632,7 @@ class LoadBalancer { } } wfProfileOut( __METHOD__ ); + return $conn; } @@ -690,6 +707,7 @@ class LoadBalancer { $conn->setLBInfo( 'foreignPoolRefCount', $refCount + 1 ); } wfProfileOut( __METHOD__ ); + return $conn; } @@ -704,6 +722,7 @@ class LoadBalancer { if ( !is_integer( $index ) ) { return false; } + return (bool)$this->getAnyOpenConnection( $index ); } @@ -743,6 +762,7 @@ class LoadBalancer { if ( isset( $server['fakeMaster'] ) ) { $db->setFakeMaster( true ); } + return $db; } @@ -764,6 +784,7 @@ class LoadBalancer { wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" ); $conn->reportConnectionError( "{$this->mLastError} ({$server})" ); // throws DBConnectionError } + return false; /* not reached */ } @@ -854,13 +875,16 @@ class LoadBalancer { $conn = $this->getAnyOpenConnection( $i ); if ( $conn ) { wfDebug( "Master pos fetched from slave\n" ); + return $conn->getSlavePos(); } } } else { wfDebug( "Master pos fetched from master\n" ); + return $masterConn->getMasterPos(); } + return false; } @@ -976,6 +1000,7 @@ class LoadBalancer { return $this->mAllowLagged; } $this->mAllowLagged = $mode; + return $this->mAllowLagged; } @@ -993,6 +1018,7 @@ class LoadBalancer { } } } + return $success; } @@ -1046,6 +1072,7 @@ class LoadBalancer { } } } + return array( $host, $maxLag, $maxIndex ); } @@ -1070,6 +1097,7 @@ class LoadBalancer { $this->mLagTimes = $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki ); } + return $this->mLagTimes; } @@ -1137,6 +1165,7 @@ class DBConnRef implements IDatabase { list( $db, $groups, $wiki ) = $this->params; $this->conn = $this->lb->getConnection( $db, $groups, $wiki ); } + return call_user_func_array( array( $this->conn, $name ), $arguments ); } diff --git a/includes/db/LoadMonitor.php b/includes/db/LoadMonitor.php index f10d07f898..b2935316ed 100644 --- a/includes/db/LoadMonitor.php +++ b/includes/db/LoadMonitor.php @@ -154,6 +154,7 @@ class LoadMonitor_MySQL implements LoadMonitor { if ( mt_rand( 0, $chance ) != 0 ) { unset( $times['timestamp'] ); // hide from caller wfProfileOut( __METHOD__ ); + return $times; } wfIncrStats( 'lag_cache_miss_expired' ); @@ -164,13 +165,14 @@ class LoadMonitor_MySQL implements LoadMonitor { # Cache key missing or expired if ( $wgMemc->add( "$memcKey:lock", 1, 10 ) ) { # Let this process alone update the cache value - $unlocker = new ScopedCallback( function() use ( $wgMemc, $memcKey ) { + $unlocker = new ScopedCallback( function () use ( $wgMemc, $memcKey ) { $wgMemc->delete( $memcKey ); } ); } elseif ( is_array( $times ) ) { # Could not acquire lock but an old cache exists, so use it unset( $times['timestamp'] ); // hide from caller wfProfileOut( __METHOD__ ); + return $times; } @@ -191,6 +193,7 @@ class LoadMonitor_MySQL implements LoadMonitor { unset( $times['timestamp'] ); // hide from caller wfProfileOut( __METHOD__ ); + return $times; } @@ -207,6 +210,7 @@ class LoadMonitor_MySQL implements LoadMonitor { if ( $status['Threads_running'] > $threshold ) { $server = $conn->getProperty( 'mServer' ); wfLogDBError( "LB backoff from $server - Threads_running = {$status['Threads_running']}\n" ); + return $status['Threads_connected']; } else { return 0; diff --git a/includes/db/ORMIterator.php b/includes/db/ORMIterator.php index 077eab0fd8..e8104b6ffe 100644 --- a/includes/db/ORMIterator.php +++ b/includes/db/ORMIterator.php @@ -27,5 +27,4 @@ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ interface ORMIterator extends Iterator { - } diff --git a/includes/db/ORMResult.php b/includes/db/ORMResult.php index 160033c4cf..e4efc016a4 100644 --- a/includes/db/ORMResult.php +++ b/includes/db/ORMResult.php @@ -30,7 +30,6 @@ */ class ORMResult implements ORMIterator { - /** * @var ResultWrapper */ @@ -119,5 +118,4 @@ class ORMResult implements ORMIterator { public function valid() { return $this->current !== false; } - } diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php index 5ce3794d5b..5f0f4f5691 100644 --- a/includes/db/ORMRow.php +++ b/includes/db/ORMRow.php @@ -32,7 +32,6 @@ */ class ORMRow implements IORMRow { - /** * The fields of the object. * field name (w/o prefix) => value @@ -130,8 +129,10 @@ class ORMRow implements IORMRow { if ( $result !== false ) { $this->setFields( $this->table->getFieldsFromDBResult( $result ), $override ); + return true; } + return false; } @@ -232,8 +233,7 @@ class ORMRow implements IORMRow { * @return boolean */ public function hasIdField() { - return $this->hasField( 'id' ) - && !is_null( $this->getField( 'id' ) ); + return $this->hasField( 'id' ) && !is_null( $this->getField( 'id' ) ); } /** @@ -252,7 +252,7 @@ class ORMRow implements IORMRow { $value = $this->fields[$name]; // Skip null id fields so that the DBMS can set the default. - if ( $name === 'id' && is_null ( $value ) ) { + if ( $name === 'id' && is_null( $value ) ) { continue; } @@ -552,7 +552,6 @@ class ORMRow implements IORMRow { * @param array|string|null $summaryFields */ public function loadSummaryFields( $summaryFields = null ) { - } /** @@ -590,5 +589,4 @@ class ORMRow implements IORMRow { public function getTable() { return $this->table; } - } diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php index 5f6723b960..8026e31e68 100644 --- a/includes/db/ORMTable.php +++ b/includes/db/ORMTable.php @@ -29,7 +29,6 @@ */ class ORMTable extends DBAccessBase implements IORMTable { - /** * Cache for instances, used by the singleton method. * @@ -201,8 +200,10 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return ORMResult */ public function select( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ) { + array $options = array(), $functionName = null + ) { $res = $this->rawSelect( $fields, $conditions, $options, $functionName ); + return new ORMResult( $this, $res ); } @@ -221,7 +222,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * @throws DBQueryError if the query failed (even if the database was in ignoreErrors mode). */ public function selectObjects( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ) { + array $options = array(), $functionName = null + ) { $result = $this->selectFields( $fields, $conditions, $options, false, $functionName ); $objects = array(); @@ -239,19 +241,19 @@ class ORMTable extends DBAccessBase implements IORMTable { * @since 1.20 * * @param null|string|array $fields - * @param array $conditions - * @param array $options - * @param null|string $functionName + * @param array $conditions + * @param array $options + * @param null|string $functionName * * @return ResultWrapper * @throws DBQueryError if the quey failed (even if the database was in ignoreErrors mode). */ public function rawSelect( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ) { + array $options = array(), $functionName = null + ) { if ( is_null( $fields ) ) { $fields = array_keys( $this->getFields() ); - } - else { + } else { $fields = (array)$fields; } @@ -313,7 +315,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return array of array */ public function selectFields( $fields = null, array $conditions = array(), - array $options = array(), $collapse = true, $functionName = null ) { + array $options = array(), $collapse = true, $functionName = null + ) { $objects = array(); $result = $this->rawSelect( $fields, $conditions, $options, $functionName ); @@ -325,8 +328,7 @@ class ORMTable extends DBAccessBase implements IORMTable { if ( $collapse ) { if ( count( $fields ) === 1 ) { $objects = array_map( 'array_shift', $objects ); - } - elseif ( count( $fields ) === 2 ) { + } elseif ( count( $fields ) === 2 ) { $o = array(); foreach ( $objects as $object ) { @@ -354,7 +356,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return IORMRow|bool False on failure */ public function selectRow( $fields = null, array $conditions = array(), - array $options = array(), $functionName = null ) { + array $options = array(), $functionName = null + ) { $options['LIMIT'] = 1; $objects = $this->select( $fields, $conditions, $options, $functionName ); @@ -376,7 +379,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return ResultWrapper */ public function rawSelectRow( array $fields, array $conditions = array(), - array $options = array(), $functionName = null ) { + array $options = array(), $functionName = null + ) { $dbr = $this->getReadDbConnection(); $result = $dbr->selectRow( @@ -388,6 +392,7 @@ class ORMTable extends DBAccessBase implements IORMTable { ); $this->releaseConnection( $dbr ); + return $result; } @@ -409,7 +414,8 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return mixed|array|bool False on failure */ public function selectFieldsRow( $fields = null, array $conditions = array(), - array $options = array(), $collapse = true, $functionName = null ) { + array $options = array(), $collapse = true, $functionName = null + ) { $options['LIMIT'] = 1; $objects = $this->selectFields( $fields, $conditions, $options, $collapse, $functionName ); @@ -491,6 +497,7 @@ class ORMTable extends DBAccessBase implements IORMTable { ) !== false; // DatabaseBase::delete does not always return true for success as documented... $this->releaseConnection( $dbw ); + return $result; } @@ -665,6 +672,7 @@ class ORMTable extends DBAccessBase implements IORMTable { ) !== false; // DatabaseBase::update does not always return true for success as documented... $this->releaseConnection( $dbw ); + return $result; } @@ -711,8 +719,7 @@ class ORMTable extends DBAccessBase implements IORMTable { if ( is_array( $value ) ) { $field = $value[0]; $value = $value[1]; - } - else { + } else { $value = explode( ' ', $value, 2 ); $value[0] = $this->getPrefixedField( $value[0] ); $prefixedValues[] = implode( ' ', $value ); @@ -1103,5 +1110,4 @@ class ORMTable extends DBAccessBase implements IORMTable { return $success; } - }