Completed
Pull Request — 3.x (#184)
by
unknown
01:29
created

Select::lateralJoinSubSelect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 2
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 */
9
namespace Aura\SqlQuery\Pgsql;
10
11
use Aura\SqlQuery\Common;
12
13
/**
14
 *
15
 * An object for PgSQL SELECT queries.
16
 *
17
 * @package Aura.SqlQuery
18
 *
19
 */
20
class Select extends Common\Select
21
{
22
    /**
23
     *
24
     * Adds a LATERAL JOIN to an aliased subselect and columns to the query.
25
     *
26
     * @param string $join The join type: inner, left, natural, etc.
27
     *
28
     * @param string|Select $spec If a Select
29
     * object, use as the sub-select; if a string, the sub-select
30
     * command string.
31
     *
32
     * @param string $name The alias name for the sub-select.
33
     *
34
     * @param string $cond Join on this condition.
35
     *
36
     * @param array $bind Values to bind to ?-placeholders in the condition.
37
     *
38
     * @return $this
39
     *
40
     * @throws Exception
41
     *
42
     */
43
    public function lateralJoinSubSelect($join, $spec, $name, $cond = null, array $bind = array())
44
    {
45
        $join = strtoupper(ltrim("$join JOIN LATERAL"));
46
        $this->addTableRef("$join (SELECT ...) AS", $name);
47
48
        $spec = $this->subSelect($spec, '            ');
49
        $name = $this->quoter->quoteName($name);
50
        $cond = $this->fixJoinCondition($cond, $bind);
51
52
        $text = rtrim("$join ($spec        ) $name $cond");
53
        return $this->addJoin('        ' . $text);
54
    }
55
}
56