SqliteQueryBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getQueryHead() 0 21 3
A getQueries() 0 9 2
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 SqliteQueryBuilder extends AbstractQueryBuilder
14
{
15
    const MULTIPLE_QUERY_IMPORT_LIMIT = 100;
16
17
    /**
18
     * @return string
19
     */
20
    private function getQueryHead()
21
    {
22
        $sql = 'INSERT ';
23
24
        if (true === $this->debug) {
25
            $sql .= 'OR IGNORE ';
26
        }
27
28
        $sql .= 'INTO `'.$this->table.'` (';
29
        $c = 1;
30
        $values = array_keys($this->mapping);
31
32
        foreach ($values as $value) {
33
            $sql .= '`'.$value.'`';
34
            $sql .= $this->appendComma($c, $values);
35
            $c++;
36
        }
37
38
        $sql .= ') VALUES ';
39
40
        return $sql;
41
    }
42
43
    /**
44
     * Returns the array of insert queries
45
     * @param string $mode
46
     *
47
     * @return array
48
     */
49
    public function getQueries($mode = 'multiple')
50
    {
51
        $sql = [];
52
53
        foreach ($this->getQueriesBody($mode, self::MULTIPLE_QUERY_IMPORT_LIMIT) as $query) {
54
            $sql[] = $this->getQueryHead().$query;
55
        }
56
57
        return $sql;
58
    }
59
}
60