|
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
|
|
|
public function __construct(string $dsn, QueryCache $queryCache, SchemaCache $schemaCache) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->queryCache = $queryCache; |
|
23
|
|
|
$this->schemaCache = $schemaCache; |
|
24
|
|
|
|
|
25
|
|
|
parent::__construct($dsn, $queryCache); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function createCommand(?string $sql = null, array $params = []): Command |
|
29
|
|
|
{ |
|
30
|
|
|
if ($sql !== null) { |
|
31
|
|
|
$sql = $this->quoteSql($sql); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$command = new Command($this, $this->queryCache, $sql); |
|
35
|
|
|
|
|
36
|
|
|
if ($this->logger !== null) { |
|
37
|
|
|
$command->setLogger($this->logger); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ($this->profiler !== null) { |
|
41
|
|
|
$command->setProfiler($this->profiler); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
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
|
|
|
public function getSchema(): Schema |
|
53
|
|
|
{ |
|
54
|
|
|
return new Schema($this, $this->schemaCache); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function createPdoInstance(): PDO |
|
58
|
|
|
{ |
|
59
|
|
|
return new PDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function initConnection(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$pdo = $this->getPDO(); |
|
65
|
|
|
|
|
66
|
|
|
if ($pdo !== null) { |
|
67
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
68
|
|
|
|
|
69
|
|
|
if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) { |
|
70
|
|
|
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare()); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the name of the DB driver. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string name of the DB driver |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getDriverName(): string |
|
81
|
|
|
{ |
|
82
|
|
|
return 'oci'; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|