From e6dbc733c5551ef26442dd5fffb42b1a8bb6b950 Mon Sep 17 00:00:00 2001 From: romanb Date: Mon, 23 Mar 2009 18:48:54 +0000 Subject: [PATCH] [2.0] Added remaining supported functions for 2.0. --- .../ORM/Query/AST/Functions/AbsFunction.php | 44 ++++++++++++ .../AST/Functions/CurrentDateFunction.php | 34 +++++++++ .../AST/Functions/CurrentTimeFunction.php | 34 +++++++++ .../Functions/CurrentTimestampFunction.php | 34 +++++++++ .../Query/AST/Functions/LengthFunction.php | 44 ++++++++++++ .../Query/AST/Functions/LocateFunction.php | 70 +++++++++++++++++++ .../ORM/Query/AST/Functions/ModFunction.php | 56 +++++++++++++++ .../ORM/Query/AST/Functions/SizeFunction.php | 44 ++++++++++++ .../ORM/Query/AST/Functions/SqrtFunction.php | 44 ++++++++++++ 9 files changed, 404 insertions(+) create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php new file mode 100644 index 000000000..bc1863fa9 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php @@ -0,0 +1,44 @@ +_simpleArithmeticExpression; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Use platform to get SQL + return 'ABS(' . $sqlWalker->walkSimpleArithmeticExpression($this->_simpleArithmeticExpression) . ')'; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_simpleArithmeticExpression = $parser->_SimpleArithmeticExpression(); + $parser->match(')'); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php new file mode 100644 index 000000000..8d75d97a3 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php @@ -0,0 +1,34 @@ +getLexer(); + $parser->match($lexer->lookahead['value']); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php new file mode 100644 index 000000000..1f54d449c --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php @@ -0,0 +1,34 @@ +getLexer(); + $parser->match($lexer->lookahead['value']); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php new file mode 100644 index 000000000..edbb9b37c --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php @@ -0,0 +1,34 @@ +getLexer(); + $parser->match($lexer->lookahead['value']); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php new file mode 100644 index 000000000..142b296ba --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php @@ -0,0 +1,44 @@ +_stringPrimary; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Use platform to get SQL + return 'LENGTH(' . $sqlWalker->walkStringPrimary($this->_stringPrimary) . ')'; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_stringPrimary = $parser->_StringPrimary(); + $parser->match(')'); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php new file mode 100644 index 000000000..b7ee43b5f --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php @@ -0,0 +1,70 @@ +_firstStringPrimary; + } + + public function getSecondStringPrimary() + { + return $this->_secondStringPrimary; + } + + public function getSimpleArithmeticExpression() + { + return $this->_simpleArithmeticExpression; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Use platform to get SQL + $sql = 'LOCATE(' . + $sqlWalker->walkStringPrimary($this->_firstStringPrimary) + . ', ' . + $sqlWalker->walkStringPrimary($this->_secondStringPrimary); + + if ($this->_simpleArithmeticExpression) { + $sql .= ', ' . $sqlWalker->walkSimpleArithmeticExpression($this->_simpleArithmeticExpression); + } + return $sql . ')'; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_firstStringPrimary = $parser->_StringPrimary(); + $parser->match(','); + $this->_secondStringPrimary = $parser->_StringPrimary(); + if ($lexer->isNextToken(',')) { + $parser->match(','); + $this->_simpleArithmeticExpression = $parser->_SimpleArithmeticExpression(); + } + $parser->match(')'); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php new file mode 100644 index 000000000..9d176888c --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php @@ -0,0 +1,56 @@ +_firstSimpleArithmeticExpression; + } + + public function getSecondSimpleArithmeticExpression() + { + return $this->_secondSimpleArithmeticExpression; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Use platform to get SQL + return 'SQRT(' . + $sqlWalker->walkSimpleArithmeticExpression($this->_firstSimpleArithmeticExpression) + . ', ' . + $sqlWalker->walkSimpleArithmeticExpression($this->_secondSimpleArithmeticExpression) + . ')'; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_firstSimpleArithmeticExpression = $parser->_SimpleArithmeticExpression(); + $parser->match(','); + $this->_secondSimpleArithmeticExpression = $parser->_SimpleArithmeticExpression(); + $parser->match(')'); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php new file mode 100644 index 000000000..ff612ce63 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -0,0 +1,44 @@ +_collectionPathExpression; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Construct appropriate SQL + return ""; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_collectionPathExpression = $parser->_CollectionValuedPathExpression(); + $parser->match(')'); + } +} + diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php new file mode 100644 index 000000000..cf97dc64d --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php @@ -0,0 +1,44 @@ +_simpleArithmeticExpression; + } + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + //TODO: Use platform to get SQL + return 'SQRT(' . $sqlWalker->walkSimpleArithmeticExpression($this->_simpleArithmeticExpression) . ')'; + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $lexer = $parser->getLexer(); + $parser->match($lexer->lookahead['value']); + $parser->match('('); + $this->_simpleArithmeticExpression = $parser->_SimpleArithmeticExpression(); + $parser->match(')'); + } +} +