Passed
Push — binary-fix ( 8471db )
by Def
06:50
created

Connection::createPdoInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle;
6
7
use PDO;
8
use Yiisoft\Db\Connection\Connection as AbstractConnection;
9
use Yiisoft\Db\Cache\QueryCache;
10
use Yiisoft\Db\Cache\SchemaCache;
11
12
/**
13
 * Database connection class prefilled for ORACLE Server.
14
 */
15
final class Connection extends AbstractConnection
16
{
17
    private QueryCache $queryCache;
18
    private SchemaCache $schemaCache;
19
20 386
    public function __construct(string $dsn, QueryCache $queryCache, SchemaCache $schemaCache)
21
    {
22 386
        $this->queryCache = $queryCache;
23 386
        $this->schemaCache = $schemaCache;
24
25 386
        parent::__construct($dsn, $queryCache);
26 386
    }
27
28 168
    public function createCommand(?string $sql = null, array $params = []): Command
29
    {
30 168
        if ($sql !== null) {
31 168
            $sql = $this->quoteSql($sql);
32
        }
33
34 168
        $command = new Command($this, $this->queryCache, $sql);
35
36 168
        if ($this->logger !== null) {
37 168
            $command->setLogger($this->logger);
38
        }
39
40 168
        if ($this->profiler !== null) {
41 168
            $command->setProfiler($this->profiler);
42
        }
43
44 168
        return $command->bindValues($params);
45
    }
46
47
    /**
48
     * Returns the schema information for the database opened by this connection.
49
     *
50
     * @return Schema the schema information for the database opened by this connection.
51
     */
52 312
    public function getSchema(): Schema
53
    {
54 312
        return new Schema($this, $this->schemaCache);
55
    }
56
57 208
    protected function createPdoInstance(): PDO
58
    {
59 208
        return new PDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes());
60
    }
61
62 208
    protected function initConnection(): void
63
    {
64 208
        $pdo = $this->getPDO();
65
66 208
        if ($pdo !== null) {
67 208
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
68
69 208
            if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) {
70
                $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare());
71
            }
72
        }
73 208
    }
74
75
    /**
76
     * Returns the name of the DB driver.
77
     *
78
     * @return string name of the DB driver
79
     */
80 7
    public function getDriverName(): string
81
    {
82 7
        return 'oci';
83
    }
84
}
85