|
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
|
225 |
|
public function createCommand(?string $sql = null, array $params = []): CommandPDOInterface |
|
30
|
|
|
{ |
|
31
|
225 |
|
$command = new CommandPDO($this, $this->queryCache); |
|
32
|
|
|
|
|
33
|
225 |
|
if ($sql !== null) { |
|
34
|
224 |
|
$command->setSql($sql); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
225 |
|
if ($this->logger !== null) { |
|
38
|
225 |
|
$command->setLogger($this->logger); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
225 |
|
if ($this->profiler !== null) { |
|
42
|
225 |
|
$command->setProfiler($this->profiler); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
225 |
|
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
|
386 |
|
public function getQueryBuilder(): QueryBuilderInterface |
|
57
|
|
|
{ |
|
58
|
386 |
|
if ($this->queryBuilder === null) { |
|
59
|
386 |
|
$this->queryBuilder = new QueryBuilder( |
|
60
|
386 |
|
$this->getQuoter(), |
|
61
|
386 |
|
$this->getSchema(), |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
386 |
|
return $this->queryBuilder; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
407 |
|
public function getQuoter(): QuoterInterface |
|
69
|
|
|
{ |
|
70
|
407 |
|
if ($this->quoter === null) { |
|
71
|
407 |
|
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
407 |
|
return $this->quoter; |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
389 |
|
public function getSchema(): SchemaInterface |
|
78
|
|
|
{ |
|
79
|
389 |
|
if ($this->schema === null) { |
|
80
|
389 |
|
$this->schema = new Schema($this, $this->schemaCache); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
389 |
|
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
|
220 |
|
protected function initConnection(): void |
|
98
|
|
|
{ |
|
99
|
220 |
|
$this->pdo = $this->driver->createConnection(); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|