From 73c7ab84ca985026221c881cfd7ef5d89d77579f Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Mon, 30 Mar 2015 15:03:34 -0400 Subject: [PATCH 1/3] process reserved subtrees (case when exists etc) --- src/PHPSQL/Creator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PHPSQL/Creator.php b/src/PHPSQL/Creator.php index 39b26e9..4eef23c 100644 --- a/src/PHPSQL/Creator.php +++ b/src/PHPSQL/Creator.php @@ -449,6 +449,7 @@ protected function processSubTree($parsed, $delim = " ") { $sql .= $this->processConstant($v); $sql .= $this->processSubQuery($v); $sql .= $this->processSelectBracketExpression($v); + $sql .= $this->processReserved($v); if ($len == strlen($sql)) { throw new \PHPSQL\Exception\UnableToCreateSQL('expression subtree', $k, $v, 'expr_type'); From fc4b9b8e1bdcf28ef00dcc60f2dd63ec3a0b4ba2 Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Tue, 21 Apr 2015 10:31:50 -0400 Subject: [PATCH 2/3] Adding some processFunction, processColRef that allow creation of a valid query I had just succesfully parsed --- src/PHPSQL/Creator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PHPSQL/Creator.php b/src/PHPSQL/Creator.php index 4eef23c..ada074e 100644 --- a/src/PHPSQL/Creator.php +++ b/src/PHPSQL/Creator.php @@ -450,6 +450,7 @@ protected function processSubTree($parsed, $delim = " ") { $sql .= $this->processSubQuery($v); $sql .= $this->processSelectBracketExpression($v); $sql .= $this->processReserved($v); + $sql .= $this->processColRef($v); if ($len == strlen($sql)) { throw new \PHPSQL\Exception\UnableToCreateSQL('expression subtree', $k, $v, 'expr_type'); @@ -471,6 +472,7 @@ protected function processRefClause($parsed) { $sql .= $this->processColRef($v); $sql .= $this->processOperator($v); $sql .= $this->processConstant($v); + $sql .= $this->processFunction($v); if ($len == strlen($sql)) { throw new \PHPSQL\Exception\UnableToCreateSQL('expression ref_clause', $k, $v, 'expr_type'); From a03e3ce1ad6c298b4337e9f87c31546ab87d5304 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Apr 2015 10:56:51 -0400 Subject: [PATCH 3/3] Fixing CAST statement generation (was putting a comma after the column name (before AS)) --- src/PHPSQL/Creator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPSQL/Creator.php b/src/PHPSQL/Creator.php index ada074e..6f0dd45 100644 --- a/src/PHPSQL/Creator.php +++ b/src/PHPSQL/Creator.php @@ -413,8 +413,8 @@ protected function processFunction($parsed) { if ($len == strlen($sql)) { throw new \PHPSQL\Exception\UnableToCreateSQL('function subtree', $k, $v, 'expr_type'); } - - $sql .= ($this->isReserved($v) ? " " : ","); + $sql .= ($this->isReserved($v) || ($parsed['base_expr'] == 'CAST') + ? " " : ","); } return $parsed['base_expr'] . "(" . substr($sql, 0, -1) . ")"; }