Page MenuHomePhabricator

Do not rely on indexed fields in MySQL queries in CargoUtils::getTables().
Closed, ResolvedPublic

Description

Relying on indexed fields in MySQL queries is not reliable and not compatible with all MySQL installations. The fix is simple.

diff --git a/extensions/Cargo/CargoUtils.php b/extensions/Cargo/CargoUtils.php
index 78e4979..56b7ab2 100755
--- a/extensions/Cargo/CargoUtils.php
+++ b/extensions/Cargo/CargoUtils.php
@@ -123,7 +123,7 @@ class CargoUtils {
         $dbw = wfGetDB( DB_MASTER );
         $res = $dbw->select( 'cargo_tables', 'main_table' );
         while ( $row = $dbw->fetchRow( $res ) ) {
-            $tableNames[] = $row[0];
+            $tableNames[] = $row['main_table'];
         }
         return $tableNames;
     }

Event Timeline

This shows up as issue in the CargoTables special page as well.

Line 49: $out->addWikiText( $this->msg( 'cargo-cargotables-totalrows' )->numParams( $row[0] )->text() . "\n" );

var_dump($row[0]); //null

However, the actual result row has:

array(1) {
  ["COUNT(*)"]=>
  string(1) "3"
}

It would be best to reference COUNT(*) to a field alias such as: 'COUNT(*) AS total'
Then pull it by the associative index: $row['total'].

Yaron_Koren claimed this task.
Yaron_Koren subscribed.

This was merged in months ago.