Skip to content

Commit

Permalink
Fixes #22 add JOIN_FULL_OUTER for full outer join
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
  • Loading branch information
samsonasik committed Aug 3, 2020
1 parent 69f932b commit 1002d8e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/book/sql.md
Expand Up @@ -117,6 +117,7 @@ class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface
{
const JOIN_INNER = 'inner';
const JOIN_OUTER = 'outer';
const JOIN_FULL_OUTER = 'full outer';
const JOIN_LEFT = 'left';
const JOIN_RIGHT = 'right';
const SQL_STAR = '*';
Expand Down Expand Up @@ -180,7 +181,7 @@ $select->join(
'foo', // table name
'id = bar.id', // expression to join on (will be quoted by platform object before insertion),
['bar', 'baz'], // (optional) list of columns, same requirements as columns() above
$select::JOIN_OUTER // (optional), one of inner, outer, left, right also represented by constants in the API
$select::JOIN_OUTER // (optional), one of inner, outer, full outer, left, right also represented by constants in the API
);

$select
Expand Down
1 change: 1 addition & 0 deletions src/Sql/Join.php
Expand Up @@ -27,6 +27,7 @@ class Join implements Iterator, Countable
{
const JOIN_INNER = 'inner';
const JOIN_OUTER = 'outer';
const JOIN_FULL_OUTER = 'full outer';
const JOIN_LEFT = 'left';
const JOIN_RIGHT = 'right';
const JOIN_RIGHT_OUTER = 'right outer';
Expand Down
1 change: 1 addition & 0 deletions src/Sql/Select.php
Expand Up @@ -39,6 +39,7 @@ class Select extends AbstractPreparableSql
const QUANTIFIER_ALL = 'ALL';
const JOIN_INNER = Join::JOIN_INNER;
const JOIN_OUTER = Join::JOIN_OUTER;
const JOIN_FULL_OUTER = Join::JOIN_FULL_OUTER;
const JOIN_LEFT = Join::JOIN_LEFT;
const JOIN_RIGHT = Join::JOIN_RIGHT;
const JOIN_RIGHT_OUTER = Join::JOIN_RIGHT_OUTER;
Expand Down
7 changes: 7 additions & 0 deletions test/unit/Sql/JoinTest.php
Expand Up @@ -94,6 +94,13 @@ public function testJoin()
self::assertSame($join, $return);
}

public function testJoinFullOuter()
{
$join = new Join;
$return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_FULL_OUTER);
self::assertSame($join, $return);
}

public function testJoinWillThrowAnExceptionIfNameIsNoValid()
{
$join = new Join();
Expand Down
13 changes: 13 additions & 0 deletions test/unit/Sql/SelectTest.php
Expand Up @@ -1420,6 +1420,18 @@ public function providerData()
'processOffset' => ['?'],
];

// join with alternate type full outer
$select54 = new Select;
$select54->from('foo')->join('zac', 'm = n', ['bar', 'baz'], Select::JOIN_FULL_OUTER);
// @codingStandardsIgnoreStart
$sqlPrep54 = // same
$sqlStr54 = 'SELECT "foo".*, "zac"."bar" AS "bar", "zac"."baz" AS "baz" FROM "foo" FULL OUTER JOIN "zac" ON "m" = "n"';
// @codingStandardsIgnoreEnd
$internalTests54 = [
'processSelect' => [[['"foo".*'], ['"zac"."bar"', '"bar"'], ['"zac"."baz"', '"baz"']], '"foo"'],
'processJoins' => [[['FULL OUTER', '"zac"', '"m" = "n"']]],
];

/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
Expand Down Expand Up @@ -1484,6 +1496,7 @@ public function providerData()
[$select51, $sqlPrep51, [], $sqlStr51, $internalTests51],
[$select52, $sqlPrep52, [], $sqlStr52, $internalTests52],
[$select53, $sqlPrep53, $params53, $sqlStr53, $internalTests53, true],
[$select54, $sqlPrep54, [], $sqlStr54, $internalTests54],
];
}
}

0 comments on commit 1002d8e

Please sign in to comment.