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

Alexia created this task.Oct 3 2016, 5:31 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 3 2016, 5:31 PM

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'].

I made a patch that fixes all of these instances.

https://gerrit.wikimedia.org/r/#/c/316831/

Yaron_Koren closed this task as Resolved.Feb 20 2017, 6:35 PM
Yaron_Koren claimed this task.
Yaron_Koren added a subscriber: Yaron_Koren.

This was merged in months ago.