[BUGFIX] Check for query failures in admin methods 40/24940/2
authorThomas Maroschik <tmaroschik@dfau.de>
Mon, 21 Oct 2013 17:18:23 +0000 (19:18 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Mon, 21 Oct 2013 18:08:58 +0000 (20:08 +0200)
 In the DatabaseConnection class the two methods admin_get_fields
 and admin_get_keys throw a fatal error when a query failure occurs.

 This fix introduces two checks that prevent the methods from fataling
 and return an empty result on failure.

 Fixes: #53014
 Releases: 6.2

Change-Id: I40f7e52fe14b7d75766f0484e42834b0e1b1a5dc
Reviewed-on: https://review.typo3.org/24940
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/core/Classes/Database/DatabaseConnection.php

index dfb4ef2..51a7f93 100644 (file)
@@ -1351,10 +1351,12 @@ class DatabaseConnection {
                }
                $output = array();
                $columns_res = $this->link->query('SHOW COLUMNS FROM `' . $tableName . '`');
-               while ($fieldRow = $columns_res->fetch_assoc()) {
-                       $output[$fieldRow['Field']] = $fieldRow;
+               if ($columns_res !== FALSE) {
+                       while ($fieldRow = $columns_res->fetch_assoc()) {
+                               $output[$fieldRow['Field']] = $fieldRow;
+                       }
+                       $columns_res->free();
                }
-               $columns_res->free();
                return $output;
        }
 
@@ -1371,10 +1373,12 @@ class DatabaseConnection {
                }
                $output = array();
                $keyRes = $this->link->query('SHOW KEYS FROM `' . $tableName . '`');
-               while ($keyRow = $keyRes->fetch_assoc()) {
-                       $output[] = $keyRow;
+               if ($keyRes !== FALSE) {
+                       while ($keyRow = $keyRes->fetch_assoc()) {
+                               $output[] = $keyRow;
+                       }
+                       $keyRes->free();
                }
-               $keyRes->free();
                return $output;
        }