add identity and lock
[m6w6/pq-gateway] / lib / pq / Query / Writer.php
index 6e069450d046332460cae6becb0b71444186ed6d..b5f3ab2176d8d9fe4d0999060fc01ee206bc30d2 100644 (file)
@@ -48,7 +48,13 @@ class Writer implements WriterInterface
         * @return string
         */
        protected function reduce($q, $v) {
-               return $q . " " . (is_array($v) ? implode(", ", $v) : $v);
+               if (is_array($v)) {
+                       $v = implode(", ", $v);
+               }
+               if (strlen($q)) {
+                       $q .= " ";
+               }
+               return $q . $v;
        }
 
        /**
@@ -83,6 +89,9 @@ class Writer implements WriterInterface
         * @return \pq\Query\Writer
         */
        function write() {
+               if (strlen($this->query)) {
+                       $this->query .= " ";
+               }
                $this->query .= array_reduce(func_get_args(), array($this, "reduce"));
                return $this;
        }