Skip to content

Commit 8991871

Browse files
authored
Merge pull request #104 from Sevavietl/master
Do not reset placeholders in set writers
2 parents 277e87a + 2056f9e commit 8991871

File tree

4 files changed

+113
-8
lines changed

4 files changed

+113
-8
lines changed

src/Builder/Syntax/AbstractSetWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function abstractWrite(QueryPartInterface $setClass, $setOperation, $g
4343
$selects = [];
4444

4545
foreach ($setClass->$setOperation() as $select) {
46-
$selects[] = $this->writer->write($select);
46+
$selects[] = $this->writer->write($select, false);
4747
}
4848

4949
return \implode("\n".$glue."\n", $selects);

tests/Builder/Syntax/IntersectWriterTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
1110
namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;
1211

1312
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
@@ -48,7 +47,7 @@ public function tearDown()
4847
/**
4948
* @test
5049
*/
51-
public function itShouldWriteIntersects()
50+
public function itShouldWriteIntersect()
5251
{
5352
$intersect = new Intersect();
5453

@@ -80,4 +79,40 @@ public function itShouldWriteIntersectFromGenericBuilder()
8079
SQL;
8180
$this->assertEquals($expected, $this->writer->write($intersect));
8281
}
82+
83+
/**
84+
* @test
85+
*/
86+
public function itShouldNotResetPlaceholders()
87+
{
88+
$select1 = (new Select('table1'))
89+
->where()
90+
->between('column', 1, 2)
91+
->end();
92+
93+
$select2 = (new Select('table2'))
94+
->where()
95+
->between('column', 3, 4)
96+
->end();
97+
98+
$union = (new Intersect())
99+
->add($select1)
100+
->add($select2);
101+
102+
$expectedSql = <<<SQL
103+
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
104+
INTERSECT
105+
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
106+
SQL;
107+
108+
$expectedParams = [
109+
':v1' => 1,
110+
':v2' => 2,
111+
':v3' => 3,
112+
':v4' => 4,
113+
];
114+
115+
$this->assertEquals($expectedSql, $this->writer->write($union));
116+
$this->assertEquals($expectedParams, $this->writer->getValues());
117+
}
83118
}

tests/Builder/Syntax/UnionAllWriterTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
1110
namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;
1211

1312
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
@@ -48,7 +47,7 @@ public function tearDown()
4847
/**
4948
* @test
5049
*/
51-
public function itShouldWriteIntersects()
50+
public function itShouldWriteUnionAll()
5251
{
5352
$union = new UnionAll();
5453

@@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder()
8079
SQL;
8180
$this->assertEquals($expected, $this->writer->write($unionAll));
8281
}
82+
83+
/**
84+
* @test
85+
*/
86+
public function itShouldNotResetPlaceholders()
87+
{
88+
$select1 = (new Select('table1'))
89+
->where()
90+
->between('column', 1, 2)
91+
->end();
92+
93+
$select2 = (new Select('table2'))
94+
->where()
95+
->between('column', 3, 4)
96+
->end();
97+
98+
$union = (new UnionAll())
99+
->add($select1)
100+
->add($select2);
101+
102+
$expectedSql = <<<SQL
103+
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
104+
UNION ALL
105+
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
106+
SQL;
107+
108+
$expectedParams = [
109+
':v1' => 1,
110+
':v2' => 2,
111+
':v3' => 3,
112+
':v4' => 4,
113+
];
114+
115+
$this->assertEquals($expectedSql, $this->writer->write($union));
116+
$this->assertEquals($expectedParams, $this->writer->getValues());
117+
}
83118
}

tests/Builder/Syntax/UnionWriterTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
1110
namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;
1211

1312
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
@@ -48,7 +47,7 @@ public function tearDown()
4847
/**
4948
* @test
5049
*/
51-
public function itShouldWriteIntersects()
50+
public function itShouldWriteUnion()
5251
{
5352
$union = new Union();
5453

@@ -66,7 +65,7 @@ public function itShouldWriteIntersects()
6665
/**
6766
* @test
6867
*/
69-
public function itShouldWriteUnionAllFromGenericBuilder()
68+
public function itShouldWriteUnionFromGenericBuilder()
7069
{
7170
$unionAll = $this->writer->union();
7271

@@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder()
8079
SQL;
8180
$this->assertEquals($expected, $this->writer->write($unionAll));
8281
}
82+
83+
/**
84+
* @test
85+
*/
86+
public function itShouldNotResetPlaceholders()
87+
{
88+
$select1 = (new Select('table1'))
89+
->where()
90+
->between('column', 1, 2)
91+
->end();
92+
93+
$select2 = (new Select('table2'))
94+
->where()
95+
->between('column', 3, 4)
96+
->end();
97+
98+
$union = (new Union())
99+
->add($select1)
100+
->add($select2);
101+
102+
$expectedSql = <<<SQL
103+
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
104+
UNION
105+
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
106+
SQL;
107+
108+
$expectedParams = [
109+
':v1' => 1,
110+
':v2' => 2,
111+
':v3' => 3,
112+
':v4' => 4,
113+
];
114+
115+
$this->assertEquals($expectedSql, $this->writer->write($union));
116+
$this->assertEquals($expectedParams, $this->writer->getValues());
117+
}
83118
}

0 commit comments

Comments
 (0)