Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MySQL CHAR_LENGTH function. #61

Merged
merged 1 commit into from

3 participants

@smottt

Added support for MySQL CHAR_LENGTH function.

@beberlei beberlei merged commit ee131dd into beberlei:master
@Hardix

Do i have to every time write classes to parse mysql functions ? is there anyway to bypass this so that i no longer need to write classes for this. i mean this is too complex architecture. what if my query is using nested mysql functions for complex db operation. so it would be too difficult to write parser for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2012
  1. @smottt
This page is out of date. Refresh to see the latest.
Showing with 52 additions and 0 deletions.
  1. +52 −0 lib/DoctrineExtensions/Query/Mysql/CharLength.php
View
52 lib/DoctrineExtensions/Query/Mysql/CharLength.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * DoctrineExtensions Mysql Function Pack
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace DoctrineExtensions\Query\Mysql;
+
+use Doctrine\ORM\Query\AST\Functions\FunctionNode,
+ Doctrine\ORM\Query\Lexer;
+
+/**
+ * "CHAR_LENGTH" "(" SimpleArithmeticExpression ")"
+ *
+ * @category DoctrineExtensions
+ * @package DoctrineExtensions\Query\Mysql
+ * @author Metod <metod@simpel.si>
+ * @license BSD License
+ */
+class CharLength extends FunctionNode
+{
+ private $expr;
+
+ /**
+ * @override
+ */
+ public function parse(\Doctrine\ORM\Query\Parser $parser)
+ {
+ $parser->match(Lexer::T_IDENTIFIER);
+ $parser->match(Lexer::T_OPEN_PARENTHESIS);
+
+ $this->expr1 = $parser->ArithmeticExpression();
+
+ $parser->match(Lexer::T_CLOSE_PARENTHESIS);
+ }
+
+ /**
+ * @override
+ */
+ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
+ {
+ return 'CHAR_LENGTH('.$sqlWalker->walkArithmeticPrimary($this->expr1).')';
+ }
+}
Something went wrong with that request. Please try again.