Added a function to disable the where keyword in condition builders
authorMarcel Werk <burntime@woltlab.com>
Wed, 4 Jul 2012 16:49:09 +0000 (18:49 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 4 Jul 2012 16:49:09 +0000 (18:49 +0200)
wcfsetup/install/files/lib/system/database/util/ConditionBuilder.class.php
wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php

index 8a833a1b3a7b6c2b781b790e215c371a31936309..97ab6b2a386d1f50aec965614c9574e36e308331 100644 (file)
@@ -43,8 +43,6 @@ class ConditionBuilder {
                
                foreach ($conditions as $condition) {
                        if (!empty($this->conditions)) $this->conditions .= " AND ";
-                       else $this->conditions = ($this->addWhereKeyword ? " WHERE " : '');
-                       
                        $this->conditions .= $condition;
                }
        }
@@ -55,6 +53,15 @@ class ConditionBuilder {
         * @return      string
         */
        public function __toString() {
-               return $this->conditions;
+               return (($this->addWhereKeyword && $this->conditions) ? 'WHERE ' : '').$this->conditions;
+       }
+       
+       /**
+        * Enables / disables the where keyword.
+        * 
+        * @param       boolean         $enable
+        */
+       public function enableWhereKeyword($enable = true) {
+               $this->addWhereKeyword = $enable;
        }
 }
index 867ce2ec3749e48a1b57312aab84e38396bfa509..c66c6524f98b82d0256783ec321e98c77439b7ef 100644 (file)
@@ -47,7 +47,6 @@ class PreparedStatementConditionBuilder extends ConditionBuilder {
                
                // add condtion
                if (!empty($this->conditions)) $this->conditions .= " AND ";
-               else $this->conditions = ($this->addWhereKeyword ? " WHERE " : '');
                $this->conditions .= $condition;
                
                // parameter handling