X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FQuery%2FExpr.php;h=ae87c1f92abe4b4bdd4d20f1cc6d5c2d9f9b6ce0;hp=d02b13fea5d07781a9f136eb249fff5de8963796;hb=01bd45d05ce58796db7540d60671b8cff5d46bff;hpb=caa2499169b61c7dc6254886e73dcfc000737ed6 diff --git a/lib/pq/Query/Expr.php b/lib/pq/Query/Expr.php index d02b13f..ae87c1f 100644 --- a/lib/pq/Query/Expr.php +++ b/lib/pq/Query/Expr.php @@ -8,6 +8,11 @@ class Expr * @var string */ protected $expression; + + /** + * @var \pq\Query\Expr + */ + protected $next; /** * @param string $e the expression or a format string followed by arguments @@ -15,10 +20,9 @@ class Expr */ function __construct($e) { 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,29 @@ class Expr * @return string */ function __toString() { - return (string) $this->expression; + return (string) $this->expression . $this->next; + } + + /** + * 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; } }