|
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
|
239 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
|
26
|
|
|
{ |
|
27
|
239 |
|
$command = new CommandPDO($this, $this->queryCache); |
|
28
|
|
|
|
|
29
|
239 |
|
if ($sql !== null) { |
|
30
|
218 |
|
$command->setSql($sql); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
239 |
|
if ($this->logger !== null) { |
|
34
|
1 |
|
$command->setLogger($this->logger); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
239 |
|
if ($this->profiler !== null) { |
|
38
|
1 |
|
$command->setProfiler($this->profiler); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
239 |
|
return $command->bindValues($params); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
8 |
|
public function createTransaction(): TransactionInterface |
|
45
|
|
|
{ |
|
46
|
8 |
|
return new TransactionPDO($this); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Override base behaviour |
|
51
|
|
|
*/ |
|
52
|
5 |
|
public function getLastInsertID(string $sequenceName = null): string |
|
53
|
|
|
{ |
|
54
|
5 |
|
if ($sequenceName === null) { |
|
55
|
1 |
|
throw new InvalidArgumentException('Oracle not support lastInsertId without sequence name.'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
4 |
|
if ($this->isActive()) { |
|
59
|
|
|
/* get the last insert id from connection */ |
|
60
|
4 |
|
$sequenceName = $this->getQuoter()->quoteSimpleTableName($sequenceName); |
|
61
|
|
|
|
|
62
|
4 |
|
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
|
457 |
|
public function getQueryBuilder(): QueryBuilderInterface |
|
72
|
|
|
{ |
|
73
|
457 |
|
if ($this->queryBuilder === null) { |
|
74
|
457 |
|
$this->queryBuilder = new QueryBuilder( |
|
75
|
457 |
|
$this->getQuoter(), |
|
76
|
457 |
|
$this->getSchema(), |
|
77
|
457 |
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
457 |
|
return $this->queryBuilder; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
512 |
|
public function getQuoter(): QuoterInterface |
|
84
|
|
|
{ |
|
85
|
512 |
|
if ($this->quoter === null) { |
|
86
|
512 |
|
$this->quoter = new Quoter('"', '"', $this->getTablePrefix()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
512 |
|
return $this->quoter; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
482 |
|
public function getSchema(): SchemaInterface |
|
93
|
|
|
{ |
|
94
|
482 |
|
if ($this->schema === null) { |
|
95
|
482 |
|
$this->schema = new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername())); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
482 |
|
return $this->schema; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|