1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Oracle; |
6
|
|
|
|
7
|
|
|
use PDO; |
8
|
|
|
use Yiisoft\Db\Driver\PDO\CommandPDOInterface; |
9
|
|
|
use Yiisoft\Db\Driver\PDO\ConnectionPDO as AbstractConnectionPDO; |
10
|
|
|
use Yiisoft\Db\Exception\Exception; |
11
|
|
|
use Yiisoft\Db\Exception\InvalidArgumentException; |
12
|
|
|
use Yiisoft\Db\Exception\InvalidCallException; |
13
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
14
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
15
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
16
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
17
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Database connection class prefilled for Oracle SQL Server. |
21
|
|
|
* The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php). |
22
|
|
|
*/ |
23
|
|
|
final class ConnectionPDO extends AbstractConnectionPDO |
24
|
|
|
{ |
25
|
244 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
26
|
|
|
{ |
27
|
244 |
|
$command = new CommandPDO($this, $this->queryCache); |
28
|
|
|
|
29
|
244 |
|
if ($sql !== null) { |
30
|
223 |
|
$command->setSql($sql); |
31
|
|
|
} |
32
|
|
|
|
33
|
244 |
|
if ($this->logger !== null) { |
34
|
22 |
|
$command->setLogger($this->logger); |
35
|
|
|
} |
36
|
|
|
|
37
|
244 |
|
if ($this->profiler !== null) { |
38
|
22 |
|
$command->setProfiler($this->profiler); |
39
|
|
|
} |
40
|
|
|
|
41
|
244 |
|
return $command->bindValues($params); |
42
|
|
|
} |
43
|
|
|
|
44
|
12 |
|
public function createTransaction(): TransactionInterface |
45
|
|
|
{ |
46
|
12 |
|
return new TransactionPDO($this); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Override base behaviour |
51
|
|
|
*/ |
52
|
3 |
|
public function getLastInsertID(string $sequenceName = null): string |
53
|
|
|
{ |
54
|
3 |
|
if ($sequenceName === null) { |
55
|
|
|
throw new InvalidArgumentException('Oracle not support lastInsertId without sequence name'); |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
if ($this->isActive()) { |
59
|
|
|
/* get the last insert id from connection */ |
60
|
3 |
|
$sequenceName = $this->getQuoter()->quoteSimpleTableName($sequenceName); |
61
|
|
|
|
62
|
3 |
|
return (string) $this->createCommand("SELECT $sequenceName.CURRVAL FROM DUAL")->queryScalar(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
throw new InvalidCallException('DB Connection is not active.'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws Exception|InvalidConfigException |
70
|
|
|
*/ |
71
|
462 |
|
public function getQueryBuilder(): QueryBuilderInterface |
72
|
|
|
{ |
73
|
462 |
|
if ($this->queryBuilder === null) { |
74
|
462 |
|
$this->queryBuilder = new QueryBuilder( |
75
|
462 |
|
$this->getQuoter(), |
76
|
462 |
|
$this->getSchema(), |
77
|
462 |
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
462 |
|
return $this->queryBuilder; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
497 |
|
public function getQuoter(): QuoterInterface |
84
|
|
|
{ |
85
|
497 |
|
if ($this->quoter === null) { |
86
|
497 |
|
$this->quoter = new Quoter('"', '"', $this->getTablePrefix()); |
87
|
|
|
} |
88
|
|
|
|
89
|
497 |
|
return $this->quoter; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
487 |
|
public function getSchema(): SchemaInterface |
93
|
|
|
{ |
94
|
487 |
|
if ($this->schema === null) { |
95
|
487 |
|
$this->schema = new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername())); |
96
|
|
|
} |
97
|
|
|
|
98
|
487 |
|
return $this->schema; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|