1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Driver\PDO\CommandPDOInterface; |
8
|
|
|
use Yiisoft\Db\Driver\PDO\ConnectionPDO as AbstractConnectionPDO; |
9
|
|
|
use Yiisoft\Db\Exception\Exception; |
10
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
11
|
|
|
use Yiisoft\Db\Query\BatchQueryResultInterface; |
12
|
|
|
use Yiisoft\Db\Query\QueryInterface; |
13
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
14
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
15
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
16
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Database connection class prefilled for Microsoft SQL Server. |
20
|
|
|
* The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php). |
21
|
|
|
*/ |
22
|
|
|
final class ConnectionPDO extends AbstractConnectionPDO |
23
|
|
|
{ |
24
|
3 |
|
public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface |
25
|
|
|
{ |
26
|
3 |
|
return new BatchQueryResult($query, $each); |
27
|
|
|
} |
28
|
|
|
|
29
|
223 |
|
public function createCommand(?string $sql = null, array $params = []): CommandPDOInterface |
30
|
|
|
{ |
31
|
223 |
|
$command = new CommandPDO($this, $this->queryCache); |
32
|
|
|
|
33
|
223 |
|
if ($sql !== null) { |
34
|
223 |
|
$command->setSql($sql); |
35
|
|
|
} |
36
|
|
|
|
37
|
223 |
|
if ($this->logger !== null) { |
38
|
223 |
|
$command->setLogger($this->logger); |
39
|
|
|
} |
40
|
|
|
|
41
|
223 |
|
if ($this->profiler !== null) { |
42
|
223 |
|
$command->setProfiler($this->profiler); |
43
|
|
|
} |
44
|
|
|
|
45
|
223 |
|
return $command->bindValues($params); |
46
|
|
|
} |
47
|
|
|
|
48
|
11 |
|
public function createTransaction(): TransactionInterface |
49
|
|
|
{ |
50
|
11 |
|
return new TransactionPDO($this); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @throws Exception|InvalidConfigException |
55
|
|
|
*/ |
56
|
385 |
|
public function getQueryBuilder(): QueryBuilderInterface |
57
|
|
|
{ |
58
|
385 |
|
if ($this->queryBuilder === null) { |
59
|
385 |
|
$this->queryBuilder = new QueryBuilder( |
60
|
385 |
|
$this->getQuoter(), |
61
|
385 |
|
$this->getSchema(), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
385 |
|
return $this->queryBuilder; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
406 |
|
public function getQuoter(): QuoterInterface |
69
|
|
|
{ |
70
|
406 |
|
if ($this->quoter === null) { |
71
|
406 |
|
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
72
|
|
|
} |
73
|
|
|
|
74
|
406 |
|
return $this->quoter; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
387 |
|
public function getSchema(): SchemaInterface |
78
|
|
|
{ |
79
|
387 |
|
if ($this->schema === null) { |
80
|
387 |
|
$this->schema = new Schema($this, $this->schemaCache); |
81
|
|
|
} |
82
|
|
|
|
83
|
387 |
|
return $this->schema; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Initializes the DB connection. |
88
|
|
|
* |
89
|
|
|
* This method is invoked right after the DB connection is established. |
90
|
|
|
* |
91
|
|
|
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`. |
92
|
|
|
* |
93
|
|
|
* if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty. |
94
|
|
|
* |
95
|
|
|
* It then triggers an {@see EVENT_AFTER_OPEN} event. |
96
|
|
|
*/ |
97
|
219 |
|
protected function initConnection(): void |
98
|
|
|
{ |
99
|
219 |
|
$this->pdo = $this->driver->createConnection(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|