yiisoft /
db-pgsql
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Yiisoft\Db\Pgsql; |
||
| 6 | |||
| 7 | use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; |
||
| 8 | use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
||
| 9 | use Yiisoft\Db\Exception\InvalidArgumentException; |
||
| 10 | use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
||
| 11 | use Yiisoft\Db\Schema\Quoter; |
||
| 12 | use Yiisoft\Db\Schema\QuoterInterface; |
||
| 13 | use Yiisoft\Db\Schema\SchemaInterface; |
||
| 14 | use Yiisoft\Db\Transaction\TransactionInterface; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Implements a connection to a database via PDO (PHP Data Objects) for PostgreSQL Server. |
||
| 18 | * |
||
| 19 | * @link https://www.php.net/manual/en/ref.pdo-pgsql.php |
||
| 20 | */ |
||
| 21 | final class Connection extends AbstractPdoConnection |
||
| 22 | { |
||
| 23 | 310 | public function createCommand(string $sql = null, array $params = []): PdoCommandInterface |
|
| 24 | { |
||
| 25 | 310 | $command = new Command($this); |
|
| 26 | |||
| 27 | 310 | if ($sql !== null) { |
|
| 28 | 284 | $command->setSql($sql); |
|
| 29 | } |
||
| 30 | |||
| 31 | 310 | if ($this->logger !== null) { |
|
| 32 | 2 | $command->setLogger($this->logger); |
|
| 33 | } |
||
| 34 | |||
| 35 | 310 | if ($this->profiler !== null) { |
|
| 36 | 3 | $command->setProfiler($this->profiler); |
|
| 37 | } |
||
| 38 | |||
| 39 | 310 | return $command->bindValues($params); |
|
| 40 | } |
||
| 41 | |||
| 42 | 13 | public function createTransaction(): TransactionInterface |
|
| 43 | { |
||
| 44 | 13 | return new Transaction($this); |
|
| 45 | } |
||
| 46 | |||
| 47 | 4 | public function getLastInsertID(string $sequenceName = null): string |
|
| 48 | { |
||
| 49 | 4 | if ($sequenceName === null) { |
|
| 50 | 1 | throw new InvalidArgumentException('PostgreSQL not support lastInsertId without sequence name.'); |
|
| 51 | } |
||
| 52 | |||
| 53 | 3 | return parent::getLastInsertID($sequenceName); |
|
| 54 | } |
||
| 55 | |||
| 56 | 611 | public function getQueryBuilder(): QueryBuilderInterface |
|
| 57 | { |
||
| 58 | 611 | if ($this->queryBuilder === null) { |
|
| 59 | 611 | $this->queryBuilder = new QueryBuilder( |
|
| 60 | 611 | $this->getQuoter(), |
|
| 61 | 611 | $this->getSchema(), |
|
| 62 | 611 | ); |
|
| 63 | } |
||
| 64 | |||
| 65 | 611 | return $this->queryBuilder; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 66 | } |
||
| 67 | |||
| 68 | 648 | public function getQuoter(): QuoterInterface |
|
| 69 | { |
||
| 70 | 648 | if ($this->quoter === null) { |
|
| 71 | 648 | $this->quoter = new Quoter('"', '"', $this->getTablePrefix()); |
|
| 72 | } |
||
| 73 | |||
| 74 | 648 | return $this->quoter; |
|
|
0 ignored issues
–
show
|
|||
| 75 | } |
||
| 76 | |||
| 77 | 635 | public function getSchema(): SchemaInterface |
|
| 78 | { |
||
| 79 | 635 | if ($this->schema === null) { |
|
| 80 | 635 | $this->schema = new Schema($this, $this->schemaCache); |
|
| 81 | } |
||
| 82 | |||
| 83 | 635 | return $this->schema; |
|
|
0 ignored issues
–
show
|
|||
| 84 | } |
||
| 85 | } |
||
| 86 |