Skip to content

Do not reset placeholders in set writers #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Builder/Syntax/AbstractSetWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function abstractWrite(QueryPartInterface $setClass, $setOperation, $g
$selects = [];

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

return \implode("\n".$glue."\n", $selects);
Expand Down
39 changes: 37 additions & 2 deletions tests/Builder/Syntax/IntersectWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;

use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function tearDown()
/**
* @test
*/
public function itShouldWriteIntersects()
public function itShouldWriteIntersect()
{
$intersect = new Intersect();

Expand Down Expand Up @@ -80,4 +79,40 @@ public function itShouldWriteIntersectFromGenericBuilder()
SQL;
$this->assertEquals($expected, $this->writer->write($intersect));
}

/**
* @test
*/
public function itShouldNotResetPlaceholders()
{
$select1 = (new Select('table1'))
->where()
->between('column', 1, 2)
->end();

$select2 = (new Select('table2'))
->where()
->between('column', 3, 4)
->end();

$union = (new Intersect())
->add($select1)
->add($select2);

$expectedSql = <<<SQL
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
INTERSECT
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
SQL;

$expectedParams = [
':v1' => 1,
':v2' => 2,
':v3' => 3,
':v4' => 4,
];

$this->assertEquals($expectedSql, $this->writer->write($union));
$this->assertEquals($expectedParams, $this->writer->getValues());
}
}
39 changes: 37 additions & 2 deletions tests/Builder/Syntax/UnionAllWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;

use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function tearDown()
/**
* @test
*/
public function itShouldWriteIntersects()
public function itShouldWriteUnionAll()
{
$union = new UnionAll();

Expand Down Expand Up @@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder()
SQL;
$this->assertEquals($expected, $this->writer->write($unionAll));
}

/**
* @test
*/
public function itShouldNotResetPlaceholders()
{
$select1 = (new Select('table1'))
->where()
->between('column', 1, 2)
->end();

$select2 = (new Select('table2'))
->where()
->between('column', 3, 4)
->end();

$union = (new UnionAll())
->add($select1)
->add($select2);

$expectedSql = <<<SQL
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
UNION ALL
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
SQL;

$expectedParams = [
':v1' => 1,
':v2' => 2,
':v3' => 3,
':v4' => 4,
];

$this->assertEquals($expectedSql, $this->writer->write($union));
$this->assertEquals($expectedParams, $this->writer->getValues());
}
}
41 changes: 38 additions & 3 deletions tests/Builder/Syntax/UnionWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax;

use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function tearDown()
/**
* @test
*/
public function itShouldWriteIntersects()
public function itShouldWriteUnion()
{
$union = new Union();

Expand All @@ -66,7 +65,7 @@ public function itShouldWriteIntersects()
/**
* @test
*/
public function itShouldWriteUnionAllFromGenericBuilder()
public function itShouldWriteUnionFromGenericBuilder()
{
$unionAll = $this->writer->union();

Expand All @@ -80,4 +79,40 @@ public function itShouldWriteUnionAllFromGenericBuilder()
SQL;
$this->assertEquals($expected, $this->writer->write($unionAll));
}

/**
* @test
*/
public function itShouldNotResetPlaceholders()
{
$select1 = (new Select('table1'))
->where()
->between('column', 1, 2)
->end();

$select2 = (new Select('table2'))
->where()
->between('column', 3, 4)
->end();

$union = (new Union())
->add($select1)
->add($select2);

$expectedSql = <<<SQL
SELECT table1.* FROM table1 WHERE (table1.column BETWEEN :v1 AND :v2)
UNION
SELECT table2.* FROM table2 WHERE (table2.column BETWEEN :v3 AND :v4)
SQL;

$expectedParams = [
':v1' => 1,
':v2' => 2,
':v3' => 3,
':v4' => 4,
];

$this->assertEquals($expectedSql, $this->writer->write($union));
$this->assertEquals($expectedParams, $this->writer->getValues());
}
}