1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Tests\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
6
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
7
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform; |
8
|
|
|
use Doctrine\DBAL\Schema\Column; |
9
|
|
|
use Doctrine\DBAL\Schema\Table; |
10
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
11
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel; |
12
|
|
|
use Doctrine\DBAL\Types\Type; |
13
|
|
|
|
14
|
|
|
class SqlitePlatformTest extends AbstractPlatformTestCase |
15
|
|
|
{ |
16
|
|
|
public function createPlatform() : AbstractPlatform |
17
|
|
|
{ |
18
|
|
|
return new SqlitePlatform(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getGenerateTableSql() : string |
22
|
|
|
{ |
23
|
|
|
return 'CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritDoc} |
28
|
|
|
*/ |
29
|
|
|
public function getGenerateTableWithMultiColumnUniqueIndexSql() : array |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', |
33
|
|
|
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', |
34
|
|
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGeneratesSqlSnippets() : void |
38
|
|
|
{ |
39
|
|
|
self::assertEquals('REGEXP', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); |
40
|
|
|
self::assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); |
41
|
|
|
self::assertEquals('SUBSTR(column, 0, 5)', $this->platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGeneratesTransactionCommands() : void |
45
|
|
|
{ |
46
|
|
|
self::assertEquals( |
47
|
|
|
'PRAGMA read_uncommitted = 0', |
48
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) |
49
|
|
|
); |
50
|
|
|
self::assertEquals( |
51
|
|
|
'PRAGMA read_uncommitted = 1', |
52
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) |
53
|
|
|
); |
54
|
|
|
self::assertEquals( |
55
|
|
|
'PRAGMA read_uncommitted = 1', |
56
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) |
57
|
|
|
); |
58
|
|
|
self::assertEquals( |
59
|
|
|
'PRAGMA read_uncommitted = 1', |
60
|
|
|
$this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testPrefersIdentityColumns() : void |
65
|
|
|
{ |
66
|
|
|
self::assertTrue($this->platform->prefersIdentityColumns()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers() : void |
70
|
|
|
{ |
71
|
|
|
self::assertSame( |
72
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
73
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @group DBAL-752 |
79
|
|
|
* @group DBAL-924 |
80
|
|
|
*/ |
81
|
|
|
public function testGeneratesTypeDeclarationForTinyIntegers() : void |
82
|
|
|
{ |
83
|
|
|
self::assertEquals( |
84
|
|
|
'TINYINT', |
85
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL([]) |
|
|
|
|
86
|
|
|
); |
87
|
|
|
self::assertEquals( |
88
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
89
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true]) |
90
|
|
|
); |
91
|
|
|
self::assertEquals( |
92
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
93
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL( |
94
|
|
|
['autoincrement' => true, 'primary' => true] |
95
|
|
|
) |
96
|
|
|
); |
97
|
|
|
self::assertEquals( |
98
|
|
|
'TINYINT', |
99
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL(['unsigned' => false]) |
100
|
|
|
); |
101
|
|
|
self::assertEquals( |
102
|
|
|
'TINYINT UNSIGNED', |
103
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL(['unsigned' => true]) |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @group DBAL-752 |
109
|
|
|
* @group DBAL-924 |
110
|
|
|
*/ |
111
|
|
|
public function testGeneratesTypeDeclarationForSmallIntegers() : void |
112
|
|
|
{ |
113
|
|
|
self::assertEquals( |
114
|
|
|
'SMALLINT', |
115
|
|
|
$this->platform->getSmallIntTypeDeclarationSQL([]) |
116
|
|
|
); |
117
|
|
|
self::assertEquals( |
118
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
119
|
|
|
$this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) |
120
|
|
|
); |
121
|
|
|
self::assertEquals( |
122
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
123
|
|
|
$this->platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) |
124
|
|
|
); |
125
|
|
|
self::assertEquals( |
126
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
127
|
|
|
$this->platform->getSmallIntTypeDeclarationSQL( |
128
|
|
|
['autoincrement' => true, 'primary' => true] |
129
|
|
|
) |
130
|
|
|
); |
131
|
|
|
self::assertEquals( |
132
|
|
|
'SMALLINT', |
133
|
|
|
$this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => false]) |
134
|
|
|
); |
135
|
|
|
self::assertEquals( |
136
|
|
|
'SMALLINT UNSIGNED', |
137
|
|
|
$this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]) |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @group DBAL-752 |
143
|
|
|
* @group DBAL-924 |
144
|
|
|
*/ |
145
|
|
|
public function testGeneratesTypeDeclarationForMediumIntegers() : void |
146
|
|
|
{ |
147
|
|
|
self::assertEquals( |
148
|
|
|
'MEDIUMINT', |
149
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL([]) |
|
|
|
|
150
|
|
|
); |
151
|
|
|
self::assertEquals( |
152
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
153
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true]) |
154
|
|
|
); |
155
|
|
|
self::assertEquals( |
156
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
157
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) |
158
|
|
|
); |
159
|
|
|
self::assertEquals( |
160
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
161
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL( |
162
|
|
|
['autoincrement' => true, 'primary' => true] |
163
|
|
|
) |
164
|
|
|
); |
165
|
|
|
self::assertEquals( |
166
|
|
|
'MEDIUMINT', |
167
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL(['unsigned' => false]) |
168
|
|
|
); |
169
|
|
|
self::assertEquals( |
170
|
|
|
'MEDIUMINT UNSIGNED', |
171
|
|
|
$this->platform->getMediumIntTypeDeclarationSQL(['unsigned' => true]) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testGeneratesTypeDeclarationForIntegers() : void |
176
|
|
|
{ |
177
|
|
|
self::assertEquals( |
178
|
|
|
'INTEGER', |
179
|
|
|
$this->platform->getIntegerTypeDeclarationSQL([]) |
180
|
|
|
); |
181
|
|
|
self::assertEquals( |
182
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
183
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) |
184
|
|
|
); |
185
|
|
|
self::assertEquals( |
186
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
187
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) |
188
|
|
|
); |
189
|
|
|
self::assertEquals( |
190
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
191
|
|
|
$this->platform->getIntegerTypeDeclarationSQL( |
192
|
|
|
['autoincrement' => true, 'primary' => true] |
193
|
|
|
) |
194
|
|
|
); |
195
|
|
|
self::assertEquals( |
196
|
|
|
'INTEGER', |
197
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['unsigned' => false]) |
198
|
|
|
); |
199
|
|
|
self::assertEquals( |
200
|
|
|
'INTEGER UNSIGNED', |
201
|
|
|
$this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true]) |
202
|
|
|
); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @group DBAL-752 |
207
|
|
|
* @group DBAL-924 |
208
|
|
|
*/ |
209
|
|
|
public function testGeneratesTypeDeclarationForBigIntegers() : void |
210
|
|
|
{ |
211
|
|
|
self::assertEquals( |
212
|
|
|
'BIGINT', |
213
|
|
|
$this->platform->getBigIntTypeDeclarationSQL([]) |
214
|
|
|
); |
215
|
|
|
self::assertEquals( |
216
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
217
|
|
|
$this->platform->getBigIntTypeDeclarationSQL(['autoincrement' => true]) |
218
|
|
|
); |
219
|
|
|
self::assertEquals( |
220
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
221
|
|
|
$this->platform->getBigIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) |
222
|
|
|
); |
223
|
|
|
self::assertEquals( |
224
|
|
|
'INTEGER PRIMARY KEY AUTOINCREMENT', |
225
|
|
|
$this->platform->getBigIntTypeDeclarationSQL( |
226
|
|
|
['autoincrement' => true, 'primary' => true] |
227
|
|
|
) |
228
|
|
|
); |
229
|
|
|
self::assertEquals( |
230
|
|
|
'BIGINT', |
231
|
|
|
$this->platform->getBigIntTypeDeclarationSQL(['unsigned' => false]) |
232
|
|
|
); |
233
|
|
|
self::assertEquals( |
234
|
|
|
'BIGINT UNSIGNED', |
235
|
|
|
$this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true]) |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public function testGeneratesTypeDeclarationForStrings() : void |
240
|
|
|
{ |
241
|
|
|
self::assertEquals( |
242
|
|
|
'CHAR(10)', |
243
|
|
|
$this->platform->getVarcharTypeDeclarationSQL( |
244
|
|
|
['length' => 10, 'fixed' => true] |
245
|
|
|
) |
246
|
|
|
); |
247
|
|
|
self::assertEquals( |
248
|
|
|
'VARCHAR(50)', |
249
|
|
|
$this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), |
250
|
|
|
'Variable string declaration is not correct' |
251
|
|
|
); |
252
|
|
|
self::assertEquals( |
253
|
|
|
'VARCHAR(255)', |
254
|
|
|
$this->platform->getVarcharTypeDeclarationSQL([]), |
255
|
|
|
'Long string declaration is not correct' |
256
|
|
|
); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function getGenerateIndexSql() : string |
260
|
|
|
{ |
261
|
|
|
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function getGenerateUniqueIndexSql() : string |
265
|
|
|
{ |
266
|
|
|
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function testGeneratesForeignKeyCreationSql() : void |
270
|
|
|
{ |
271
|
|
|
$this->expectException(DBALException::class); |
272
|
|
|
|
273
|
|
|
parent::testGeneratesForeignKeyCreationSql(); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function testGeneratesConstraintCreationSql() : void |
277
|
|
|
{ |
278
|
|
|
$this->expectException(DBALException::class); |
279
|
|
|
|
280
|
|
|
parent::testGeneratesConstraintCreationSql(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function getGenerateForeignKeySql() : string |
284
|
|
|
{ |
285
|
|
|
return null; |
|
|
|
|
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
public function testModifyLimitQuery() : void |
289
|
|
|
{ |
290
|
|
|
$sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); |
291
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
public function testModifyLimitQueryWithEmptyOffset() : void |
295
|
|
|
{ |
296
|
|
|
$sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); |
297
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function testModifyLimitQueryWithOffsetAndEmptyLimit() : void |
301
|
|
|
{ |
302
|
|
|
$sql = $this->platform->modifyLimitQuery('SELECT * FROM user', null, 10); |
303
|
|
|
self::assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* {@inheritDoc} |
308
|
|
|
*/ |
309
|
|
|
public function getGenerateAlterTableSql() : array |
310
|
|
|
{ |
311
|
|
|
return [ |
312
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable', |
313
|
|
|
'DROP TABLE mytable', |
314
|
|
|
"CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, baz VARCHAR(255) DEFAULT 'def' NOT NULL, bloo BOOLEAN DEFAULT '0' NOT NULL, quota INTEGER DEFAULT NULL)", |
315
|
|
|
'INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable', |
316
|
|
|
'DROP TABLE __temp__mytable', |
317
|
|
|
'ALTER TABLE mytable RENAME TO userlist', |
318
|
|
|
]; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @group DDC-1845 |
323
|
|
|
*/ |
324
|
|
|
public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() : void |
325
|
|
|
{ |
326
|
|
|
$table = new Table('test'); |
327
|
|
|
$table->addColumn('"like"', 'integer', ['notnull' => true, 'autoincrement' => true]); |
328
|
|
|
$table->setPrimaryKey(['"like"']); |
329
|
|
|
|
330
|
|
|
$createTableSQL = $this->platform->getCreateTableSQL($table); |
331
|
|
|
self::assertEquals( |
332
|
|
|
'CREATE TABLE test ("like" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)', |
333
|
|
|
$createTableSQL[0] |
334
|
|
|
); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function testAlterTableAddColumns() : void |
338
|
|
|
{ |
339
|
|
|
$diff = new TableDiff('user'); |
340
|
|
|
$diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); |
341
|
|
|
$diff->addedColumns['count'] = new Column('count', Type::getType('integer'), ['notnull' => false, 'default' => 1]); |
342
|
|
|
|
343
|
|
|
$expected = [ |
344
|
|
|
'ALTER TABLE user ADD COLUMN foo VARCHAR(255) NOT NULL', |
345
|
|
|
'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1', |
346
|
|
|
]; |
347
|
|
|
|
348
|
|
|
self::assertEquals($expected, $this->platform->getAlterTableSQL($diff)); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* @dataProvider complexDiffProvider |
353
|
|
|
*/ |
354
|
|
|
public function testAlterTableAddComplexColumns(TableDiff $diff) : void |
355
|
|
|
{ |
356
|
|
|
$this->expectException(DBALException::class); |
357
|
|
|
|
358
|
|
|
$this->platform->getAlterTableSQL($diff); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @return mixed[][] |
363
|
|
|
*/ |
364
|
|
|
public static function complexDiffProvider() : iterable |
365
|
|
|
{ |
366
|
|
|
$date = new TableDiff('user'); |
367
|
|
|
$date->addedColumns['time'] = new Column('time', Type::getType('date'), ['default' => 'CURRENT_DATE']); |
368
|
|
|
|
369
|
|
|
$id = new TableDiff('user'); |
370
|
|
|
$id->addedColumns['id'] = new Column('id', Type::getType('integer'), ['autoincrement' => true]); |
371
|
|
|
|
372
|
|
|
return [ |
373
|
|
|
'date column with default value' => [$date], |
374
|
|
|
'id column with auto increment' => [$id], |
375
|
|
|
]; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function testCreateTableWithDeferredForeignKeys() : void |
379
|
|
|
{ |
380
|
|
|
$table = new Table('user'); |
381
|
|
|
$table->addColumn('id', 'integer'); |
382
|
|
|
$table->addColumn('article', 'integer'); |
383
|
|
|
$table->addColumn('post', 'integer'); |
384
|
|
|
$table->addColumn('parent', 'integer'); |
385
|
|
|
$table->setPrimaryKey(['id']); |
386
|
|
|
$table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); |
387
|
|
|
$table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); |
388
|
|
|
$table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); |
389
|
|
|
|
390
|
|
|
$sql = [ |
391
|
|
|
'CREATE TABLE user (' |
392
|
|
|
. 'id INTEGER NOT NULL, article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL' |
393
|
|
|
. ', PRIMARY KEY(id)' |
394
|
|
|
. ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE' |
395
|
|
|
. ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (post) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED' |
396
|
|
|
. ', CONSTRAINT FK_8D93D6493D8E604F FOREIGN KEY (parent) REFERENCES user (id) DEFERRABLE INITIALLY DEFERRED' |
397
|
|
|
. ')', |
398
|
|
|
'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)', |
399
|
|
|
'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)', |
400
|
|
|
'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)', |
401
|
|
|
]; |
402
|
|
|
|
403
|
|
|
self::assertEquals($sql, $this->platform->getCreateTableSQL($table)); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
public function testAlterTable() : void |
407
|
|
|
{ |
408
|
|
|
$table = new Table('user'); |
409
|
|
|
$table->addColumn('id', 'integer'); |
410
|
|
|
$table->addColumn('article', 'integer'); |
411
|
|
|
$table->addColumn('post', 'integer'); |
412
|
|
|
$table->addColumn('parent', 'integer'); |
413
|
|
|
$table->setPrimaryKey(['id']); |
414
|
|
|
$table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); |
415
|
|
|
$table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); |
416
|
|
|
$table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); |
417
|
|
|
$table->addIndex(['article', 'post'], 'index1'); |
418
|
|
|
|
419
|
|
|
$diff = new TableDiff('user'); |
420
|
|
|
$diff->fromTable = $table; |
421
|
|
|
$diff->newName = 'client'; |
422
|
|
|
$diff->renamedColumns['id'] = new Column('key', Type::getType('integer'), []); |
423
|
|
|
$diff->renamedColumns['post'] = new Column('comment', Type::getType('integer'), []); |
424
|
|
|
$diff->removedColumns['parent'] = new Column('comment', Type::getType('integer'), []); |
425
|
|
|
$diff->removedIndexes['index1'] = $table->getIndex('index1'); |
426
|
|
|
|
427
|
|
|
$sql = [ |
428
|
|
|
'DROP INDEX IDX_8D93D64923A0E66', |
429
|
|
|
'DROP INDEX IDX_8D93D6495A8A6C8D', |
430
|
|
|
'DROP INDEX IDX_8D93D6493D8E604F', |
431
|
|
|
'DROP INDEX index1', |
432
|
|
|
'CREATE TEMPORARY TABLE __temp__user AS SELECT id, article, post FROM user', |
433
|
|
|
'DROP TABLE user', |
434
|
|
|
'CREATE TABLE user (' |
435
|
|
|
. '"key" INTEGER NOT NULL, article INTEGER NOT NULL, comment INTEGER NOT NULL' |
436
|
|
|
. ', PRIMARY KEY("key")' |
437
|
|
|
. ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE' |
438
|
|
|
. ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (comment) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED' |
439
|
|
|
. ')', |
440
|
|
|
'INSERT INTO user ("key", article, comment) SELECT id, article, post FROM __temp__user', |
441
|
|
|
'DROP TABLE __temp__user', |
442
|
|
|
'ALTER TABLE user RENAME TO client', |
443
|
|
|
'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)', |
444
|
|
|
'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)', |
445
|
|
|
]; |
446
|
|
|
|
447
|
|
|
self::assertEquals($sql, $this->platform->getAlterTableSQL($diff)); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* {@inheritDoc} |
452
|
|
|
*/ |
453
|
|
|
protected function getQuotedColumnInPrimaryKeySQL() : array |
454
|
|
|
{ |
455
|
|
|
return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* {@inheritDoc} |
460
|
|
|
*/ |
461
|
|
|
protected function getQuotedColumnInIndexSQL() : array |
462
|
|
|
{ |
463
|
|
|
return [ |
464
|
|
|
'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', |
465
|
|
|
'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', |
466
|
|
|
]; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* {@inheritDoc} |
471
|
|
|
*/ |
472
|
|
|
protected function getQuotedNameInIndexSQL() : array |
473
|
|
|
{ |
474
|
|
|
return [ |
475
|
|
|
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', |
476
|
|
|
'CREATE INDEX "key" ON test (column1)', |
477
|
|
|
]; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* {@inheritDoc} |
482
|
|
|
*/ |
483
|
|
|
protected function getQuotedColumnInForeignKeySQL() : array |
484
|
|
|
{ |
485
|
|
|
return [ |
486
|
|
|
'CREATE TABLE "quoted" (' . |
487
|
|
|
'"create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, ' . |
488
|
|
|
'CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . |
489
|
|
|
'CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . |
490
|
|
|
'CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE)', |
491
|
|
|
]; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
protected function getBinaryDefaultLength() : int |
495
|
|
|
{ |
496
|
|
|
return 0; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
protected function getBinaryMaxLength() : int |
500
|
|
|
{ |
501
|
|
|
return 0; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testReturnsBinaryTypeDeclarationSQL() : void |
505
|
|
|
{ |
506
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL([])); |
507
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); |
508
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); |
509
|
|
|
|
510
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); |
511
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); |
512
|
|
|
self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* {@inheritDoc} |
517
|
|
|
* |
518
|
|
|
* @group DBAL-234 |
519
|
|
|
*/ |
520
|
|
|
protected function getAlterTableRenameIndexSQL() : array |
521
|
|
|
{ |
522
|
|
|
return [ |
523
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable', |
524
|
|
|
'DROP TABLE mytable', |
525
|
|
|
'CREATE TABLE mytable (id INTEGER NOT NULL, PRIMARY KEY(id))', |
526
|
|
|
'INSERT INTO mytable (id) SELECT id FROM __temp__mytable', |
527
|
|
|
'DROP TABLE __temp__mytable', |
528
|
|
|
'CREATE INDEX idx_bar ON mytable (id)', |
529
|
|
|
]; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* {@inheritDoc} |
534
|
|
|
* |
535
|
|
|
* @group DBAL-234 |
536
|
|
|
*/ |
537
|
|
|
protected function getQuotedAlterTableRenameIndexSQL() : array |
538
|
|
|
{ |
539
|
|
|
return [ |
540
|
|
|
'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"', |
541
|
|
|
'DROP TABLE "table"', |
542
|
|
|
'CREATE TABLE "table" (id INTEGER NOT NULL, PRIMARY KEY(id))', |
543
|
|
|
'INSERT INTO "table" (id) SELECT id FROM __temp__table', |
544
|
|
|
'DROP TABLE __temp__table', |
545
|
|
|
'CREATE INDEX "select" ON "table" (id)', |
546
|
|
|
'CREATE INDEX "bar" ON "table" (id)', |
547
|
|
|
]; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* {@inheritdoc} |
552
|
|
|
*/ |
553
|
|
|
protected function getQuotedAlterTableRenameColumnSQL() : array |
554
|
|
|
{ |
555
|
|
|
return [ |
556
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable', |
557
|
|
|
'DROP TABLE mytable', |
558
|
|
|
'CREATE TABLE mytable (unquoted INTEGER NOT NULL --Unquoted 1 |
559
|
|
|
, "where" INTEGER NOT NULL --Unquoted 2 |
560
|
|
|
, "foo" INTEGER NOT NULL --Unquoted 3 |
561
|
|
|
, reserved_keyword INTEGER NOT NULL --Reserved keyword 1 |
562
|
|
|
, "from" INTEGER NOT NULL --Reserved keyword 2 |
563
|
|
|
, "bar" INTEGER NOT NULL --Reserved keyword 3 |
564
|
|
|
, quoted INTEGER NOT NULL --Quoted 1 |
565
|
|
|
, "and" INTEGER NOT NULL --Quoted 2 |
566
|
|
|
, "baz" INTEGER NOT NULL --Quoted 3 |
567
|
|
|
)', |
568
|
|
|
'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable', |
569
|
|
|
'DROP TABLE __temp__mytable', |
570
|
|
|
]; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* {@inheritdoc} |
575
|
|
|
*/ |
576
|
|
|
protected function getQuotedAlterTableChangeColumnLengthSQL() : array |
577
|
|
|
{ |
578
|
|
|
return [ |
579
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable', |
580
|
|
|
'DROP TABLE mytable', |
581
|
|
|
'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL --Unquoted 1 |
582
|
|
|
, unquoted2 VARCHAR(255) NOT NULL --Unquoted 2 |
583
|
|
|
, unquoted3 VARCHAR(255) NOT NULL --Unquoted 3 |
584
|
|
|
, "create" VARCHAR(255) NOT NULL --Reserved keyword 1 |
585
|
|
|
, "table" VARCHAR(255) NOT NULL --Reserved keyword 2 |
586
|
|
|
, "select" VARCHAR(255) NOT NULL --Reserved keyword 3 |
587
|
|
|
)', |
588
|
|
|
'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable', |
589
|
|
|
'DROP TABLE __temp__mytable', |
590
|
|
|
]; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* @group DBAL-807 |
595
|
|
|
*/ |
596
|
|
|
public function testAlterTableRenameIndexInSchema() : void |
597
|
|
|
{ |
598
|
|
|
self::markTestIncomplete( |
599
|
|
|
'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . |
600
|
|
|
'when used with schemas.' |
601
|
|
|
); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* @group DBAL-807 |
606
|
|
|
*/ |
607
|
|
|
public function testQuotesAlterTableRenameIndexInSchema() : void |
608
|
|
|
{ |
609
|
|
|
self::markTestIncomplete( |
610
|
|
|
'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . |
611
|
|
|
'when used with schemas.' |
612
|
|
|
); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* @group DBAL-423 |
617
|
|
|
*/ |
618
|
|
|
public function testReturnsGuidTypeDeclarationSQL() : void |
619
|
|
|
{ |
620
|
|
|
self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* {@inheritdoc} |
625
|
|
|
*/ |
626
|
|
|
public function getAlterTableRenameColumnSQL() : array |
627
|
|
|
{ |
628
|
|
|
return [ |
629
|
|
|
'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo', |
630
|
|
|
'DROP TABLE foo', |
631
|
|
|
'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL --rename test |
632
|
|
|
)', |
633
|
|
|
'INSERT INTO foo (baz) SELECT bar FROM __temp__foo', |
634
|
|
|
'DROP TABLE __temp__foo', |
635
|
|
|
]; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* {@inheritdoc} |
640
|
|
|
*/ |
641
|
|
|
protected function getQuotesTableIdentifiersInAlterTableSQL() : array |
642
|
|
|
{ |
643
|
|
|
return [ |
644
|
|
|
'DROP INDEX IDX_8C736521A81E660E', |
645
|
|
|
'DROP INDEX IDX_8C736521FDC58D6C', |
646
|
|
|
'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"', |
647
|
|
|
'DROP TABLE "foo"', |
648
|
|
|
'CREATE TABLE "foo" (fk2 INTEGER NOT NULL, fk3 INTEGER NOT NULL, fk INTEGER NOT NULL, war INTEGER NOT NULL, ' . |
649
|
|
|
'bar INTEGER DEFAULT NULL, bloo INTEGER NOT NULL, ' . |
650
|
|
|
'CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE, ' . |
651
|
|
|
'CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)', |
652
|
|
|
'INSERT INTO "foo" (fk, fk2, war, fk3, bar) SELECT fk, fk2, id, fk3, bar FROM __temp__foo', |
653
|
|
|
'DROP TABLE __temp__foo', |
654
|
|
|
'ALTER TABLE "foo" RENAME TO "table"', |
655
|
|
|
'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)', |
656
|
|
|
'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)', |
657
|
|
|
]; |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* {@inheritdoc} |
662
|
|
|
*/ |
663
|
|
|
protected function getCommentOnColumnSQL() : array |
664
|
|
|
{ |
665
|
|
|
return [ |
666
|
|
|
'COMMENT ON COLUMN foo.bar IS \'comment\'', |
667
|
|
|
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', |
668
|
|
|
'COMMENT ON COLUMN "select"."from" IS \'comment\'', |
669
|
|
|
]; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
protected static function getInlineColumnCommentDelimiter() : string |
673
|
|
|
{ |
674
|
|
|
return "\n"; |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
protected static function getInlineColumnRegularCommentSQL() : string |
678
|
|
|
{ |
679
|
|
|
return "--Regular comment\n"; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
protected static function getInlineColumnCommentRequiringEscapingSQL() : string |
683
|
|
|
{ |
684
|
|
|
return "--Using inline comment delimiter \n-- works\n"; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
protected static function getInlineColumnEmptyCommentSQL() : string |
688
|
|
|
{ |
689
|
|
|
return "--\n"; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string |
693
|
|
|
{ |
694
|
|
|
return 'CONSTRAINT "select" UNIQUE (foo)'; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string |
698
|
|
|
{ |
699
|
|
|
return 'INDEX "select" (foo)'; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
protected function getQuotesReservedKeywordInTruncateTableSQL() : string |
703
|
|
|
{ |
704
|
|
|
return 'DELETE FROM "select"'; |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
/** |
708
|
|
|
* {@inheritdoc} |
709
|
|
|
*/ |
710
|
|
|
protected function getAlterStringToFixedStringSQL() : array |
711
|
|
|
{ |
712
|
|
|
return [ |
713
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable', |
714
|
|
|
'DROP TABLE mytable', |
715
|
|
|
'CREATE TABLE mytable (name CHAR(2) NOT NULL)', |
716
|
|
|
'INSERT INTO mytable (name) SELECT name FROM __temp__mytable', |
717
|
|
|
'DROP TABLE __temp__mytable', |
718
|
|
|
]; |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* {@inheritdoc} |
723
|
|
|
*/ |
724
|
|
|
protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array |
725
|
|
|
{ |
726
|
|
|
return [ |
727
|
|
|
'DROP INDEX idx_foo', |
728
|
|
|
'DROP INDEX idx_bar', |
729
|
|
|
'CREATE TEMPORARY TABLE __temp__mytable AS SELECT foo, bar, baz FROM mytable', |
730
|
|
|
'DROP TABLE mytable', |
731
|
|
|
'CREATE TABLE mytable (foo INTEGER NOT NULL, bar INTEGER NOT NULL, baz INTEGER NOT NULL, CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT fk_bar FOREIGN KEY (bar) REFERENCES foreign_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)', |
732
|
|
|
'INSERT INTO mytable (foo, bar, baz) SELECT foo, bar, baz FROM __temp__mytable', |
733
|
|
|
'DROP TABLE __temp__mytable', |
734
|
|
|
'CREATE INDEX idx_bar ON mytable (bar)', |
735
|
|
|
'CREATE INDEX idx_foo_renamed ON mytable (foo)', |
736
|
|
|
]; |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
/** |
740
|
|
|
* @group DBAL-2436 |
741
|
|
|
*/ |
742
|
|
|
public function testQuotesTableNameInListTableConstraintsSQL() : void |
743
|
|
|
{ |
744
|
|
|
self::assertStringContainsStringIgnoringCase( |
745
|
|
|
"'Foo''Bar\\'", |
746
|
|
|
$this->platform->getListTableConstraintsSQL("Foo'Bar\\") |
747
|
|
|
); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* @group DBAL-2436 |
752
|
|
|
*/ |
753
|
|
|
public function testQuotesTableNameInListTableColumnsSQL() : void |
754
|
|
|
{ |
755
|
|
|
self::assertStringContainsStringIgnoringCase( |
756
|
|
|
"'Foo''Bar\\'", |
757
|
|
|
$this->platform->getListTableColumnsSQL("Foo'Bar\\") |
758
|
|
|
); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* @group DBAL-2436 |
763
|
|
|
*/ |
764
|
|
|
public function testQuotesTableNameInListTableIndexesSQL() : void |
765
|
|
|
{ |
766
|
|
|
self::assertStringContainsStringIgnoringCase( |
767
|
|
|
"'Foo''Bar\\'", |
768
|
|
|
$this->platform->getListTableIndexesSQL("Foo'Bar\\") |
769
|
|
|
); |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
/** |
773
|
|
|
* @group DBAL-2436 |
774
|
|
|
*/ |
775
|
|
|
public function testQuotesTableNameInListTableForeignKeysSQL() : void |
776
|
|
|
{ |
777
|
|
|
self::assertStringContainsStringIgnoringCase( |
778
|
|
|
"'Foo''Bar\\'", |
779
|
|
|
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\") |
780
|
|
|
); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
public function testDateAddStaticNumberOfDays() : void |
784
|
|
|
{ |
785
|
|
|
self::assertSame("DATE(rentalBeginsOn,'+12 DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 12)); |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
public function testDateAddNumberOfDaysFromColumn() : void |
789
|
|
|
{ |
790
|
|
|
self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 'duration')); |
|
|
|
|
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
public function testSupportsColumnCollation() : void |
794
|
|
|
{ |
795
|
|
|
self::assertTrue($this->platform->supportsColumnCollation()); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
public function testColumnCollationDeclarationSQL() : void |
799
|
|
|
{ |
800
|
|
|
self::assertSame( |
801
|
|
|
'COLLATE NOCASE', |
802
|
|
|
$this->platform->getColumnCollationDeclarationSQL('NOCASE') |
803
|
|
|
); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
public function testGetCreateTableSQLWithColumnCollation() : void |
807
|
|
|
{ |
808
|
|
|
$table = new Table('foo'); |
809
|
|
|
$table->addColumn('no_collation', 'string'); |
810
|
|
|
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'NOCASE'); |
811
|
|
|
|
812
|
|
|
self::assertSame( |
813
|
|
|
['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE NOCASE)'], |
814
|
|
|
$this->platform->getCreateTableSQL($table), |
815
|
|
|
'Column "no_collation" will use the default collation (BINARY) and "column_collation" overwrites the collation on this column' |
816
|
|
|
); |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
public function testGetSequencePrefixWithSchema() : void |
820
|
|
|
{ |
821
|
|
|
self::assertSame('bar__foo', $this->platform->getSequencePrefix('foo', 'bar')); |
822
|
|
|
} |
823
|
|
|
} |
824
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.