|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; |
|
8
|
|
|
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
|
9
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
|
10
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
|
11
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
|
12
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Implements a connection to a database via PDO (PHP Data Objects) for MSSQL Server. |
|
16
|
|
|
* |
|
17
|
|
|
* @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php |
|
18
|
|
|
*/ |
|
19
|
|
|
final class Connection extends AbstractPdoConnection |
|
20
|
|
|
{ |
|
21
|
673 |
|
public function createCommand(string $sql = null, array $params = []): PdoCommandInterface |
|
22
|
|
|
{ |
|
23
|
673 |
|
$command = new Command($this); |
|
24
|
|
|
|
|
25
|
673 |
|
if ($sql !== null) { |
|
26
|
614 |
|
$command->setSql($sql); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
673 |
|
if ($this->logger !== null) { |
|
30
|
2 |
|
$command->setLogger($this->logger); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
673 |
|
if ($this->profiler !== null) { |
|
34
|
3 |
|
$command->setProfiler($this->profiler); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
673 |
|
return $command->bindValues($params); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
14 |
|
public function createTransaction(): TransactionInterface |
|
41
|
|
|
{ |
|
42
|
14 |
|
return new Transaction($this); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
920 |
|
public function getQueryBuilder(): QueryBuilderInterface |
|
46
|
|
|
{ |
|
47
|
920 |
|
if ($this->queryBuilder === null) { |
|
48
|
920 |
|
$this->queryBuilder = new QueryBuilder( |
|
49
|
920 |
|
$this->getQuoter(), |
|
50
|
920 |
|
$this->getSchema(), |
|
51
|
920 |
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
920 |
|
return $this->queryBuilder; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
985 |
|
public function getQuoter(): QuoterInterface |
|
58
|
|
|
{ |
|
59
|
985 |
|
if ($this->quoter === null) { |
|
60
|
985 |
|
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
985 |
|
return $this->quoter; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
931 |
|
public function getSchema(): SchemaInterface |
|
67
|
|
|
{ |
|
68
|
931 |
|
if ($this->schema === null) { |
|
69
|
931 |
|
$this->schema = new Schema($this, $this->schemaCache); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
931 |
|
return $this->schema; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Initializes the DB connection. |
|
77
|
|
|
* |
|
78
|
|
|
* This method is invoked right after the DB connection is established. |
|
79
|
|
|
*/ |
|
80
|
661 |
|
protected function initConnection(): void |
|
81
|
|
|
{ |
|
82
|
661 |
|
$this->pdo = $this->driver->createConnection(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|