X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpq%2FQuery%2FExpr.php;h=0f3d86e52ba1db3ae3cfb99ca9391e7f3e2396e1;hb=0e2eb1f13ef60ce9a8709354136c42f7d87b2345;hp=d02b13fea5d07781a9f136eb249fff5de8963796;hpb=caa2499169b61c7dc6254886e73dcfc000737ed6;p=m6w6%2Fpq-gateway diff --git a/lib/pq/Query/Expr.php b/lib/pq/Query/Expr.php index d02b13f..0f3d86e 100644 --- a/lib/pq/Query/Expr.php +++ b/lib/pq/Query/Expr.php @@ -8,17 +8,21 @@ class Expr * @var string */ protected $expression; + + /** + * @var \pq\Query\Expr + */ + protected $next; /** * @param string $e the expression or a format string followed by arguments * @param string ... */ - function __construct($e) { + function __construct($e, $arg = null) { if (func_num_args() > 1) { - $this->expression = call_user_func_array("sprintf", func_get_args()); - } else { - $this->expression = $e; + $e = call_user_func_array("sprintf", func_get_args()); } + $this->expression = trim($e); } /** @@ -26,6 +30,33 @@ class Expr * @return string */ function __toString() { - return (string) $this->expression; + $string = $this->expression; + if ($this->next) { + $string .= " " . $this->next; + } + return (string) $string; + } + + /** + * Check for NULL + * @return bool + */ + function isNull() { + return !strcasecmp($this->expression, "null"); + } + + /** + * Append an expresssion + * @param \pq\Query\Expr $next + * @return \pq\Query\Expr $this + * @throws \UnexpectedValueException if any expr is NULL + */ + function add(Expr $next) { + if ($this->isNull() || $next->isNull()) { + throw new \UnexpectedValueException("Cannot add anything to NULL"); + } + for ($that = $this; $that->next; $that = $that->next); + $that->next = $next; + return $this; } }