|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\QueryBuilder; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
|
8
|
|
|
use Yiisoft\Db\Query\QueryInterface; |
|
9
|
|
|
use Yiisoft\Db\Tests\AbstractQueryBuilderTest; |
|
10
|
|
|
use Yiisoft\Db\Tests\Support\TestTrait; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @group db |
|
14
|
|
|
*/ |
|
15
|
|
|
final class QueryBuilderTest extends AbstractQueryBuilderTest |
|
16
|
|
|
{ |
|
17
|
|
|
use TestTrait; |
|
18
|
|
|
|
|
19
|
|
|
public function testAddDefaultValue(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$db = $this->getConnection(); |
|
22
|
|
|
|
|
23
|
|
|
$qb = $db->getQueryBuilder(); |
|
24
|
|
|
|
|
25
|
|
|
$this->expectException(NotSupportedException::class); |
|
26
|
|
|
$this->expectExceptionMessage( |
|
27
|
|
|
'Yiisoft\Db\QueryBuilder\DDLQueryBuilder::addDefaultValue is not supported by this DBMS.' |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
$qb->addDefaultValue('name', 'table', 'column', 'value'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @dataProvider Yiisoft\Db\Tests\Provider\QueryBuilderProvider::batchInsert() |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testBatchInsert(string $table, array $columns, array $rows, string $expected): void |
|
37
|
|
|
{ |
|
38
|
|
|
$db = $this->getConnection(); |
|
39
|
|
|
|
|
40
|
|
|
$qb = $db->getQueryBuilder(); |
|
41
|
|
|
|
|
42
|
|
|
$this->expectException(NotSupportedException::class); |
|
43
|
|
|
$this->expectExceptionMessage( |
|
44
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableSchema is not supported by this DBMS.' |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$qb->batchInsert('table', ['column1', 'column2'], [['value1', 'value2'], ['value3', 'value4']]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testCheckIntegrity(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$db = $this->getConnection(); |
|
53
|
|
|
|
|
54
|
|
|
$this->expectException(NotSupportedException::class); |
|
55
|
|
|
$this->expectExceptionMessage( |
|
56
|
|
|
'Yiisoft\Db\QueryBuilder\DDLQueryBuilder::checkIntegrity is not supported by this DBMS.' |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$qb = $db->getQueryBuilder(); |
|
60
|
|
|
$qb->checkIntegrity('schema', 'table'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testDropDefaultValue(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$db = $this->getConnection(true); |
|
66
|
|
|
|
|
67
|
|
|
$qb = $db->getQueryBuilder(); |
|
68
|
|
|
|
|
69
|
|
|
$this->expectException(NotSupportedException::class); |
|
70
|
|
|
$this->expectExceptionMessage( |
|
71
|
|
|
'Yiisoft\Db\QueryBuilder\DDLQueryBuilder::dropDefaultValue is not supported by this DBMS.' |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$qb->dropDefaultValue('CN_pk', 'T_constraints_1'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::insert() |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testInsert( |
|
81
|
|
|
string $table, |
|
82
|
|
|
array|QueryInterface $columns, |
|
83
|
|
|
array $params, |
|
84
|
|
|
string $expectedSQL, |
|
85
|
|
|
array $expectedParams |
|
86
|
|
|
): void { |
|
87
|
|
|
$db = $this->getConnection(); |
|
88
|
|
|
|
|
89
|
|
|
$qb = $db->getQueryBuilder(); |
|
90
|
|
|
|
|
91
|
|
|
$this->expectException(NotSupportedException::class); |
|
92
|
|
|
$this->expectExceptionMessage( |
|
93
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableSchema is not supported by this DBMS.' |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$qb->insert($table, $columns, $params); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::insertEx() |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testInsertEx( |
|
103
|
|
|
string $table, |
|
104
|
|
|
array|QueryInterface $columns, |
|
105
|
|
|
array $params, |
|
106
|
|
|
string $expectedSQL, |
|
107
|
|
|
array $expectedParams |
|
108
|
|
|
): void { |
|
109
|
|
|
$db = $this->getConnection(); |
|
110
|
|
|
|
|
111
|
|
|
$qb = $db->getQueryBuilder(); |
|
112
|
|
|
|
|
113
|
|
|
$this->expectException(NotSupportedException::class); |
|
114
|
|
|
$this->expectExceptionMessage( |
|
115
|
|
|
'Yiisoft\Db\QueryBuilder\DMLQueryBuilder::insertEx() is not supported by this DBMS.' |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$qb->insertEx($table, $columns, $params); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testResetSequence(): void |
|
122
|
|
|
{ |
|
123
|
|
|
$db = $this->getConnection(); |
|
124
|
|
|
|
|
125
|
|
|
$qb = $db->getQueryBuilder(); |
|
126
|
|
|
|
|
127
|
|
|
$this->expectException(NotSupportedException::class); |
|
128
|
|
|
$this->expectExceptionMessage( |
|
129
|
|
|
'Yiisoft\Db\QueryBuilder\DMLQueryBuilder::resetSequence() is not supported by this DBMS.' |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
$qb->resetSequence('T_constraints_1', 'id'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::update() |
|
137
|
|
|
*/ |
|
138
|
|
|
public function testUpdate( |
|
139
|
|
|
string $table, |
|
140
|
|
|
array $columns, |
|
141
|
|
|
array|string $condition, |
|
142
|
|
|
string $expectedSQL, |
|
143
|
|
|
array $expectedParams |
|
144
|
|
|
): void { |
|
145
|
|
|
$db = $this->getConnection(); |
|
146
|
|
|
|
|
147
|
|
|
$qb = $db->getQueryBuilder(); |
|
148
|
|
|
$actualParams = []; |
|
149
|
|
|
|
|
150
|
|
|
$this->expectException(NotSupportedException::class); |
|
151
|
|
|
$this->expectExceptionMessage( |
|
152
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableSchema is not supported by this DBMS.' |
|
153
|
|
|
); |
|
154
|
|
|
|
|
155
|
|
|
$qb->update($table, $columns, $condition, $actualParams); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::upsert() |
|
160
|
|
|
* |
|
161
|
|
|
* @throws Exception |
|
162
|
|
|
* @throws JsonException |
|
163
|
|
|
* @throws NotSupportedException |
|
164
|
|
|
*/ |
|
165
|
|
|
public function testUpsert( |
|
166
|
|
|
string $table, |
|
167
|
|
|
array|QueryInterface $insertColumns, |
|
168
|
|
|
array|bool $updateColumns, |
|
169
|
|
|
string|array $expectedSQL, |
|
170
|
|
|
array $expectedParams |
|
171
|
|
|
): void { |
|
172
|
|
|
$db = $this->getConnection(); |
|
173
|
|
|
|
|
174
|
|
|
$actualParams = []; |
|
175
|
|
|
|
|
176
|
|
|
$this->expectException(NotSupportedException::class); |
|
177
|
|
|
$this->expectExceptionMessage( |
|
178
|
|
|
'Yiisoft\Db\QueryBuilder\DMLQueryBuilder::upsert is not supported by this DBMS.' |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
$db->getQueryBuilder()->upsert($table, $insertColumns, $updateColumns, $actualParams); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|