Skip to content

Commit 8a2c0d4

Browse files
committed
Update join types and constants to match ANSI SQL specs
Signed-off-by: pine3ree <pine3ree@gmail.com>
1 parent 140953c commit 8a2c0d4

File tree

4 files changed

+112
-16
lines changed

4 files changed

+112
-16
lines changed

src/Command/Select.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,20 @@ public function rightJoin(string $table, string $alias, $specification): self
304304
return $this;
305305
}
306306

307+
/**
308+
* @see SqlSelect::fullJoin()
309+
*
310+
* @param string $table The joined table name
311+
* @param string $alias The joined table alias
312+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
313+
* @return $this Fluent interface
314+
*/
315+
public function fullJoin(string $table, string $alias, $specification = null): self
316+
{
317+
$this->sqlStatement->fullJoin($table, $alias, $specification);
318+
return $this;
319+
}
320+
307321
/**
308322
* @see SqlSelect::naturalJoin()
309323
*
@@ -318,6 +332,20 @@ public function naturalJoin(string $table, string $alias, $specification = null)
318332
return $this;
319333
}
320334

335+
/**
336+
* @see SqlSelect::naturalInnerJoin()
337+
*
338+
* @param string $table The joined table name
339+
* @param string $alias The joined table alias
340+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
341+
* @return $this Fluent interface
342+
*/
343+
public function naturalInnerJoin(string $table, string $alias, $specification = null): self
344+
{
345+
$this->sqlStatement->naturalInnerJoin($table, $alias, $specification);
346+
return $this;
347+
}
348+
321349
/**
322350
* @see SqlSelect::naturalLeftJoin()
323351
*
@@ -346,6 +374,20 @@ public function naturalRightJoin(string $table, string $alias, $specification =
346374
return $this;
347375
}
348376

377+
/**
378+
* @see SqlSelect::naturalFullJoin()
379+
*
380+
* @param string $table The joined table name
381+
* @param string $alias The joined table alias
382+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
383+
* @return $this Fluent interface
384+
*/
385+
public function naturalFullJoin(string $table, string $alias, $specification = null): self
386+
{
387+
$this->sqlStatement->naturalFullJoin($table, $alias, $specification);
388+
return $this;
389+
}
390+
349391
/**
350392
* @see SqlSelect::crossJoin()
351393
*
@@ -361,16 +403,16 @@ public function crossJoin(string $table, string $alias, $specification = null):
361403
}
362404

363405
/**
364-
* @see SqlSelect::straightJoin()
406+
* @see SqlSelect::unionJoin()
365407
*
366408
* @param string $table The joined table name
367409
* @param string $alias The joined table alias
368410
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
369411
* @return $this Fluent interface
370412
*/
371-
public function straightJoin(string $table, string $alias, $specification = null): self
413+
public function unionJoin(string $table, string $alias, $specification = null): self
372414
{
373-
$this->sqlStatement->straightJoin($table, $alias, $specification);
415+
$this->sqlStatement->unionJoin($table, $alias, $specification);
374416
return $this;
375417
}
376418

src/Sql.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,32 @@ class Sql
9191
* Join clause types
9292
*/
9393
public const JOIN_AUTO = '';
94-
public const JOIN_INNER = 'INNER';
9594
public const JOIN_CROSS = 'CROSS';
95+
public const JOIN_UNION = 'UNION';
96+
public const JOIN_INNER = 'INNER';
9697
public const JOIN_LEFT = 'LEFT';
9798
public const JOIN_RIGHT = 'RIGHT';
98-
public const JOIN_STRAIGHT = 'STRAIGHT';
99+
public const JOIN_FULL = 'FULL';
99100
public const JOIN_NATURAL = 'NATURAL';
101+
public const JOIN_NATURAL_INNER = 'NATURAL INNER';
100102
public const JOIN_NATURAL_LEFT = 'NATURAL LEFT';
101103
public const JOIN_NATURAL_RIGHT = 'NATURAL RIGHT';
104+
public const JOIN_NATURAL_FULL = 'NATURAL_FULL';
102105
public const USING = 'USING';
103106

104107
public const JOIN_TYPES = [
105108
self::JOIN_AUTO => self::JOIN_AUTO,
106-
self::JOIN_INNER => self::JOIN_INNER,
107109
self::JOIN_CROSS => self::JOIN_CROSS,
110+
self::JOIN_UNION => self::JOIN_UNION,
111+
self::JOIN_INNER => self::JOIN_INNER,
108112
self::JOIN_LEFT => self::JOIN_LEFT,
109113
self::JOIN_RIGHT => self::JOIN_RIGHT,
110-
self::JOIN_STRAIGHT => self::JOIN_STRAIGHT,
114+
self::JOIN_FULL => self::JOIN_FULL,
111115
self::JOIN_NATURAL => self::JOIN_NATURAL,
116+
self::JOIN_NATURAL_INNER => self::JOIN_NATURAL_INNER,
112117
self::JOIN_NATURAL_LEFT => self::JOIN_NATURAL_LEFT,
113118
self::JOIN_NATURAL_RIGHT => self::JOIN_NATURAL_RIGHT,
119+
self::JOIN_NATURAL_FULL => self::JOIN_NATURAL_FULL,
114120
];
115121

116122
/*

src/Sql/Statement/Select.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public function innerJoin(string $table, string $alias, $specification = null):
631631
}
632632

633633
/**
634-
* Add a LEFT JOIN clause
634+
* Add a LEFT [OUTER] JOIN clause
635635
*
636636
* @param string $table The joined table name
637637
* @param string $alias The joined table alias
@@ -646,7 +646,7 @@ public function leftJoin(string $table, string $alias, $specification = null): s
646646
}
647647

648648
/**
649-
* Add a RIGHT JOIN clause
649+
* Add a RIGHT [OUTER] JOIN clause
650650
*
651651
* @param string $table The joined table name
652652
* @param string $alias The joined table alias
@@ -660,6 +660,21 @@ public function rightJoin(string $table, string $alias, $specification = null):
660660
);
661661
}
662662

663+
/**
664+
* Add a FULL [OUTER] JOIN clause
665+
*
666+
* @param string $table The joined table name
667+
* @param string $alias The joined table alias
668+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
669+
* @return $this Fluent interface
670+
*/
671+
public function fullJoin(string $table, string $alias, $specification = null): self
672+
{
673+
return $this->addJoin(
674+
new Join(Sql::JOIN_FULL, $table, $alias, $specification)
675+
);
676+
}
677+
663678
/**
664679
* Add a NATURAL JOIN clause
665680
*
@@ -676,7 +691,22 @@ public function naturalJoin(string $table, string $alias, $specification = null)
676691
}
677692

678693
/**
679-
* Add a NATURAL LEFT JOIN clause
694+
* Add a NATURAL INNER JOIN clause
695+
*
696+
* @param string $table The joined table name
697+
* @param string $alias The joined table alias
698+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
699+
* @return $this Fluent interface
700+
*/
701+
public function naturalInnerJoin(string $table, string $alias, $specification = null): self
702+
{
703+
return $this->addJoin(
704+
new Join(Sql::JOIN_NATURAL_INNER, $table, $alias, $specification)
705+
);
706+
}
707+
708+
/**
709+
* Add a NATURAL LEFT [OUTER]JOIN clause
680710
*
681711
* @param string $table The joined table name
682712
* @param string $alias The joined table alias
@@ -691,7 +721,7 @@ public function naturalLeftJoin(string $table, string $alias, $specification = n
691721
}
692722

693723
/**
694-
* Add a NATURAL RIGHT JOIN clause
724+
* Add a NATURAL RIGHT [OUTER] JOIN clause
695725
*
696726
* @param string $table The joined table name
697727
* @param string $alias The joined table alias
@@ -705,6 +735,21 @@ public function naturalRightJoin(string $table, string $alias, $specification =
705735
);
706736
}
707737

738+
/**
739+
* Add a NATURAL FULL [OUTER] JOIN clause
740+
*
741+
* @param string $table The joined table name
742+
* @param string $alias The joined table alias
743+
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
744+
* @return $this Fluent interface
745+
*/
746+
public function naturalFullJoin(string $table, string $alias, $specification = null): self
747+
{
748+
return $this->addJoin(
749+
new Join(Sql::JOIN_NATURAL_FULL, $table, $alias, $specification)
750+
);
751+
}
752+
708753
/**
709754
* Add a CROSS JOIN clause
710755
*
@@ -721,17 +766,17 @@ public function crossJoin(string $table, string $alias, $specification = null):
721766
}
722767

723768
/**
724-
* Add a STRAIGHT JOIN clause
769+
* Add a UNION JOIN clause
725770
*
726771
* @param string $table The joined table name
727772
* @param string $alias The joined table alias
728773
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
729774
* @return $this Fluent interface
730775
*/
731-
public function straightJoin(string $table, string $alias, $specification = null): self
776+
public function unionJoin(string $table, string $alias, $specification = null): self
732777
{
733778
return $this->addJoin(
734-
new Join(Sql::JOIN_STRAIGHT, $table, $alias, $specification)
779+
new Join(Sql::JOIN_UNION, $table, $alias, $specification)
735780
);
736781
}
737782

test/Command/SelectTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,14 @@ public function provideJoinOptions(): array
385385
['crossJoin', Sql::JOIN_CROSS],
386386
['innerJoin', Sql::JOIN_INNER],
387387
['leftJoin', Sql::JOIN_LEFT],
388+
['rightJoin', Sql::JOIN_RIGHT],
389+
['fullJoin', Sql::JOIN_FULL],
388390
['naturalJoin', Sql::JOIN_NATURAL],
391+
['naturalInnerJoin', Sql::JOIN_NATURAL_INNER],
389392
['naturalLeftJoin', Sql::JOIN_NATURAL_LEFT],
390393
['naturalRightJoin', Sql::JOIN_NATURAL_RIGHT],
391-
['rightJoin', Sql::JOIN_RIGHT],
392-
['straightjoin', Sql::JOIN_STRAIGHT],
394+
['naturalfullJoin', Sql::JOIN_NATURAL_FULL],
395+
['unionjoin', Sql::JOIN_UNION],
393396
];
394397
}
395398

0 commit comments

Comments
 (0)