X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FQuery%2FExpressible.php;fp=lib%2Fpq%2FQuery%2FExpressible.php;h=ffcf7c2c0f0936d0b693ece11846b85261492156;hp=0000000000000000000000000000000000000000;hb=dc87da9c4ec52918e34f2e43eac3014f0f99a8bc;hpb=519b07c17830f76e97b269a4b2a4936b02a4eae7 diff --git a/lib/pq/Query/Expressible.php b/lib/pq/Query/Expressible.php new file mode 100644 index 0000000..ffcf7c2 --- /dev/null +++ b/lib/pq/Query/Expressible.php @@ -0,0 +1,72 @@ +data = $data; + } + + /** + * Get value as string + * @return string + */ + function __toString() { + return (string) $this->data; + } + + /** + * Test whether the value is an unevaluated expression + * @return bool + */ + function isExpr() { + return $this->data instanceof Expr; + } + + /** + * Get value + * @return mixed + */ + function get() { + return $this->data; + } + + /** + * Set the value + * @param mixed $data + * @return \pq\Query\Expressible + */ + function set($data) { + $this->data = $data; + return $this; + } + + /** + * Modify the data + * @param mixed $data + * @param string $op a specific operator + * @return \pq\Query\Expressible + */ + function mod($data, $op = null) { + if (!($this->data instanceof Expr)) { + $this->data = new Expr($this->name); + } + + if ($data instanceof Expr) { + $this->data->add($data); + } elseif (!isset($op) && is_numeric($data)) { + $this->data->add(new Expr("+ $data")); + } else { + $data = $this->row->getTable()->getConnection()->quote($data); + $this->data->add(new Expr("%s %s", isset($op) ? $op : "||", $data)); + } + + return $this; + } +} \ No newline at end of file