|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Driver\PDO\AbstractConnectionPDO; |
|
8
|
|
|
use Yiisoft\Db\Driver\PDO\CommandPDOInterface; |
|
9
|
|
|
use Yiisoft\Db\Query\BatchQueryResultInterface; |
|
10
|
|
|
use Yiisoft\Db\Query\QueryInterface; |
|
11
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
|
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 MSSQL Server. |
|
18
|
|
|
* |
|
19
|
|
|
* @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php |
|
20
|
|
|
*/ |
|
21
|
|
|
final class Connection extends AbstractConnectionPDO |
|
22
|
|
|
{ |
|
23
|
4 |
|
public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface |
|
24
|
|
|
{ |
|
25
|
4 |
|
return new BatchQueryResult($query, $each); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
642 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
|
29
|
|
|
{ |
|
30
|
642 |
|
$command = new Command($this); |
|
31
|
|
|
|
|
32
|
642 |
|
if ($sql !== null) { |
|
33
|
614 |
|
$command->setSql($sql); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
642 |
|
if ($this->logger !== null) { |
|
37
|
2 |
|
$command->setLogger($this->logger); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
642 |
|
if ($this->profiler !== null) { |
|
41
|
3 |
|
$command->setProfiler($this->profiler); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
642 |
|
return $command->bindValues($params); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
14 |
|
public function createTransaction(): TransactionInterface |
|
48
|
|
|
{ |
|
49
|
14 |
|
return new Transaction($this); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
880 |
|
public function getQueryBuilder(): QueryBuilderInterface |
|
53
|
|
|
{ |
|
54
|
880 |
|
if ($this->queryBuilder === null) { |
|
55
|
880 |
|
$this->queryBuilder = new QueryBuilder( |
|
56
|
880 |
|
$this->getQuoter(), |
|
57
|
880 |
|
$this->getSchema(), |
|
58
|
880 |
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
880 |
|
return $this->queryBuilder; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
938 |
|
public function getQuoter(): QuoterInterface |
|
65
|
|
|
{ |
|
66
|
938 |
|
if ($this->quoter === null) { |
|
67
|
938 |
|
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
938 |
|
return $this->quoter; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
892 |
|
public function getSchema(): SchemaInterface |
|
74
|
|
|
{ |
|
75
|
892 |
|
if ($this->schema === null) { |
|
76
|
892 |
|
$this->schema = new Schema($this, $this->schemaCache); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
892 |
|
return $this->schema; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Initializes the DB connection. |
|
84
|
|
|
* |
|
85
|
|
|
* This method is invoked right after the DB connection is established. |
|
86
|
|
|
*/ |
|
87
|
631 |
|
protected function initConnection(): void |
|
88
|
|
|
{ |
|
89
|
631 |
|
$this->pdo = $this->driver->createConnection(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|