From: Aaron Schulz Date: Mon, 20 May 2019 19:47:18 +0000 (-0700) Subject: rdbms: replace some return-based sanity checks in Database with exception-based checks X-Git-Tag: 1.34.0-rc.0~1647^2 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=8c52c6be3310855525ddb60f3b8f97368d65e4c4;p=lhc%2Fweb%2Fwiklou.git rdbms: replace some return-based sanity checks in Database with exception-based checks Change-Id: I51a541fb560438a34522ca442a8b8e572830deea --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 6e30d3fca4..1e7180d920 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1607,17 +1607,16 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $options['LIMIT'] = 1; $res = $this->select( $table, $var, $cond, $fname, $options, $join_conds ); - if ( $res === false || !$this->numRows( $res ) ) { - return false; + if ( $res === false ) { + throw new DBUnexpectedError( $this, "Got false from select()" ); } $row = $this->fetchRow( $res ); - - if ( $row !== false ) { - return reset( $row ); - } else { + if ( $row === false ) { return false; } + + return reset( $row ); } public function selectFieldValues( @@ -1635,7 +1634,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $res = $this->select( $table, [ 'value' => $var ], $cond, $fname, $options, $join_conds ); if ( $res === false ) { - return false; + throw new DBUnexpectedError( $this, "Got false from select()" ); } $values = []; @@ -1872,19 +1871,17 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware ) { $options = (array)$options; $options['LIMIT'] = 1; - $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds ); + $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds ); if ( $res === false ) { - return false; + throw new DBUnexpectedError( $this, "Got false from select()" ); } if ( !$this->numRows( $res ) ) { return false; } - $obj = $this->fetchObject( $res ); - - return $obj; + return $this->fetchObject( $res ); } public function estimateRowCount(