dont depend on react
[m6w6/pq-gateway] / lib / pq / Query / Expr.php
index ae87c1f92abe4b4bdd4d20f1cc6d5c2d9f9b6ce0..31e8c969b290f21a3653a6a20e3faae7fa465846 100644 (file)
@@ -30,7 +30,11 @@ class Expr
         * @return string
         */
        function __toString() {
-               return (string) $this->expression . $this->next;
+               $string = $this->expression;
+               if ($this->next) {
+                       $string .= " " . $this->next;
+               }
+               return (string) $string;
        }
        
        /**
@@ -48,11 +52,14 @@ class Expr
         * @throws \UnexpectedValueException if any expr is NULL
         */
        function add(Expr $next) {
-               if ($this->isNull() || $next->isNull()) {
+               if ($this->isNull()) {
                        throw new \UnexpectedValueException("Cannot add anything to NULL");
                }
-               for ($that = $this; $that->next; $that = $that->next);
-               $that->next = $next;
+               if ($this->next) {
+                       $this->next->add($next);
+               } else {
+                       $this->next = $next;
+               }
                return $this;
        }
 }