From 5f3957498b5819375f525949e79cad8564d998ec Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Thu, 22 Jan 2015 10:36:18 -0500 Subject: [PATCH] Database: Cast to int in estimateRowCount(), selectRowCount() Doc comments state that these methods return ints. In order to ensure that, values must be cast to int before they are returned. With respect to selectRowCount(), follows-up 65f81d284386. Change-Id: I108221ce4ad1b5b103b015fe875de54e04781741 --- includes/api/ApiQueryUserInfo.php | 2 +- includes/db/Database.php | 4 ++-- includes/db/DatabaseMssql.php | 2 +- includes/db/DatabaseMysqlBase.php | 2 +- includes/db/DatabasePostgres.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index aa38564e1c..7fc0ba88b7 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -181,7 +181,7 @@ class ApiQueryUserInfo extends ApiQueryBase { if ( $count >= self::WL_UNREAD_LIMIT ) { $vals['unreadcount'] = self::WL_UNREAD_LIMIT . '+'; } else { - $vals['unreadcount'] = (int)$count; + $vals['unreadcount'] = $count; } } diff --git a/includes/db/Database.php b/includes/db/Database.php index 92d998c60b..e95f134c01 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1814,7 +1814,7 @@ abstract class DatabaseBase implements IDatabase { if ( $res ) { $row = $this->fetchRow( $res ); - $rows = ( isset( $row['rowcount'] ) ) ? $row['rowcount'] : 0; + $rows = ( isset( $row['rowcount'] ) ) ? (int)$row['rowcount'] : 0; } return $rows; @@ -1844,7 +1844,7 @@ abstract class DatabaseBase implements IDatabase { if ( $res ) { $row = $this->fetchRow( $res ); - $rows = ( isset( $row['rowcount'] ) ) ? $row['rowcount'] : 0; + $rows = ( isset( $row['rowcount'] ) ) ? (int)$row['rowcount'] : 0; } return $rows; diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index a7bc6dd621..d62769cc60 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -518,7 +518,7 @@ class DatabaseMssql extends DatabaseBase { $row = $this->fetchRow( $res ); if ( isset( $row['EstimateRows'] ) ) { - $rows = $row['EstimateRows']; + $rows = (int)$row['EstimateRows']; } } diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 7b903d6826..458b286948 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -468,7 +468,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase { $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero } - return $rows; + return (int)$rows; } /** diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index ce14d7a969..abf26e06ff 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -712,7 +712,7 @@ class DatabasePostgres extends DatabaseBase { $row = $this->fetchRow( $res ); $count = array(); if ( preg_match( '/rows=(\d+)/', $row[0], $count ) ) { - $rows = $count[1]; + $rows = (int)$count[1]; } } -- 2.20.1