yiisoft /
db-oracle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Yiisoft\Db\Oracle; |
||
| 6 | |||
| 7 | use Throwable; |
||
| 8 | use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; |
||
| 9 | use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
||
| 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 | * Implements a connection to a database via PDO (PHP Data Objects) for Oracle Server. |
||
| 21 | * |
||
| 22 | * @link https://www.php.net/manual/en/ref.pdo-oci.php |
||
| 23 | */ |
||
| 24 | final class Connection extends AbstractPdoConnection |
||
| 25 | { |
||
| 26 | 305 | public function createCommand(string $sql = null, array $params = []): PdoCommandInterface |
|
| 27 | { |
||
| 28 | 305 | $command = new Command($this); |
|
| 29 | |||
| 30 | 305 | if ($sql !== null) { |
|
| 31 | 280 | $command->setSql($sql); |
|
| 32 | } |
||
| 33 | |||
| 34 | 305 | if ($this->logger !== null) { |
|
| 35 | 2 | $command->setLogger($this->logger); |
|
| 36 | } |
||
| 37 | |||
| 38 | 305 | if ($this->profiler !== null) { |
|
| 39 | 3 | $command->setProfiler($this->profiler); |
|
| 40 | } |
||
| 41 | |||
| 42 | 305 | return $command->bindValues($params); |
|
| 43 | } |
||
| 44 | |||
| 45 | 13 | public function createTransaction(): TransactionInterface |
|
| 46 | { |
||
| 47 | 13 | return new Transaction($this); |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Override base behaviour to support Oracle sequences. |
||
| 52 | * |
||
| 53 | * @throws Exception |
||
| 54 | * @throws InvalidConfigException |
||
| 55 | * @throws InvalidCallException |
||
| 56 | * @throws Throwable |
||
| 57 | */ |
||
| 58 | 5 | public function getLastInsertID(string $sequenceName = null): string |
|
| 59 | { |
||
| 60 | 5 | if ($sequenceName === null) { |
|
| 61 | 1 | throw new InvalidArgumentException('Oracle not support lastInsertId without sequence name.'); |
|
| 62 | } |
||
| 63 | |||
| 64 | 4 | if ($this->isActive()) { |
|
| 65 | // get the last insert id from connection |
||
| 66 | 4 | $sequenceName = $this->getQuoter()->quoteSimpleTableName($sequenceName); |
|
| 67 | |||
| 68 | 4 | return (string) $this->createCommand("SELECT $sequenceName.CURRVAL FROM DUAL")->queryScalar(); |
|
| 69 | } |
||
| 70 | |||
| 71 | throw new InvalidCallException('DB Connection is not active.'); |
||
| 72 | } |
||
| 73 | |||
| 74 | 556 | public function getQueryBuilder(): QueryBuilderInterface |
|
| 75 | { |
||
| 76 | 556 | if ($this->queryBuilder === null) { |
|
| 77 | 556 | $this->queryBuilder = new QueryBuilder($this->getQuoter(), $this->getSchema()); |
|
| 78 | } |
||
| 79 | |||
| 80 | 556 | return $this->queryBuilder; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 81 | } |
||
| 82 | |||
| 83 | 618 | public function getQuoter(): QuoterInterface |
|
| 84 | { |
||
| 85 | 618 | if ($this->quoter === null) { |
|
| 86 | 618 | $this->quoter = new Quoter('"', '"', $this->getTablePrefix()); |
|
| 87 | } |
||
| 88 | |||
| 89 | 618 | return $this->quoter; |
|
|
0 ignored issues
–
show
|
|||
| 90 | } |
||
| 91 | |||
| 92 | 580 | public function getSchema(): SchemaInterface |
|
| 93 | { |
||
| 94 | 580 | if ($this->schema === null) { |
|
| 95 | 580 | $this->schema = new Schema($this, $this->schemaCache, strtoupper($this->driver->getUsername())); |
|
| 96 | } |
||
| 97 | |||
| 98 | 580 | return $this->schema; |
|
|
0 ignored issues
–
show
|
|||
| 99 | } |
||
| 100 | } |
||
| 101 |