From 70cd7dd7129da8a9d5c00e44d609d4c054ece101 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Mon, 13 Mar 2017 04:29:43 +0000 Subject: [PATCH] Make selectRowCount() (hopefully) work in MSSQL. Make table and column aliases be quoted identifiers. This is needed for MSSQL (rowcount is a reserved word), and is generally just a good idea. I have tested this on MySql and SQLite. I don't have MSSQL installed to test on. Bug: T158766 Change-Id: Ic63f63d208ba6ad15e77eb634e94855ee2728d05 --- includes/libs/rdbms/database/Database.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index e807bc84ad..90e60a322e 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1354,7 +1354,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware ) { $rows = 0; $sql = $this->selectSQLText( $tables, '1', $conds, $fname, $options, $join_conds ); - $res = $this->query( "SELECT COUNT(*) AS rowcount FROM ($sql) tmp_count", $fname ); + // The identifier quotes is primarily for MSSQL. + $rowCountCol = $this->addIdentifierQuotes( "rowcount" ); + $tableName = $this->addIdentifierQuotes( "tmp_count" ); + $res = $this->query( "SELECT COUNT(*) AS $rowCountCol FROM ($sql) $tableName", $fname ); if ( $res ) { $row = $this->fetchRow( $res ); -- 2.20.1