1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Column; |
6
|
|
|
use Doctrine\DBAL\Schema\ColumnDiff; |
7
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
8
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
9
|
|
|
use Doctrine\DBAL\Schema\Sequence; |
10
|
|
|
use Doctrine\DBAL\Schema\Table; |
11
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
12
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel; |
13
|
|
|
use Doctrine\DBAL\Types\Type; |
14
|
|
|
use UnexpectedValueException; |
15
|
|
|
use function sprintf; |
16
|
|
|
|
17
|
|
|
abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase |
18
|
|
|
{ |
19
|
|
|
public function getGenerateTableSql() : string |
20
|
|
|
{ |
21
|
|
|
return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
*/ |
27
|
|
|
public function getGenerateTableWithMultiColumnUniqueIndexSql() : array |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', |
31
|
|
|
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
*/ |
38
|
|
|
public function getGenerateAlterTableSql() : array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
'ALTER TABLE mytable ADD quota INT DEFAULT NULL', |
42
|
|
|
'ALTER TABLE mytable DROP foo', |
43
|
|
|
'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)', |
44
|
|
|
"ALTER TABLE mytable ALTER bar SET DEFAULT 'def'", |
45
|
|
|
'ALTER TABLE mytable ALTER bar SET NOT NULL', |
46
|
|
|
'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN', |
47
|
|
|
"ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'", |
48
|
|
|
'ALTER TABLE mytable ALTER bloo SET NOT NULL', |
49
|
|
|
'ALTER TABLE mytable RENAME TO userlist', |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getGenerateIndexSql() : string |
54
|
|
|
{ |
55
|
|
|
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getGenerateForeignKeySql() : string |
59
|
|
|
{ |
60
|
|
|
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSupportsTruncateMultiTable() : void |
64
|
|
|
{ |
65
|
|
|
self::assertTrue($this->platform->supportsTruncateMultiTable()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGeneratesForeignKeySqlForNonStandardOptions() : void |
69
|
|
|
{ |
70
|
|
|
$foreignKey = new ForeignKeyConstraint( |
71
|
|
|
['foreign_id'], |
72
|
|
|
'my_table', |
73
|
|
|
['id'], |
74
|
|
|
'my_fk', |
75
|
|
|
['onDelete' => 'CASCADE'] |
76
|
|
|
); |
77
|
|
|
self::assertEquals( |
78
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE', |
79
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$foreignKey = new ForeignKeyConstraint( |
83
|
|
|
['foreign_id'], |
84
|
|
|
'my_table', |
85
|
|
|
['id'], |
86
|
|
|
'my_fk', |
87
|
|
|
['match' => 'full'] |
88
|
|
|
); |
89
|
|
|
self::assertEquals( |
90
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE', |
91
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$foreignKey = new ForeignKeyConstraint( |
95
|
|
|
['foreign_id'], |
96
|
|
|
'my_table', |
97
|
|
|
['id'], |
98
|
|
|
'my_fk', |
99
|
|
|
['deferrable' => true] |
100
|
|
|
); |
101
|
|
|
self::assertEquals( |
102
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE', |
103
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$foreignKey = new ForeignKeyConstraint( |
107
|
|
|
['foreign_id'], |
108
|
|
|
'my_table', |
109
|
|
|
['id'], |
110
|
|
|
'my_fk', |
111
|
|
|
['deferred' => true] |
112
|
|
|
); |
113
|
|
|
self::assertEquals( |
114
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', |
115
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$foreignKey = new ForeignKeyConstraint( |
119
|
|
|
['foreign_id'], |
120
|
|
|
'my_table', |
121
|
|
|
['id'], |
122
|
|
|
'my_fk', |
123
|
|
|
['feferred' => true] |
124
|
|
|
); |
125
|
|
|
self::assertEquals( |
126
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', |
127
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$foreignKey = new ForeignKeyConstraint( |
131
|
|
|
['foreign_id'], |
132
|
|
|
'my_table', |
133
|
|
|
['id'], |
134
|
|
|
'my_fk', |
135
|
|
|
['deferrable' => true, 'deferred' => true, 'match' => 'full'] |
136
|
|
|
); |
137
|
|
|
self::assertEquals( |
138
|
|
|
'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED', |
139
|
|
|
$this->platform->getForeignKeyDeclarationSQL($foreignKey) |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testGeneratesSqlSnippets() : void |
144
|
|
|
{ |
145
|
|
|
self::assertEquals('SIMILAR TO', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); |
146
|
|
|
self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct'); |
147
|
|
|
self::assertEquals('column1 || column2 || column3', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct'); |
148
|
|
|
self::assertEquals('SUBSTRING(column FROM 5)', $this->platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); |
149
|
|
|
self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->platform->getSubstringExpression('column', 1, 5), 'Substring expression with length is not correct'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testGeneratesTransactionCommands() : void |
153
|
|
|
{ |
154
|
|
|
self::assertEquals( |
155
|
|
|
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', |
156
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) |
157
|
|
|
); |
158
|
|
|
self::assertEquals( |
159
|
|
|
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED', |
160
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) |
161
|
|
|
); |
162
|
|
|
self::assertEquals( |
163
|
|
|
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ', |
164
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) |
165
|
|
|
); |
166
|
|
|
self::assertEquals( |
167
|
|
|
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE', |
168
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testGeneratesDDLSnippets() : void |
173
|
|
|
{ |
174
|
|
|
self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); |
175
|
|
|
self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); |
176
|
|
|
self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function testGenerateTableWithAutoincrement() : void |
180
|
|
|
{ |
181
|
|
|
$table = new Table('autoinc_table'); |
182
|
|
|
$column = $table->addColumn('id', 'integer'); |
183
|
|
|
$column->setAutoincrement(true); |
184
|
|
|
|
185
|
|
|
self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->platform->getCreateTableSQL($table)); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return mixed[][] |
190
|
|
|
*/ |
191
|
|
|
public static function serialTypes() : iterable |
192
|
|
|
{ |
193
|
|
|
return [ |
194
|
|
|
['integer', 'SERIAL'], |
195
|
|
|
['bigint', 'BIGSERIAL'], |
196
|
|
|
]; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @dataProvider serialTypes |
201
|
|
|
* @group 2906 |
202
|
|
|
*/ |
203
|
|
|
public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type, string $definition) : void |
204
|
|
|
{ |
205
|
|
|
$table = new Table('autoinc_table_notnull'); |
206
|
|
|
$column = $table->addColumn('id', $type); |
207
|
|
|
$column->setAutoIncrement(true); |
208
|
|
|
$column->setNotNull(false); |
209
|
|
|
|
210
|
|
|
$sql = $this->platform->getCreateTableSQL($table); |
211
|
|
|
|
212
|
|
|
self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull (id %s)', $definition)], $sql); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @dataProvider serialTypes |
217
|
|
|
* @group 2906 |
218
|
|
|
*/ |
219
|
|
|
public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string $type, string $definition) : void |
220
|
|
|
{ |
221
|
|
|
$table = new Table('autoinc_table_notnull_enabled'); |
222
|
|
|
$column = $table->addColumn('id', $type); |
223
|
|
|
$column->setAutoIncrement(true); |
224
|
|
|
$column->setNotNull(true); |
225
|
|
|
|
226
|
|
|
$sql = $this->platform->getCreateTableSQL($table); |
227
|
|
|
|
228
|
|
|
self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull_enabled (id %s NOT NULL)', $definition)], $sql); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @dataProvider serialTypes |
233
|
|
|
* @group 2906 |
234
|
|
|
*/ |
235
|
|
|
public function testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFieldIsSerial(string $type) : void |
236
|
|
|
{ |
237
|
|
|
$sql = $this->platform->getDefaultValueDeclarationSQL( |
238
|
|
|
[ |
239
|
|
|
'autoincrement' => true, |
240
|
|
|
'type' => Type::getType($type), |
241
|
|
|
'default' => 1, |
242
|
|
|
] |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
self::assertSame('', $sql); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testGeneratesTypeDeclarationForIntegers() : void |
249
|
|
|
{ |
250
|
|
|
self::assertEquals( |
251
|
|
|
'INT', |
252
|
|
|
$this->platform->getIntegerTypeDeclarationSQL([]) |
253
|
|
|
); |
254
|
|
|
self::assertEquals( |
255
|
|
|
'SERIAL', |
256
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) |
257
|
|
|
); |
258
|
|
|
self::assertEquals( |
259
|
|
|
'SERIAL', |
260
|
|
|
$this->platform->getIntegerTypeDeclarationSQL( |
261
|
|
|
['autoincrement' => true, 'primary' => true] |
262
|
|
|
) |
263
|
|
|
); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
public function testGeneratesTypeDeclarationForStrings() : void |
267
|
|
|
{ |
268
|
|
|
self::assertEquals( |
269
|
|
|
'CHAR(10)', |
270
|
|
|
$this->platform->getVarcharTypeDeclarationSQL( |
271
|
|
|
['length' => 10, 'fixed' => true] |
272
|
|
|
) |
273
|
|
|
); |
274
|
|
|
self::assertEquals( |
275
|
|
|
'VARCHAR(50)', |
276
|
|
|
$this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), |
277
|
|
|
'Variable string declaration is not correct' |
278
|
|
|
); |
279
|
|
|
self::assertEquals( |
280
|
|
|
'VARCHAR(255)', |
281
|
|
|
$this->platform->getVarcharTypeDeclarationSQL([]), |
282
|
|
|
'Long string declaration is not correct' |
283
|
|
|
); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
public function getGenerateUniqueIndexSql() : string |
287
|
|
|
{ |
288
|
|
|
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function testGeneratesSequenceSqlCommands() : void |
292
|
|
|
{ |
293
|
|
|
$sequence = new Sequence('myseq', 20, 1); |
294
|
|
|
self::assertEquals( |
295
|
|
|
'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1', |
296
|
|
|
$this->platform->getCreateSequenceSQL($sequence) |
297
|
|
|
); |
298
|
|
|
self::assertEquals( |
299
|
|
|
'DROP SEQUENCE myseq CASCADE', |
300
|
|
|
$this->platform->getDropSequenceSQL('myseq') |
301
|
|
|
); |
302
|
|
|
self::assertEquals( |
303
|
|
|
"SELECT NEXTVAL('myseq')", |
304
|
|
|
$this->platform->getSequenceNextValSQL('myseq') |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
public function testDoesNotPreferIdentityColumns() : void |
309
|
|
|
{ |
310
|
|
|
self::assertFalse($this->platform->prefersIdentityColumns()); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function testPrefersSequences() : void |
314
|
|
|
{ |
315
|
|
|
self::assertTrue($this->platform->prefersSequences()); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function testSupportsIdentityColumns() : void |
319
|
|
|
{ |
320
|
|
|
self::assertTrue($this->platform->supportsIdentityColumns()); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
public function testSupportsSavePoints() : void |
324
|
|
|
{ |
325
|
|
|
self::assertTrue($this->platform->supportsSavepoints()); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
public function testSupportsSequences() : void |
329
|
|
|
{ |
330
|
|
|
self::assertTrue($this->platform->supportsSequences()); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* {@inheritdoc} |
335
|
|
|
*/ |
336
|
|
|
protected function supportsCommentOnStatement() : bool |
337
|
|
|
{ |
338
|
|
|
return true; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function testModifyLimitQuery() : void |
342
|
|
|
{ |
343
|
|
|
$sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); |
344
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
public function testModifyLimitQueryWithEmptyOffset() : void |
348
|
|
|
{ |
349
|
|
|
$sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); |
350
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* {@inheritDoc} |
355
|
|
|
*/ |
356
|
|
|
public function getCreateTableColumnCommentsSQL() : array |
357
|
|
|
{ |
358
|
|
|
return [ |
359
|
|
|
'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))', |
360
|
|
|
"COMMENT ON COLUMN test.id IS 'This is a comment'", |
361
|
|
|
]; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* {@inheritDoc} |
366
|
|
|
*/ |
367
|
|
|
public function getAlterTableColumnCommentsSQL() : array |
368
|
|
|
{ |
369
|
|
|
return [ |
370
|
|
|
'ALTER TABLE mytable ADD quota INT NOT NULL', |
371
|
|
|
"COMMENT ON COLUMN mytable.quota IS 'A comment'", |
372
|
|
|
'COMMENT ON COLUMN mytable.foo IS NULL', |
373
|
|
|
"COMMENT ON COLUMN mytable.baz IS 'B comment'", |
374
|
|
|
]; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* {@inheritDoc} |
379
|
|
|
*/ |
380
|
|
|
public function getCreateTableColumnTypeCommentsSQL() : array |
381
|
|
|
{ |
382
|
|
|
return [ |
383
|
|
|
'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))', |
384
|
|
|
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'", |
385
|
|
|
]; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* {@inheritDoc} |
390
|
|
|
*/ |
391
|
|
|
protected function getQuotedColumnInPrimaryKeySQL() : array |
392
|
|
|
{ |
393
|
|
|
return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* {@inheritDoc} |
398
|
|
|
*/ |
399
|
|
|
protected function getQuotedColumnInIndexSQL() : array |
400
|
|
|
{ |
401
|
|
|
return [ |
402
|
|
|
'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', |
403
|
|
|
'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', |
404
|
|
|
]; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* {@inheritDoc} |
409
|
|
|
*/ |
410
|
|
|
protected function getQuotedNameInIndexSQL() : array |
411
|
|
|
{ |
412
|
|
|
return [ |
413
|
|
|
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', |
414
|
|
|
'CREATE INDEX "key" ON test (column1)', |
415
|
|
|
]; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* {@inheritDoc} |
420
|
|
|
*/ |
421
|
|
|
protected function getQuotedColumnInForeignKeySQL() : array |
422
|
|
|
{ |
423
|
|
|
return [ |
424
|
|
|
'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', |
425
|
|
|
'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', |
426
|
|
|
'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', |
427
|
|
|
'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', |
428
|
|
|
]; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @param string|bool $databaseValue |
433
|
|
|
* |
434
|
|
|
* @group DBAL-457 |
435
|
|
|
* @dataProvider pgBooleanProvider |
436
|
|
|
*/ |
437
|
|
|
public function testConvertBooleanAsLiteralStrings( |
438
|
|
|
$databaseValue, |
439
|
|
|
string $preparedStatementValue, |
440
|
|
|
?int $integerValue, |
|
|
|
|
441
|
|
|
?bool $booleanValue |
|
|
|
|
442
|
|
|
) : void { |
443
|
|
|
$platform = $this->createPlatform(); |
444
|
|
|
|
445
|
|
|
self::assertEquals($preparedStatementValue, $platform->convertBooleans($databaseValue)); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @group DBAL-457 |
450
|
|
|
*/ |
451
|
|
|
public function testConvertBooleanAsLiteralIntegers() : void |
452
|
|
|
{ |
453
|
|
|
$platform = $this->createPlatform(); |
454
|
|
|
$platform->setUseBooleanTrueFalseStrings(false); |
|
|
|
|
455
|
|
|
|
456
|
|
|
self::assertEquals(1, $platform->convertBooleans(true)); |
457
|
|
|
self::assertEquals(1, $platform->convertBooleans('1')); |
458
|
|
|
|
459
|
|
|
self::assertEquals(0, $platform->convertBooleans(false)); |
460
|
|
|
self::assertEquals(0, $platform->convertBooleans('0')); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @param string|bool $databaseValue |
465
|
|
|
* |
466
|
|
|
* @group DBAL-630 |
467
|
|
|
* @dataProvider pgBooleanProvider |
468
|
|
|
*/ |
469
|
|
|
public function testConvertBooleanAsDatabaseValueStrings( |
470
|
|
|
$databaseValue, |
|
|
|
|
471
|
|
|
string $preparedStatementValue, |
|
|
|
|
472
|
|
|
?int $integerValue, |
473
|
|
|
?bool $booleanValue |
474
|
|
|
) : void { |
475
|
|
|
$platform = $this->createPlatform(); |
476
|
|
|
|
477
|
|
|
self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue)); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* @group DBAL-630 |
482
|
|
|
*/ |
483
|
|
|
public function testConvertBooleanAsDatabaseValueIntegers() : void |
484
|
|
|
{ |
485
|
|
|
$platform = $this->createPlatform(); |
486
|
|
|
$platform->setUseBooleanTrueFalseStrings(false); |
487
|
|
|
|
488
|
|
|
self::assertSame(1, $platform->convertBooleansToDatabaseValue(true)); |
489
|
|
|
self::assertSame(0, $platform->convertBooleansToDatabaseValue(false)); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* @param string|bool $databaseValue |
494
|
|
|
* |
495
|
|
|
* @dataProvider pgBooleanProvider |
496
|
|
|
*/ |
497
|
|
|
public function testConvertFromBoolean($databaseValue, string $prepareStatementValue, ?int $integerValue, ?bool $booleanValue) : void |
|
|
|
|
498
|
|
|
{ |
499
|
|
|
$platform = $this->createPlatform(); |
500
|
|
|
|
501
|
|
|
self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue)); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testThrowsExceptionWithInvalidBooleanLiteral() : void |
505
|
|
|
{ |
506
|
|
|
$platform = $this->createPlatform(); |
507
|
|
|
|
508
|
|
|
$this->expectException(UnexpectedValueException::class); |
509
|
|
|
$this->expectExceptionMessage("Unrecognized boolean literal 'my-bool'"); |
510
|
|
|
|
511
|
|
|
$platform->convertBooleansToDatabaseValue('my-bool'); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
public function testGetCreateSchemaSQL() : void |
515
|
|
|
{ |
516
|
|
|
$schemaName = 'schema'; |
517
|
|
|
$sql = $this->platform->getCreateSchemaSQL($schemaName); |
518
|
|
|
self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
public function testAlterDecimalPrecisionScale() : void |
522
|
|
|
{ |
523
|
|
|
$table = new Table('mytable'); |
524
|
|
|
$table->addColumn('dfoo1', 'decimal'); |
525
|
|
|
$table->addColumn('dfoo2', 'decimal', ['precision' => 10, 'scale' => 6]); |
526
|
|
|
$table->addColumn('dfoo3', 'decimal', ['precision' => 10, 'scale' => 6]); |
527
|
|
|
$table->addColumn('dfoo4', 'decimal', ['precision' => 10, 'scale' => 6]); |
528
|
|
|
|
529
|
|
|
$tableDiff = new TableDiff('mytable'); |
530
|
|
|
$tableDiff->fromTable = $table; |
531
|
|
|
|
532
|
|
|
$tableDiff->changedColumns['dloo1'] = new ColumnDiff( |
533
|
|
|
'dloo1', |
534
|
|
|
new Column( |
535
|
|
|
'dloo1', |
536
|
|
|
Type::getType('decimal'), |
537
|
|
|
['precision' => 16, 'scale' => 6] |
538
|
|
|
), |
539
|
|
|
['precision'] |
540
|
|
|
); |
541
|
|
|
$tableDiff->changedColumns['dloo2'] = new ColumnDiff( |
542
|
|
|
'dloo2', |
543
|
|
|
new Column( |
544
|
|
|
'dloo2', |
545
|
|
|
Type::getType('decimal'), |
546
|
|
|
['precision' => 10, 'scale' => 4] |
547
|
|
|
), |
548
|
|
|
['scale'] |
549
|
|
|
); |
550
|
|
|
$tableDiff->changedColumns['dloo3'] = new ColumnDiff( |
551
|
|
|
'dloo3', |
552
|
|
|
new Column( |
553
|
|
|
'dloo3', |
554
|
|
|
Type::getType('decimal'), |
555
|
|
|
['precision' => 10, 'scale' => 6] |
556
|
|
|
), |
557
|
|
|
[] |
558
|
|
|
); |
559
|
|
|
$tableDiff->changedColumns['dloo4'] = new ColumnDiff( |
560
|
|
|
'dloo4', |
561
|
|
|
new Column( |
562
|
|
|
'dloo4', |
563
|
|
|
Type::getType('decimal'), |
564
|
|
|
['precision' => 16, 'scale' => 8] |
565
|
|
|
), |
566
|
|
|
['precision', 'scale'] |
567
|
|
|
); |
568
|
|
|
|
569
|
|
|
$sql = $this->platform->getAlterTableSQL($tableDiff); |
570
|
|
|
|
571
|
|
|
$expectedSql = [ |
572
|
|
|
'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)', |
573
|
|
|
'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)', |
574
|
|
|
'ALTER TABLE mytable ALTER dloo4 TYPE NUMERIC(16, 8)', |
575
|
|
|
]; |
576
|
|
|
|
577
|
|
|
self::assertEquals($expectedSql, $sql); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* @group DBAL-365 |
582
|
|
|
*/ |
583
|
|
|
public function testDroppingConstraintsBeforeColumns() : void |
584
|
|
|
{ |
585
|
|
|
$newTable = new Table('mytable'); |
586
|
|
|
$newTable->addColumn('id', 'integer'); |
587
|
|
|
$newTable->setPrimaryKey(['id']); |
588
|
|
|
|
589
|
|
|
$oldTable = clone $newTable; |
590
|
|
|
$oldTable->addColumn('parent_id', 'integer'); |
591
|
|
|
$oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); |
|
|
|
|
592
|
|
|
|
593
|
|
|
$comparator = new Comparator(); |
594
|
|
|
$tableDiff = $comparator->diffTable($oldTable, $newTable); |
595
|
|
|
|
596
|
|
|
$sql = $this->platform->getAlterTableSQL($tableDiff); |
|
|
|
|
597
|
|
|
|
598
|
|
|
$expectedSql = [ |
599
|
|
|
'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', |
600
|
|
|
'DROP INDEX IDX_6B2BD609727ACA70', |
601
|
|
|
'ALTER TABLE mytable DROP parent_id', |
602
|
|
|
]; |
603
|
|
|
|
604
|
|
|
self::assertEquals($expectedSql, $sql); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* @group DBAL-563 |
609
|
|
|
*/ |
610
|
|
|
public function testUsesSequenceEmulatedIdentityColumns() : void |
611
|
|
|
{ |
612
|
|
|
self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns()); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* @group DBAL-563 |
617
|
|
|
*/ |
618
|
|
|
public function testReturnsIdentitySequenceName() : void |
619
|
|
|
{ |
620
|
|
|
self::assertSame('mytable_mycolumn_seq', $this->platform->getIdentitySequenceName('mytable', 'mycolumn')); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* @dataProvider dataCreateSequenceWithCache |
625
|
|
|
* @group DBAL-139 |
626
|
|
|
*/ |
627
|
|
|
public function testCreateSequenceWithCache(int $cacheSize, string $expectedSql) : void |
628
|
|
|
{ |
629
|
|
|
$sequence = new Sequence('foo', 1, 1, $cacheSize); |
630
|
|
|
self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* @return mixed[][] |
635
|
|
|
*/ |
636
|
|
|
public static function dataCreateSequenceWithCache() : iterable |
637
|
|
|
{ |
638
|
|
|
return [ |
639
|
|
|
[3, 'CACHE 3'], |
640
|
|
|
]; |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
protected function getBinaryDefaultLength() : int |
644
|
|
|
{ |
645
|
|
|
return 0; |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
protected function getBinaryMaxLength() : int |
649
|
|
|
{ |
650
|
|
|
return 0; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
public function testReturnsBinaryTypeDeclarationSQL() : void |
654
|
|
|
{ |
655
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL([])); |
656
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); |
657
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); |
658
|
|
|
|
659
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); |
660
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); |
661
|
|
|
self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() : void |
665
|
|
|
{ |
666
|
|
|
$table1 = new Table('mytable'); |
667
|
|
|
$table1->addColumn('column_varbinary', 'binary'); |
668
|
|
|
$table1->addColumn('column_binary', 'binary', ['fixed' => true]); |
669
|
|
|
$table1->addColumn('column_blob', 'blob'); |
670
|
|
|
|
671
|
|
|
$table2 = new Table('mytable'); |
672
|
|
|
$table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); |
673
|
|
|
$table2->addColumn('column_binary', 'binary'); |
674
|
|
|
$table2->addColumn('column_blob', 'binary'); |
675
|
|
|
|
676
|
|
|
$comparator = new Comparator(); |
677
|
|
|
|
678
|
|
|
// VARBINARY -> BINARY |
679
|
|
|
// BINARY -> VARBINARY |
680
|
|
|
// BLOB -> VARBINARY |
681
|
|
|
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); |
|
|
|
|
682
|
|
|
|
683
|
|
|
$table2 = new Table('mytable'); |
684
|
|
|
$table2->addColumn('column_varbinary', 'binary', ['length' => 42]); |
685
|
|
|
$table2->addColumn('column_binary', 'blob'); |
686
|
|
|
$table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]); |
687
|
|
|
|
688
|
|
|
// VARBINARY -> VARBINARY with changed length |
689
|
|
|
// BINARY -> BLOB |
690
|
|
|
// BLOB -> BINARY |
691
|
|
|
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); |
692
|
|
|
|
693
|
|
|
$table2 = new Table('mytable'); |
694
|
|
|
$table2->addColumn('column_varbinary', 'blob'); |
695
|
|
|
$table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]); |
696
|
|
|
$table2->addColumn('column_blob', 'blob'); |
697
|
|
|
|
698
|
|
|
// VARBINARY -> BLOB |
699
|
|
|
// BINARY -> BINARY with changed length |
700
|
|
|
// BLOB -> BLOB |
701
|
|
|
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* {@inheritDoc} |
706
|
|
|
* |
707
|
|
|
* @group DBAL-234 |
708
|
|
|
*/ |
709
|
|
|
protected function getAlterTableRenameIndexSQL() : array |
710
|
|
|
{ |
711
|
|
|
return ['ALTER INDEX idx_foo RENAME TO idx_bar']; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* {@inheritDoc} |
716
|
|
|
* |
717
|
|
|
* @group DBAL-234 |
718
|
|
|
*/ |
719
|
|
|
protected function getQuotedAlterTableRenameIndexSQL() : array |
720
|
|
|
{ |
721
|
|
|
return [ |
722
|
|
|
'ALTER INDEX "create" RENAME TO "select"', |
723
|
|
|
'ALTER INDEX "foo" RENAME TO "bar"', |
724
|
|
|
]; |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
/** |
728
|
|
|
* PostgreSQL boolean strings provider |
729
|
|
|
* |
730
|
|
|
* @return mixed[][] |
731
|
|
|
*/ |
732
|
|
|
public static function pgBooleanProvider() : iterable |
733
|
|
|
{ |
734
|
|
|
return [ |
735
|
|
|
// Database value, prepared statement value, boolean integer value, boolean value. |
736
|
|
|
[true, 'true', 1, true], |
737
|
|
|
['t', 'true', 1, true], |
738
|
|
|
['true', 'true', 1, true], |
739
|
|
|
['y', 'true', 1, true], |
740
|
|
|
['yes', 'true', 1, true], |
741
|
|
|
['on', 'true', 1, true], |
742
|
|
|
['1', 'true', 1, true], |
743
|
|
|
|
744
|
|
|
[false, 'false', 0, false], |
745
|
|
|
['f', 'false', 0, false], |
746
|
|
|
['false', 'false', 0, false], |
747
|
|
|
[ 'n', 'false', 0, false], |
748
|
|
|
['no', 'false', 0, false], |
749
|
|
|
['off', 'false', 0, false], |
750
|
|
|
['0', 'false', 0, false], |
751
|
|
|
|
752
|
|
|
[null, 'NULL', null, null], |
753
|
|
|
]; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* {@inheritdoc} |
758
|
|
|
*/ |
759
|
|
|
protected function getQuotedAlterTableRenameColumnSQL() : array |
760
|
|
|
{ |
761
|
|
|
return [ |
762
|
|
|
'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', |
763
|
|
|
'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', |
764
|
|
|
'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', |
765
|
|
|
'ALTER TABLE mytable RENAME COLUMN "create" TO reserved_keyword', |
766
|
|
|
'ALTER TABLE mytable RENAME COLUMN "table" TO "from"', |
767
|
|
|
'ALTER TABLE mytable RENAME COLUMN "select" TO "bar"', |
768
|
|
|
'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', |
769
|
|
|
'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', |
770
|
|
|
'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', |
771
|
|
|
]; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* {@inheritdoc} |
776
|
|
|
*/ |
777
|
|
|
protected function getQuotedAlterTableChangeColumnLengthSQL() : array |
778
|
|
|
{ |
779
|
|
|
return [ |
780
|
|
|
'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', |
781
|
|
|
'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)', |
782
|
|
|
'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)', |
783
|
|
|
'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)', |
784
|
|
|
'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)', |
785
|
|
|
'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)', |
786
|
|
|
]; |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* {@inheritDoc} |
791
|
|
|
* |
792
|
|
|
* @group DBAL-807 |
793
|
|
|
*/ |
794
|
|
|
protected function getAlterTableRenameIndexInSchemaSQL() : array |
795
|
|
|
{ |
796
|
|
|
return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
/** |
800
|
|
|
* {@inheritDoc} |
801
|
|
|
* |
802
|
|
|
* @group DBAL-807 |
803
|
|
|
*/ |
804
|
|
|
protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array |
805
|
|
|
{ |
806
|
|
|
return [ |
807
|
|
|
'ALTER INDEX "schema"."create" RENAME TO "select"', |
808
|
|
|
'ALTER INDEX "schema"."foo" RENAME TO "bar"', |
809
|
|
|
]; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
protected function getQuotesDropForeignKeySQL() : string |
813
|
|
|
{ |
814
|
|
|
return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
public function testGetNullCommentOnColumnSQL() : void |
818
|
|
|
{ |
819
|
|
|
self::assertEquals( |
820
|
|
|
'COMMENT ON COLUMN mytable.id IS NULL', |
821
|
|
|
$this->platform->getCommentOnColumnSQL('mytable', 'id', null) |
822
|
|
|
); |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
/** |
826
|
|
|
* @group DBAL-423 |
827
|
|
|
*/ |
828
|
|
|
public function testReturnsGuidTypeDeclarationSQL() : void |
829
|
|
|
{ |
830
|
|
|
self::assertSame('UUID', $this->platform->getGuidTypeDeclarationSQL([])); |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
/** |
834
|
|
|
* {@inheritdoc} |
835
|
|
|
*/ |
836
|
|
|
public function getAlterTableRenameColumnSQL() : array |
837
|
|
|
{ |
838
|
|
|
return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* {@inheritdoc} |
843
|
|
|
*/ |
844
|
|
|
protected function getQuotesTableIdentifiersInAlterTableSQL() : array |
845
|
|
|
{ |
846
|
|
|
return [ |
847
|
|
|
'ALTER TABLE "foo" DROP CONSTRAINT fk1', |
848
|
|
|
'ALTER TABLE "foo" DROP CONSTRAINT fk2', |
849
|
|
|
'ALTER TABLE "foo" ADD bloo INT NOT NULL', |
850
|
|
|
'ALTER TABLE "foo" DROP baz', |
851
|
|
|
'ALTER TABLE "foo" ALTER bar DROP NOT NULL', |
852
|
|
|
'ALTER TABLE "foo" RENAME COLUMN id TO war', |
853
|
|
|
'ALTER TABLE "foo" RENAME TO "table"', |
854
|
|
|
'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE ' . |
855
|
|
|
'INITIALLY IMMEDIATE', |
856
|
|
|
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE ' . |
857
|
|
|
'INITIALLY IMMEDIATE', |
858
|
|
|
]; |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
/** |
862
|
|
|
* {@inheritdoc} |
863
|
|
|
*/ |
864
|
|
|
protected function getCommentOnColumnSQL() : array |
865
|
|
|
{ |
866
|
|
|
return [ |
867
|
|
|
'COMMENT ON COLUMN foo.bar IS \'comment\'', |
868
|
|
|
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', |
869
|
|
|
'COMMENT ON COLUMN "select"."from" IS \'comment\'', |
870
|
|
|
]; |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
/** |
874
|
|
|
* @group DBAL-1004 |
875
|
|
|
*/ |
876
|
|
|
public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void |
877
|
|
|
{ |
878
|
|
|
$table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); |
879
|
|
|
$table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); |
880
|
|
|
|
881
|
|
|
$comparator = new Comparator(); |
882
|
|
|
|
883
|
|
|
$tableDiff = $comparator->diffTable($table1, $table2); |
884
|
|
|
|
885
|
|
|
self::assertInstanceOf(TableDiff::class, $tableDiff); |
886
|
|
|
self::assertSame( |
887
|
|
|
['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], |
888
|
|
|
$this->platform->getAlterTableSQL($tableDiff) |
|
|
|
|
889
|
|
|
); |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
/** |
893
|
|
|
* @group 3158 |
894
|
|
|
*/ |
895
|
|
|
public function testAltersTableColumnCommentIfRequiredByType() : void |
896
|
|
|
{ |
897
|
|
|
$table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]); |
898
|
|
|
$table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]); |
899
|
|
|
|
900
|
|
|
$comparator = new Comparator(); |
901
|
|
|
|
902
|
|
|
$tableDiff = $comparator->diffTable($table1, $table2); |
903
|
|
|
|
904
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); |
905
|
|
|
$this->assertSame( |
906
|
|
|
[ |
907
|
|
|
'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', |
908
|
|
|
'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT', |
909
|
|
|
'COMMENT ON COLUMN "foo"."bar" IS \'(DC2Type:datetime_immutable)\'', |
910
|
|
|
], |
911
|
|
|
$this->platform->getAlterTableSQL($tableDiff) |
|
|
|
|
912
|
|
|
); |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
/** |
916
|
|
|
* {@inheritdoc} |
917
|
|
|
*/ |
918
|
|
|
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string |
919
|
|
|
{ |
920
|
|
|
return 'CONSTRAINT "select" UNIQUE (foo)'; |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
/** |
924
|
|
|
* {@inheritdoc} |
925
|
|
|
*/ |
926
|
|
|
protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string |
927
|
|
|
{ |
928
|
|
|
return 'INDEX "select" (foo)'; |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
/** |
932
|
|
|
* {@inheritdoc} |
933
|
|
|
*/ |
934
|
|
|
protected function getQuotesReservedKeywordInTruncateTableSQL() : string |
935
|
|
|
{ |
936
|
|
|
return 'TRUNCATE "select"'; |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
/** |
940
|
|
|
* {@inheritdoc} |
941
|
|
|
*/ |
942
|
|
|
protected function getAlterStringToFixedStringSQL() : array |
943
|
|
|
{ |
944
|
|
|
return ['ALTER TABLE mytable ALTER name TYPE CHAR(2)']; |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
/** |
948
|
|
|
* {@inheritdoc} |
949
|
|
|
*/ |
950
|
|
|
protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array |
951
|
|
|
{ |
952
|
|
|
return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
public function testGetTruncateMultiTableSQL() : void |
956
|
|
|
{ |
957
|
|
|
self::assertSame( |
958
|
|
|
'TRUNCATE foo, foo.bar, "default" CASCADE', |
959
|
|
|
$this->platform->getTruncateMultiTableSQL(['foo', 'foo.bar', 'default'], true) |
960
|
|
|
); |
961
|
|
|
} |
962
|
|
|
|
963
|
|
|
/** |
964
|
|
|
* @group DBAL-1142 |
965
|
|
|
*/ |
966
|
|
|
public function testInitializesTsvectorTypeMapping() : void |
967
|
|
|
{ |
968
|
|
|
self::assertTrue($this->platform->hasDoctrineTypeMappingFor('tsvector')); |
969
|
|
|
self::assertEquals('text', $this->platform->getDoctrineTypeMapping('tsvector')); |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
/** |
973
|
|
|
* @group DBAL-1220 |
974
|
|
|
*/ |
975
|
|
|
public function testReturnsDisallowDatabaseConnectionsSQL() : void |
976
|
|
|
{ |
977
|
|
|
self::assertSame( |
978
|
|
|
"UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", |
979
|
|
|
$this->platform->getDisallowDatabaseConnectionsSQL('foo') |
|
|
|
|
980
|
|
|
); |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* @group DBAL-1220 |
985
|
|
|
*/ |
986
|
|
|
public function testReturnsCloseActiveDatabaseConnectionsSQL() : void |
987
|
|
|
{ |
988
|
|
|
self::assertSame( |
989
|
|
|
"SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", |
990
|
|
|
$this->platform->getCloseActiveDatabaseConnectionsSQL('foo') |
|
|
|
|
991
|
|
|
); |
992
|
|
|
} |
993
|
|
|
|
994
|
|
|
/** |
995
|
|
|
* @group DBAL-2436 |
996
|
|
|
*/ |
997
|
|
|
public function testQuotesTableNameInListTableForeignKeysSQL() : void |
998
|
|
|
{ |
999
|
|
|
self::assertStringContainsStringIgnoringCase( |
1000
|
|
|
"'Foo''Bar\\'", |
1001
|
|
|
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\") |
1002
|
|
|
); |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
/** |
1006
|
|
|
* @group DBAL-2436 |
1007
|
|
|
*/ |
1008
|
|
|
public function testQuotesSchemaNameInListTableForeignKeysSQL() : void |
1009
|
|
|
{ |
1010
|
|
|
self::assertStringContainsStringIgnoringCase( |
1011
|
|
|
"'Foo''Bar\\'", |
1012
|
|
|
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") |
1013
|
|
|
); |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
/** |
1017
|
|
|
* @group DBAL-2436 |
1018
|
|
|
*/ |
1019
|
|
|
public function testQuotesTableNameInListTableConstraintsSQL() : void |
1020
|
|
|
{ |
1021
|
|
|
self::assertStringContainsStringIgnoringCase( |
1022
|
|
|
"'Foo''Bar\\'", |
1023
|
|
|
$this->platform->getListTableConstraintsSQL("Foo'Bar\\") |
1024
|
|
|
); |
1025
|
|
|
} |
1026
|
|
|
|
1027
|
|
|
/** |
1028
|
|
|
* @group DBAL-2436 |
1029
|
|
|
*/ |
1030
|
|
|
public function testQuotesTableNameInListTableIndexesSQL() : void |
1031
|
|
|
{ |
1032
|
|
|
self::assertStringContainsStringIgnoringCase( |
1033
|
|
|
"'Foo''Bar\\'", |
1034
|
|
|
$this->platform->getListTableIndexesSQL("Foo'Bar\\") |
1035
|
|
|
); |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
/** |
1039
|
|
|
* @group DBAL-2436 |
1040
|
|
|
*/ |
1041
|
|
|
public function testQuotesSchemaNameInListTableIndexesSQL() : void |
1042
|
|
|
{ |
1043
|
|
|
self::assertStringContainsStringIgnoringCase( |
1044
|
|
|
"'Foo''Bar\\'", |
1045
|
|
|
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") |
1046
|
|
|
); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
/** |
1050
|
|
|
* @group DBAL-2436 |
1051
|
|
|
*/ |
1052
|
|
|
public function testQuotesTableNameInListTableColumnsSQL() : void |
1053
|
|
|
{ |
1054
|
|
|
self::assertStringContainsStringIgnoringCase( |
1055
|
|
|
"'Foo''Bar\\'", |
1056
|
|
|
$this->platform->getListTableColumnsSQL("Foo'Bar\\") |
1057
|
|
|
); |
1058
|
|
|
} |
1059
|
|
|
|
1060
|
|
|
/** |
1061
|
|
|
* @group DBAL-2436 |
1062
|
|
|
*/ |
1063
|
|
|
public function testQuotesSchemaNameInListTableColumnsSQL() : void |
1064
|
|
|
{ |
1065
|
|
|
self::assertStringContainsStringIgnoringCase( |
1066
|
|
|
"'Foo''Bar\\'", |
1067
|
|
|
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") |
1068
|
|
|
); |
1069
|
|
|
} |
1070
|
|
|
|
1071
|
|
|
/** |
1072
|
|
|
* @group DBAL-2436 |
1073
|
|
|
*/ |
1074
|
|
|
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void |
1075
|
|
|
{ |
1076
|
|
|
self::assertStringContainsStringIgnoringCase( |
1077
|
|
|
"'Foo''Bar\\'", |
1078
|
|
|
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\") |
1079
|
|
|
); |
1080
|
|
|
} |
1081
|
|
|
} |
1082
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.