Only throw an exception for empty arrays while devtools are active
authorAlexander Ebert <ebert@woltlab.com>
Wed, 19 Jul 2017 15:23:22 +0000 (17:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 19 Jul 2017 15:23:22 +0000 (17:23 +0200)
See #2338

wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php

index d4273878ac85d4cb6c9e3f5b5398bbffb69819a7..0a884cccf0467ecd1efaa643f659686471ff7355 100644 (file)
@@ -31,11 +31,18 @@ class PreparedStatementConditionBuilder extends ConditionBuilder {
                                        throw new SystemException("missing parameter for token number " . ($count + 1) . " in condition '".$condition."'");
                                }
                                else if (is_array($parameters[$count]) && empty($parameters[$count])) {
-                                       throw new \RuntimeException("An empty array was passed for token number " . ($count + 1) . " in condition '".$condition."'");
+                                       // Only throw an exception if the developer tools are active, preventing this
+                                       // from triggering an error for queries that are never actually executed.
+                                       // 
+                                       // This is done to preserve backwards-compatibility with earlier releases that
+                                       // allowed this kind of issue, effectively relying on the database to bail out.
+                                       if (ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS) {
+                                               throw new \RuntimeException("An empty array was passed for token number " . ($count + 1) . " in condition '" . $condition . "'");
+                                       }
                                }
                                
                                $result = '?';
-                               if (is_array($parameters[$count])) {
+                               if (is_array($parameters[$count]) && !empty($parameters[$count])) {
                                        $result .= str_repeat(',?', count($parameters[$count]) - 1);
                                }