X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FTable.php;h=2e82a214b37d89c90815aded33d340616f222005;hp=ebab838bf672b8c01f2229720644a617038a17f0;hb=dc87da9c4ec52918e34f2e43eac3014f0f99a8bc;hpb=89caabf7e3ebc62190fccba97e3bc11f7f32b58c diff --git a/lib/pq/Gateway/Table.php b/lib/pq/Gateway/Table.php index ebab838..2e82a21 100644 --- a/lib/pq/Gateway/Table.php +++ b/lib/pq/Gateway/Table.php @@ -3,6 +3,7 @@ namespace pq\Gateway; use \pq\Query\Writer as QueryWriter; +use \pq\Query\Executor as QueryExecutor; class Table { @@ -27,9 +28,14 @@ class Table protected $rowset = "\\pq\\Gateway\\Rowset"; /** - * @var \pq\Query\Writer + * @var \pq\Query\WriterIterface */ protected $query; + + /** + * @var \pq\Query\ExecutorInterface + */ + protected $exec; /** * @param string $name @@ -73,7 +79,31 @@ class Table * @return \pq\Query\WriterInterface */ function getQueryWriter() { - return $this->query ?: new QueryWriter; + if (!$this->query) { + $this->query = new QueryWriter; + } + return $this->query; + } + + /** + * Set the query executor + * @param \pq\Query\ExecutorInterface $exec + * @return \pq\Gateway\Table + */ + function setQueryExecutor(\pq\Query\ExecutorInterface $exec) { + $this->exec = $exec; + return $this; + } + + /** + * Get the query executor + * @return \pq\Query\ExecutorInterface + */ + function getQueryExecutor() { + if (!$this->exec) { + $this->exec = new QueryExecutor($this->conn); + } + return $this->exec; } /** @@ -92,12 +122,19 @@ class Table /** * Execute the query - * @param \pq\Query\Writer $query + * @param \pq\Query\WriterInterface $query * @return mixed */ protected function execute(QueryWriter $query) { - $result = $query->exec($this->conn); - + return $this->getQueryExecutor()->execute($query, array($this, "onResult")); + } + + /** + * Retreives the result of an executed query + * @param \pq\Result $result + * @return mixed + */ + public function onResult(\pq\Result $result) { if ($result->status != \pq\Result::TUPLES_OK) { return $result; } @@ -111,14 +148,14 @@ class Table return $result; } - + /** * Find rows in the table * @param array $where * @param array|string $order * @param int $limit * @param int $offset - * @return \pq\Result + * @return mixed */ function find(array $where = null, $order = null, $limit = 0, $offset = 0) { $query = $this->getQueryWriter()->reset(); @@ -140,7 +177,7 @@ class Table * Insert a row into the table * @param array $data * @param string $returning - * @return \pq\Result + * @return mixed */ function create(array $data = null, $returning = "*") { $query = $this->getQueryWriter()->reset(); @@ -169,7 +206,7 @@ class Table * @param array $where * @param array $data * @param string $returning - * @retunr \pq\Result + * @retunr mixed */ function update(array $where, array $data, $returning = "*") { $query = $this->getQueryWriter()->reset(); @@ -190,7 +227,7 @@ class Table * Delete rows from the table * @param array $where * @param string $returning - * @return pq\Result + * @return mixed */ function delete(array $where, $returning = null) { $query = $this->getQueryWriter()->reset();