Skip to content

Commit 4fb87aa

Browse files
authored
Merge pull request #12 from dorantor/master
Added basic support for network address operators for PostgreSQL.
2 parents 9ffa752 + 46bb66d commit 4fb87aa

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/PHPixie/Database/Driver/PDO/Adapter/Pgsql/Parser/Operator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,28 @@
44

55
class Operator extends \PHPixie\Database\Type\SQL\Parser\Operator
66
{
7+
/**
8+
* Additional operators specific to PostgreSQL
9+
*
10+
* @var array
11+
*/
12+
protected $additionalOperators = array(
13+
'compare' => array('>>', '>>=', '<<', '<<=',),
14+
);
15+
16+
/**
17+
* Operator constructor.
18+
*
19+
* @param $database
20+
* @param $fragmentParser
21+
*/
22+
public function __construct($database, $fragmentParser)
23+
{
24+
$this->operators['compare'] = array_merge(
25+
$this->operators['compare'],
26+
$this->additionalOperators['compare']
27+
);
28+
29+
parent::__construct($database, $fragmentParser);
30+
}
731
}

tests/PHPixie/Tests/Database/Driver/PDO/Adapter/Pgsql/Parser/OperatorTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
class OperatorTest extends \PHPixie\Tests\Database\Type\SQL\Parser\OperatorTest
88
{
9+
/**
10+
* List of expected results from parser
11+
*
12+
* @var array
13+
*/
914
protected $expected = array(
1015
array('"a" = ?', array(1)),
1116
array('"a" = la', array()),
@@ -25,8 +30,32 @@ class OperatorTest extends \PHPixie\Tests\Database\Type\SQL\Parser\OperatorTest
2530
array('"a" BETWEEN ? AND ?', array(1, 2)),
2631
array('"a" NOT BETWEEN ? AND ?', array(1, 2)),
2732
array('"a"."b" = b', array(1)),
28-
array('a + b = ?', array(1))
33+
array('a + b = ?', array(1)),
34+
array('"a" >> ?', array(1)),
35+
array('"a" >>= ?', array(1)),
36+
array('"a" << ?', array(1)),
37+
array('"a" <<= ?', array(1)),
2938
);
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function conditions()
44+
{
45+
return array_merge(
46+
parent::conditions(),
47+
array(
48+
$this->operator('a', '>>', array(1)),
49+
$this->operator('a', '>>=', array(1)),
50+
$this->operator('a', '<<', array(1)),
51+
$this->operator('a', '<<=', array(1)),
52+
)
53+
);
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
3059
public function setUp()
3160
{
3261
parent::setUp();

tests/PHPixie/Tests/Database/Parser/OperatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ public function testParse()
2020
}
2121
}
2222

23+
/**
24+
* List of conditions to parse
25+
*
26+
* @return array
27+
*/
2328
abstract protected function conditions();
2429
}

0 commit comments

Comments
 (0)