-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathConnection.php
95 lines (78 loc) · 2.74 KB
/
Connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Oracle;
use Throwable;
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Oracle\Column\ColumnFactory;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;
/**
* Implements a connection to a database via PDO (PHP Data Objects) for Oracle Server.
*
* @link https://www.php.net/manual/en/ref.pdo-oci.php
*/
final class Connection extends AbstractPdoConnection
{
public function createCommand(?string $sql = null, array $params = []): PdoCommandInterface
{
$command = new Command($this);
if ($sql !== null) {
$command->setSql($sql);
}
if ($this->logger !== null) {
$command->setLogger($this->logger);
}
if ($this->profiler !== null) {
$command->setProfiler($this->profiler);
}
return $command->bindValues($params);
}
public function createTransaction(): TransactionInterface
{
return new Transaction($this);
}
public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}
/**
* Override base behaviour to support Oracle sequences.
*
* @throws Exception
* @throws InvalidConfigException
* @throws InvalidCallException
* @throws Throwable
*/
public function getLastInsertID(?string $sequenceName = null): string
{
if ($sequenceName === null) {
throw new InvalidArgumentException('Oracle not support lastInsertId without sequence name.');
}
if ($this->isActive()) {
// get the last insert id from connection
$sequenceName = $this->getQuoter()->quoteSimpleTableName($sequenceName);
return (string) $this->createCommand("SELECT $sequenceName.CURRVAL FROM DUAL")->queryScalar();
}
throw new InvalidCallException('DB Connection is not active.');
}
public function getQueryBuilder(): QueryBuilderInterface
{
return $this->queryBuilder ??= new QueryBuilder($this);
}
public function getQuoter(): QuoterInterface
{
return $this->quoter ??= new Quoter('"', '"', $this->getTablePrefix());
}
public function getSchema(): SchemaInterface
{
return $this->schema ??= new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername()));
}
}