Make selectRowCount() (hopefully) work in MSSQL.
authorBrian Wolff <bawolff+wn@gmail.com>
Mon, 13 Mar 2017 04:29:43 +0000 (04:29 +0000)
committerUmherirrender <umherirrender_de.wp@web.de>
Wed, 15 Mar 2017 17:27:02 +0000 (17:27 +0000)
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

index e807bc8..90e60a3 100644 (file)
@@ -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 );