X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FQuery%2FWriter.php;h=6e069450d046332460cae6becb0b71444186ed6d;hp=bfd7094715d76a175a99b8fc7a32783a287ebd8d;hb=dc87da9c4ec52918e34f2e43eac3014f0f99a8bc;hpb=0e684b0140154ebc8a304670c0349da840a16ad2 diff --git a/lib/pq/Query/Writer.php b/lib/pq/Query/Writer.php index bfd7094..6e06945 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 @@ -94,10 +94,11 @@ class Writer * @return string */ function param($param, $type = null) { + if ($param instanceof ExpressibleInterface) { + $param = $param->get(); + } if ($param instanceof Expr) { return (string) $param; - } else { - var_dump($param); } $this->params[] = $param; @@ -113,14 +114,13 @@ class Writer */ function criteria(array $criteria) { if ((list($left, $right) = each($criteria))) { - array_shift($criteria); $this->write("("); if (is_array($right)) { $this->criteria($right); } else { $this->write("(", $left, $this->param($right), ")"); } - foreach ($criteria as $left => $right) { + while ((list($left, $right) = each($criteria))) { $this->write(is_int($left) && is_array($right) ? "OR" : "AND"); if (is_array($right)) { $this->criteria($right); @@ -132,15 +132,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) { - fprintf(STDERR, "Q: %s\n", $this); - fprintf(STDERR, "P: %s\n", implode(", ", $this->params)); - return $c->execParams($this, $this->params, $this->types); - } }