X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fpq%2FQuery%2FWriter.php;h=b5f3ab2176d8d9fe4d0999060fc01ee206bc30d2;hb=5803d081bb5af5faeee20da91dd2c70d8686774b;hp=f326f1ebc86a4e3d4d6808e04f4da3a08dcff66b;hpb=e2709f3f6de6d5c5ba272d353db16b015b5258b3;p=m6w6%2Fpq-gateway diff --git a/lib/pq/Query/Writer.php b/lib/pq/Query/Writer.php index f326f1e..b5f3ab2 100644 --- a/lib/pq/Query/Writer.php +++ b/lib/pq/Query/Writer.php @@ -5,7 +5,7 @@ namespace pq\Query; /** * A very simple query writer used by \pq\Gateway */ -class Writer +class Writer implements WriterInterface { /** * @var string @@ -48,7 +48,13 @@ class Writer * @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 * @return \pq\Query\Writer */ function write() { + if (strlen($this->query)) { + $this->query .= " "; + } $this->query .= array_reduce(func_get_args(), array($this, "reduce")); return $this; } @@ -94,7 +103,7 @@ class Writer * @return string */ function param($param, $type = null) { - if ($param instanceof \pq\Gateway\Cell) { + if ($param instanceof ExpressibleInterface) { $param = $param->get(); } if ($param instanceof Expr) { @@ -132,13 +141,4 @@ class Writer } return $this; } - - /** - * Execute the query through \pq\Connection::execParams($this, $this->params, $this->types) - * @param \pq\Connection $c - * @return \pq\Result - */ - function exec(\pq\Connection $c) { - return $c->execParams($this, $this->getParams(), $this->getTypes()); - } }