Completed
Push — master ( fb988b...6625be )
by Emmanuel
07:10 queued 05:31
created

PostgreSQL::loadData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 4
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @copyright 2018 Emmanuel Dyan
9
 *
10
 * @package edyan/neuralyzer
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link https://github.com/edyan/neuralyzer
15
 */
16
17
namespace Edyan\Neuralyzer\Helper\DB;
18
19
/**
20
 * Various methods related to PostgreSQL
21
 */
22
class PostgreSQL extends AbstractDBHelper
23
{
24
    /**
25
     * Set the right enclosure
26
     * @return string
27
     */
28 7
    public function getEnclosureForCSV(): string
29
    {
30 7
        return chr(0);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 7
    public function loadData(string $table, string $fname, array $fields, string $mode): string
37
    {
38 7
        $fields = implode(', ', $fields);
39
40 7
        if ($this->pretend === false) {
41 6
            if ($mode === 'update') {
42 4
                $this->conn->query("TRUNCATE {$table}");
43
            }
44 6
            $pdo = $this->conn->getWrappedConnection();
45 6
            $pdo->pgsqlCopyFromFile($table, $fname, '|', '\\\\N', $fields);
46
        }
47
48 6
        $sql = "COPY {$table} ($fields) FROM '{$fname}' ";
49 6
        $sql.= '... Managed by pgsqlCopyFromFile';
50
51 6
        return $sql;
52
    }
53
}
54