-
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.
Add MySQL IS_IPV4_MAPPED/COMPAT functions
- Loading branch information
1 parent
cf83460
commit 51d9339
Showing
6 changed files
with
123 additions
and
1 deletion.
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 IsIpv4Compat 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_IPV4_COMPAT(' | ||
. ( | ||
$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
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 IsIpv4Mapped 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_IPV4_MAPPED(' | ||
. ( | ||
$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
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 IsIpv4CompatTest extends MysqlTestCase | ||
{ | ||
public function testIsIpv4Compat() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT IS_IPV4_COMPAT(INET6_ATON('::192.0.2.1')) FROM DoctrineExtensions\Tests\Entities\Blank b", | ||
"SELECT IS_IPV4_COMPAT(INET6_ATON('::192.0.2.1')) AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
} |
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 IsIpv4MappedTest extends MysqlTestCase | ||
{ | ||
public function testIsIpv4Mapped() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:192.0.2.1')) FROM DoctrineExtensions\Tests\Entities\Blank b", | ||
"SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:192.0.2.1')) AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
} |