flush
authorMichael Wallner <mike@php.net>
Tue, 5 Mar 2013 14:03:15 +0000 (15:03 +0100)
committerMichael Wallner <mike@php.net>
Tue, 5 Mar 2013 14:03:15 +0000 (15:03 +0100)
lib/pq/Gateway/Cell.php
lib/pq/Gateway/Row.php
lib/pq/Query/Writer.php
lib/tmp.php

index 730efb07bc4a36c1058bd77a3878a5bd6e755d85..ba58404a7c190c261cb82c78ec2e2a42240147c5 100644 (file)
@@ -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) {
index 885c95abd5a166b51cb35e6281aa72280e6a67f7..dc07e3f208e200cd0c1b87290619587d25d41882 100644 (file)
@@ -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;
        }
index e25a1fc7d15c71b991b05de81339771b4f531e36..bfd7094715d76a175a99b8fc7a32783a287ebd8d 100644 (file)
@@ -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;
index ef50e26bfb03a84c50d70d7f9eb40f8b9adbab97..e2624817b6da4a97ea0826c9f18e72a4d9b246b9 100644 (file)
@@ -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