X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2Fdb%2FDatabase.php;h=ff2f7f7593730783c36b35355a4f44d7822833f9;hb=6f4448dd71851c903e1fb0746fa07197e08c12f5;hp=97e2fe2f4dbfbce07056e0c4a9d6eb8259d258c2;hpb=2152738bca8ad4010de3f45a884e4dc9dd80bc7b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/Database.php b/includes/db/Database.php index 97e2fe2f4d..ff2f7f7593 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -62,9 +62,10 @@ interface DatabaseType { * Fetch the next row from the given result object, in object form. * Fields can be retrieved with $row->fieldname, with fields acting like * member variables. + * If no more rows are available, false is returned. * * @param $res ResultWrapper|object as returned from DatabaseBase::query(), etc. - * @return Row object + * @return object|bool * @throws DBUnexpectedError Thrown if the database returns an error */ function fetchObject( $res ); @@ -72,9 +73,10 @@ interface DatabaseType { /** * Fetch the next row from the given result object, in associative array * form. Fields are retrieved with $row['fieldname']. + * If no more rows are available, false is returned. * * @param $res ResultWrapper result object as returned from DatabaseBase::query(), etc. - * @return Row object + * @return array|bool * @throws DBUnexpectedError Thrown if the database returns an error */ function fetchRow( $res ); @@ -112,8 +114,8 @@ interface DatabaseType { * The value inserted should be fetched from nextSequenceValue() * * Example: - * $id = $dbw->nextSequenceValue('page_page_id_seq'); - * $dbw->insert('page',array('page_id' => $id)); + * $id = $dbw->nextSequenceValue( 'page_page_id_seq' ); + * $dbw->insert( 'page', array( 'page_id' => $id ) ); * $id = $dbw->insertId(); * * @return int @@ -393,7 +395,7 @@ abstract class DatabaseBase implements DatabaseType { return wfSetVar( $this->mTablePrefix, $prefix ); } - /** + /** * Set the filehandle to copy write statements to. * * @param $fh filehandle @@ -584,7 +586,7 @@ abstract class DatabaseBase implements DatabaseType { global $wgDebugDBTransactions; $this->mFlags |= $flag; if ( ( $flag & DBO_TRX) & $wgDebugDBTransactions ) { - wfDebug("Implicit transactions are now disabled.\n"); + wfDebug( "Implicit transactions are now disabled.\n" ); } } @@ -597,7 +599,7 @@ abstract class DatabaseBase implements DatabaseType { global $wgDebugDBTransactions; $this->mFlags &= ~$flag; if ( ( $flag & DBO_TRX ) && $wgDebugDBTransactions ) { - wfDebug("Implicit transactions are now disabled.\n"); + wfDebug( "Implicit transactions are now disabled.\n" ); } } @@ -671,12 +673,12 @@ abstract class DatabaseBase implements DatabaseType { if ( $wgCommandLineMode ) { $this->mFlags &= ~DBO_TRX; if ( $wgDebugDBTransactions ) { - wfDebug("Implicit transaction open disabled.\n"); + wfDebug( "Implicit transaction open disabled.\n" ); } } else { $this->mFlags |= DBO_TRX; if ( $wgDebugDBTransactions ) { - wfDebug("Implicit transaction open enabled.\n"); + wfDebug( "Implicit transaction open enabled.\n" ); } } } @@ -726,7 +728,7 @@ abstract class DatabaseBase implements DatabaseType { */ final public static function factory( $dbType, $p = array() ) { $canonicalDBTypes = array( - 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2' + 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql' ); $dbType = strtolower( $dbType ); $class = 'Database' . ucfirst( $dbType ); @@ -772,7 +774,7 @@ abstract class DatabaseBase implements DatabaseType { * @param $errno * @param $errstr */ - protected function connectionErrorHandler( $errno, $errstr ) { + protected function connectionErrorHandler( $errno, $errstr ) { $this->mPHPError = $errstr; } @@ -921,7 +923,7 @@ abstract class DatabaseBase implements DatabaseType { if ( strpos( $sqlstart, "SHOW " ) !== 0 && strpos( $sqlstart, "SET " ) !== 0 ) { global $wgDebugDBTransactions; if ( $wgDebugDBTransactions ) { - wfDebug("Implicit transaction start.\n"); + wfDebug( "Implicit transaction start.\n" ); } $this->begin( __METHOD__ . " ($fname)" ); $this->mTrxAutomatic = true; @@ -1096,7 +1098,7 @@ abstract class DatabaseBase implements DatabaseType { case '\\&': return '&'; } - list( /* $n */ , $arg ) = each( $this->preparedArgs ); + list( /* $n */, $arg ) = each( $this->preparedArgs ); switch( $matches[1] ) { case '?': return $this->addQuotes( $arg ); @@ -1419,7 +1421,7 @@ abstract class DatabaseBase implements DatabaseType { * join, the second is an SQL fragment giving the join condition for that * table. For example: * - * array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) + * array( 'page' => array( 'LEFT JOIN', 'page_latest=rev_id' ) ) * * @return ResultWrapper. If the query returned no rows, a ResultWrapper * with no rows in it will be returned. If there was a query error, a @@ -2097,7 +2099,7 @@ abstract class DatabaseBase implements DatabaseType { * This is handy when you need to construct SQL for joins * * Example: - * extract($dbr->tableNames('user','watchlist')); + * extract( $dbr->tableNames( 'user', 'watchlist' ) ); * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; * @@ -2119,7 +2121,7 @@ abstract class DatabaseBase implements DatabaseType { * This is handy when you need to construct SQL for joins * * Example: - * list( $user, $watchlist ) = $dbr->tableNamesN('user','watchlist'); + * list( $user, $watchlist ) = $dbr->tableNamesN( 'user', 'watchlist' ); * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; * @@ -2671,7 +2673,7 @@ abstract class DatabaseBase implements DatabaseType { list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); + $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } @@ -3013,18 +3015,18 @@ abstract class DatabaseBase implements DatabaseType { if ( $this->mTrxLevel ) { // implicit commit if ( !$this->mTrxAutomatic ) { - // We want to warn about inadvertently nested begin/commit pairs, but not about auto-committing - // implicit transactions that were started by query() because DBO_TRX was set. - - wfWarn( "$fname: Transaction already in progress (from {$this->mTrxFname}), " . - " performing implicit commit!" ); + // We want to warn about inadvertently nested begin/commit pairs, but not about + // auto-committing implicit transactions that were started by query() via DBO_TRX + $msg = "$fname: Transaction already in progress (from {$this->mTrxFname}), " . + " performing implicit commit!"; + wfWarn( $msg ); + wfLogDBError( $msg ); } else { // if the transaction was automatic and has done write operations, // log it if $wgDebugDBTransactions is enabled. - if ( $this->mTrxDoneWrites && $wgDebugDBTransactions ) { - wfDebug( "$fname: Automatic transaction with writes in progress (from {$this->mTrxFname}), " . - " performing implicit commit!\n" ); + wfDebug( "$fname: Automatic transaction with writes in progress" . + " (from {$this->mTrxFname}), performing implicit commit!\n" ); } } @@ -3466,7 +3468,7 @@ abstract class DatabaseBase implements DatabaseType { // replace `{$var}` $ins = str_replace( '`{$' . $var . '}`', $this->addIdentifierQuotes( $value ), $ins ); // replace /*$var*/ - $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $value ) , $ins ); + $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $value ), $ins ); } return $ins; }