-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8347824
commit cf83460
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Query\Mysql; | ||
|
||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\AST\Node; | ||
use Doctrine\ORM\Query\Lexer; | ||
use Doctrine\ORM\Query\Parser; | ||
use Doctrine\ORM\Query\QueryException; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
|
||
class IsIpv6 extends FunctionNode | ||
{ | ||
public $valueExpression = null; | ||
|
||
/** | ||
* @param Parser $parser | ||
* | ||
* @throws QueryException | ||
*/ | ||
public function parse(Parser $parser) | ||
{ | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$parser->match(Lexer::T_OPEN_PARENTHESIS); | ||
$this->valueExpression = $parser->StringPrimary(); | ||
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | ||
} | ||
|
||
/** | ||
* @param SqlWalker $sqlWalker | ||
* | ||
* @return string | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker) | ||
{ | ||
return 'IS_IPV6(' | ||
. ( | ||
$this->valueExpression instanceof Node | ||
? $this->valueExpression->dispatch($sqlWalker) | ||
: "'" . $this->valueExpression . "'" | ||
) | ||
.')'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Mysql; | ||
|
||
use DoctrineExtensions\Tests\Query\MysqlTestCase; | ||
|
||
class IsIpv6Test extends MysqlTestCase | ||
{ | ||
public function testIsIpv6() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT IS_IPV6('2001:db8::dead:b33f') FROM DoctrineExtensions\Tests\Entities\Blank b", | ||
"SELECT IS_IPV6('2001:db8::dead:b33f') AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
} |