From: Michael Wallner Date: Tue, 5 Mar 2013 14:03:15 +0000 (+0100) Subject: flush X-Git-Tag: v1.0.0~18 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=commitdiff_plain;h=0e684b0140154ebc8a304670c0349da840a16ad2 flush --- diff --git a/lib/pq/Gateway/Cell.php b/lib/pq/Gateway/Cell.php index 730efb0..ba58404 100644 --- a/lib/pq/Gateway/Cell.php +++ b/lib/pq/Gateway/Cell.php @@ -64,6 +64,8 @@ class Cell */ function mod($data, $op = null) { if (!($this->data instanceof Expr)) { + $this->data = new Expr($this->name); + /* if (!isset($this->data)) { $this->data = new Expr($this->name); } elseif (is_numeric($this->data)) { @@ -71,6 +73,7 @@ class Cell } else { $this->data = new Expr("%s", $this->row->getTable()->getConnection()->quote($this->data)); } + */ } if ($data instanceof Expr) { diff --git a/lib/pq/Gateway/Row.php b/lib/pq/Gateway/Row.php index 885c95a..dc07e3f 100644 --- a/lib/pq/Gateway/Row.php +++ b/lib/pq/Gateway/Row.php @@ -91,6 +91,14 @@ class Row implements \JsonSerializable return $where; } + protected function changes() { + $changes = array(); + foreach ($this->mods as $name => $cell) { + $changes[$name] = $cell->get(); + } + return $changes; + } + /** * Get a cell * @param string $p @@ -117,7 +125,7 @@ class Row implements \JsonSerializable * @return \pq\Gateway\Row */ function create() { - $this->data = $this->table->create($this->mods)->current()->data; + $this->data = $this->table->create($this->changes())->current()->data; $this->mods = array(); return $this; } @@ -127,7 +135,7 @@ class Row implements \JsonSerializable * @return \pq\Gateway\Row */ function update() { - $this->data = $this->table->update($this->criteria(), $this->mods)->current()->data; + $this->data = $this->table->update($this->criteria(), $this->changes())->current()->data; $this->mods = array(); return $this; } diff --git a/lib/pq/Query/Writer.php b/lib/pq/Query/Writer.php index e25a1fc..bfd7094 100644 --- a/lib/pq/Query/Writer.php +++ b/lib/pq/Query/Writer.php @@ -96,6 +96,8 @@ class Writer function param($param, $type = null) { if ($param instanceof Expr) { return (string) $param; + } else { + var_dump($param); } $this->params[] = $param; diff --git a/lib/tmp.php b/lib/tmp.php index ef50e26..e262481 100644 --- a/lib/tmp.php +++ b/lib/tmp.php @@ -26,17 +26,9 @@ class FooCollection extends \pq\Gateway\Rowset { $conn = new \pq\Connection; $types = new \pq\Types($conn); $table = new FooModel($conn); -print_r( $table->find(array("dt" => new \pq\Query\Expr("between %s and %s", $conn->quote("2013-03-01"), $conn->quote("2013-03-04")))) ); -echo PHP_EOL; -print_r( $table->find(array("id>" => 1, "OR" => array(array("id=" => 1), array("id="=>2))))); -echo PHP_EOL; -print_r( $table->find(array("OR" => array("id>" => 1, "OR" => array(array("id=" => 1), array("id="=>2)))))); -echo PHP_EOL; -print_r( $table->create(array("data" => "blabla")) ); -echo PHP_EOL; -print_r( $table->create(array("data" => new \pq\Query\Expr("DEFAULT"))) ); -echo PHP_EOL; -print_r( $table->update(array("id=" => 4), array("data" => "die 4")) ); -echo PHP_EOL; -print_r( $table->delete(array(new \pq\Query\Expr("data is null"))) ); +$rowset = $table->find(array(array("id>" => 1), array("id IS" => new pq\Query\Expr("NULL")))); +$current = $rowset->current(); +$current->dt->mod(new pq\Query\Expr("- interval '3 day'")); +$current->update(); +var_dump($current); echo PHP_EOL; \ No newline at end of file