Passed
Push — master ( f2cade...8ecc02 )
by Mauro
01:55
created

PgSqlQueryBuilder::getQueries()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the DbImporter package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace DbImporter\QueryBuilder;
12
13
class PgSqlQueryBuilder extends AbstractQueryBuilder
14
{
15
    const MULTIPLE_QUERY_IMPORT_LIMIT = 4000;
16
17
    /**
18
     * @return string
19
     */
20
    private function getQueryHead()
21
    {
22
        $sql = 'INSERT ';
23
24
        $sql .= 'INTO '.$this->table.' (';
25
        $c = 1;
26
        $values = array_keys($this->mapping);
27
28
        foreach ($values as $value) {
29
            $sql .= $value.$this->appendComma($c, $values);
30
            $c++;
31
        }
32
33
        $sql .= ') VALUES ';
34
35
        return $sql;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    private function getQueryTail()
42
    {
43
        return ' ON CONFLICT DO NOTHING';
44
    }
45
46
    /**
47
     * Returns the array of insert queries
48
     * @param string $mode
49
     *
50
     * @return array
51
     */
52
    public function getQueries($mode = 'multiple')
53
    {
54
        $sql = [];
55
56
        foreach ($this->getQueriesBody($mode) as $query) {
57
            $sqlString = $this->getQueryHead().$query;
58
59
            if (true === $this->debug) {
60
                $sqlString .= $this->getQueryTail();
61
            }
62
63
            $sql[] = $sqlString;
64
        }
65
66
        return $sql;
67
    }
68
}
69