[BUGFIX] DBAL: Assure all optional query array parameters are set 86/52386/4
authorDan Untenzu <mail@pixelbrackets.de>
Fri, 7 Apr 2017 13:02:32 +0000 (15:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 18 May 2017 13:28:05 +0000 (15:28 +0200)
The method »exec_SELECT_queryArray« uses an incoming array and
passes all possible query array keys on to the »exec_SELECTquery« method.
If not all keys were set, then »NULL« is passed. It should pass an
empty string however.

To avoid exceptions thrown due to NULL values, the method
now provides a fallback for all optional array keys.

Resolves: #80749
Releases: 7.6
Change-Id: I8cad33503f752062f771a53bade1188b6351d56d
Reviewed-on: https://review.typo3.org/52386
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Database/DatabaseConnection.php

index 5a569ea..3c04635 100644 (file)
@@ -349,12 +349,27 @@ class DatabaseConnection
     /**
      * Executes a select based on input query parts array
      *
-     * @param array $queryParts Query parts array
+     *     $queryArray = [
+     *         'SELECT' => 'uid',
+     *         'FROM' => 'tt_content',
+     *         'WHERE' => 'uid = ' . (int)$uid,
+     *         'LIMIT' => 1
+     *     ];
+     *     exec_SELECT_queryArray($queryArray);
+     *
+     * @param array $queryParts Query parts array, where the keys »SELECT« & »FROM« are required
      * @return bool|\mysqli_result|object MySQLi result object / DBAL object
      * @see exec_SELECTquery()
      */
     public function exec_SELECT_queryArray($queryParts)
     {
+        $queryPartsFallback = [
+            'WHERE' => '',
+            'GROUPBY' => '',
+            'ORDERBY' => '',
+            'LIMIT' => ''
+        ];
+        $queryParts = array_merge($queryPartsFallback, $queryParts);
         return $this->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
     }