1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
6
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
7
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
8
|
|
|
use Doctrine\DBAL\Schema\Index; |
9
|
|
|
use Doctrine\DBAL\Schema\Table; |
10
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
11
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel; |
12
|
|
|
|
13
|
|
|
abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase |
14
|
|
|
{ |
15
|
|
|
public function testModifyLimitQueryWitoutLimit() |
16
|
|
|
{ |
17
|
|
|
$sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10); |
18
|
|
|
self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testGenerateMixedCaseTableCreate() |
22
|
|
|
{ |
23
|
|
|
$table = new Table("Foo"); |
24
|
|
|
$table->addColumn("Bar", "integer"); |
25
|
|
|
|
26
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
27
|
|
|
self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getGenerateTableSql() |
31
|
|
|
{ |
32
|
|
|
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getGenerateTableWithMultiColumnUniqueIndexSql() |
36
|
|
|
{ |
37
|
|
|
return array( |
38
|
|
|
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getGenerateAlterTableSql() |
43
|
|
|
{ |
44
|
|
|
return array( |
45
|
|
|
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL" |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGeneratesSqlSnippets() |
50
|
|
|
{ |
51
|
|
|
self::assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); |
52
|
|
|
self::assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct'); |
53
|
|
|
self::assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGeneratesTransactionsCommands() |
57
|
|
|
{ |
58
|
|
|
self::assertEquals( |
59
|
|
|
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', |
60
|
|
|
$this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED), |
61
|
|
|
'' |
62
|
|
|
); |
63
|
|
|
self::assertEquals( |
64
|
|
|
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', |
65
|
|
|
$this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) |
66
|
|
|
); |
67
|
|
|
self::assertEquals( |
68
|
|
|
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ', |
69
|
|
|
$this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) |
70
|
|
|
); |
71
|
|
|
self::assertEquals( |
72
|
|
|
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE', |
73
|
|
|
$this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testGeneratesDDLSnippets() |
79
|
|
|
{ |
80
|
|
|
self::assertEquals('SHOW DATABASES', $this->_platform->getListDatabasesSQL()); |
81
|
|
|
self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); |
82
|
|
|
self::assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar')); |
83
|
|
|
self::assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGeneratesTypeDeclarationForIntegers() |
87
|
|
|
{ |
88
|
|
|
self::assertEquals( |
89
|
|
|
'INT', |
90
|
|
|
$this->_platform->getIntegerTypeDeclarationSQL(array()) |
91
|
|
|
); |
92
|
|
|
self::assertEquals( |
93
|
|
|
'INT AUTO_INCREMENT', |
94
|
|
|
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) |
95
|
|
|
)); |
96
|
|
|
self::assertEquals( |
97
|
|
|
'INT AUTO_INCREMENT', |
98
|
|
|
$this->_platform->getIntegerTypeDeclarationSQL( |
99
|
|
|
array('autoincrement' => true, 'primary' => true) |
100
|
|
|
)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testGeneratesTypeDeclarationForStrings() |
104
|
|
|
{ |
105
|
|
|
self::assertEquals( |
106
|
|
|
'CHAR(10)', |
107
|
|
|
$this->_platform->getVarcharTypeDeclarationSQL( |
108
|
|
|
array('length' => 10, 'fixed' => true) |
109
|
|
|
)); |
110
|
|
|
self::assertEquals( |
111
|
|
|
'VARCHAR(50)', |
112
|
|
|
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), |
113
|
|
|
'Variable string declaration is not correct' |
114
|
|
|
); |
115
|
|
|
self::assertEquals( |
116
|
|
|
'VARCHAR(255)', |
117
|
|
|
$this->_platform->getVarcharTypeDeclarationSQL(array()), |
118
|
|
|
'Long string declaration is not correct' |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testPrefersIdentityColumns() |
123
|
|
|
{ |
124
|
|
|
self::assertTrue($this->_platform->prefersIdentityColumns()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testSupportsIdentityColumns() |
128
|
|
|
{ |
129
|
|
|
self::assertTrue($this->_platform->supportsIdentityColumns()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testDoesSupportSavePoints() |
133
|
|
|
{ |
134
|
|
|
self::assertTrue($this->_platform->supportsSavepoints()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getGenerateIndexSql() |
138
|
|
|
{ |
139
|
|
|
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getGenerateUniqueIndexSql() |
143
|
|
|
{ |
144
|
|
|
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getGenerateForeignKeySql() |
148
|
|
|
{ |
149
|
|
|
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @group DBAL-126 |
154
|
|
|
*/ |
155
|
|
|
public function testUniquePrimaryKey() |
156
|
|
|
{ |
157
|
|
|
$keyTable = new Table("foo"); |
158
|
|
|
$keyTable->addColumn("bar", "integer"); |
159
|
|
|
$keyTable->addColumn("baz", "string"); |
160
|
|
|
$keyTable->setPrimaryKey(array("bar")); |
161
|
|
|
$keyTable->addUniqueIndex(array("baz")); |
162
|
|
|
|
163
|
|
|
$oldTable = new Table("foo"); |
164
|
|
|
$oldTable->addColumn("bar", "integer"); |
165
|
|
|
$oldTable->addColumn("baz", "string"); |
166
|
|
|
|
167
|
|
|
$c = new \Doctrine\DBAL\Schema\Comparator; |
168
|
|
|
$diff = $c->diffTable($oldTable, $keyTable); |
169
|
|
|
|
170
|
|
|
$sql = $this->_platform->getAlterTableSQL($diff); |
|
|
|
|
171
|
|
|
|
172
|
|
|
self::assertEquals(array( |
173
|
|
|
"ALTER TABLE foo ADD PRIMARY KEY (bar)", |
174
|
|
|
"CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)", |
175
|
|
|
), $sql); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function testModifyLimitQuery() |
179
|
|
|
{ |
180
|
|
|
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); |
181
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function testModifyLimitQueryWithEmptyOffset() |
185
|
|
|
{ |
186
|
|
|
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); |
187
|
|
|
self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @group DDC-118 |
192
|
|
|
*/ |
193
|
|
|
public function testGetDateTimeTypeDeclarationSql() |
194
|
|
|
{ |
195
|
|
|
self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false))); |
196
|
|
|
self::assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true))); |
197
|
|
|
self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array())); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function getCreateTableColumnCommentsSQL() |
201
|
|
|
{ |
202
|
|
|
return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function getAlterTableColumnCommentsSQL() |
206
|
|
|
{ |
207
|
|
|
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getCreateTableColumnTypeCommentsSQL() |
211
|
|
|
{ |
212
|
|
|
return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @group DBAL-237 |
217
|
|
|
*/ |
218
|
|
|
public function testChangeIndexWithForeignKeys() |
219
|
|
|
{ |
220
|
|
|
$index = new Index("idx", array("col"), false); |
221
|
|
|
$unique = new Index("uniq", array("col"), true); |
222
|
|
|
|
223
|
|
|
$diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index)); |
224
|
|
|
$sql = $this->_platform->getAlterTableSQL($diff); |
225
|
|
|
self::assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql); |
226
|
|
|
|
227
|
|
|
$diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique)); |
228
|
|
|
$sql = $this->_platform->getAlterTableSQL($diff); |
229
|
|
|
self::assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
protected function getQuotedColumnInPrimaryKeySQL() |
233
|
|
|
{ |
234
|
|
|
return array( |
235
|
|
|
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
protected function getQuotedColumnInIndexSQL() |
240
|
|
|
{ |
241
|
|
|
return array( |
242
|
|
|
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
protected function getQuotedNameInIndexSQL() |
247
|
|
|
{ |
248
|
|
|
return array( |
249
|
|
|
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
protected function getQuotedColumnInForeignKeySQL() |
254
|
|
|
{ |
255
|
|
|
return array( |
256
|
|
|
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
257
|
|
|
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)', |
258
|
|
|
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)', |
259
|
|
|
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)', |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function testCreateTableWithFulltextIndex() |
264
|
|
|
{ |
265
|
|
|
$table = new Table('fulltext_table'); |
266
|
|
|
$table->addOption('engine', 'MyISAM'); |
267
|
|
|
$table->addColumn('text', 'text'); |
268
|
|
|
$table->addIndex(array('text'), 'fulltext_text'); |
269
|
|
|
|
270
|
|
|
$index = $table->getIndex('fulltext_text'); |
271
|
|
|
$index->addFlag('fulltext'); |
272
|
|
|
|
273
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
274
|
|
|
self::assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function testCreateTableWithSpatialIndex() |
278
|
|
|
{ |
279
|
|
|
$table = new Table('spatial_table'); |
280
|
|
|
$table->addOption('engine', 'MyISAM'); |
281
|
|
|
$table->addColumn('point', 'text'); // This should be a point type |
282
|
|
|
$table->addIndex(array('point'), 'spatial_text'); |
283
|
|
|
|
284
|
|
|
$index = $table->getIndex('spatial_text'); |
285
|
|
|
$index->addFlag('spatial'); |
286
|
|
|
|
287
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
288
|
|
|
self::assertEquals(array('CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function testClobTypeDeclarationSQL() |
292
|
|
|
{ |
293
|
|
|
self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1))); |
294
|
|
|
self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255))); |
295
|
|
|
self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256))); |
296
|
|
|
self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535))); |
297
|
|
|
self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536))); |
298
|
|
|
self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215))); |
299
|
|
|
self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216))); |
300
|
|
|
self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array())); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function testBlobTypeDeclarationSQL() |
304
|
|
|
{ |
305
|
|
|
self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1))); |
306
|
|
|
self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255))); |
307
|
|
|
self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256))); |
308
|
|
|
self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535))); |
309
|
|
|
self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536))); |
310
|
|
|
self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215))); |
311
|
|
|
self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216))); |
312
|
|
|
self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array())); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @group DBAL-400 |
317
|
|
|
*/ |
318
|
|
|
public function testAlterTableAddPrimaryKey() |
319
|
|
|
{ |
320
|
|
|
$table = new Table('alter_table_add_pk'); |
321
|
|
|
$table->addColumn('id', 'integer'); |
322
|
|
|
$table->addColumn('foo', 'integer'); |
323
|
|
|
$table->addIndex(array('id'), 'idx_id'); |
324
|
|
|
|
325
|
|
|
$comparator = new Comparator(); |
326
|
|
|
$diffTable = clone $table; |
327
|
|
|
|
328
|
|
|
$diffTable->dropIndex('idx_id'); |
329
|
|
|
$diffTable->setPrimaryKey(array('id')); |
330
|
|
|
|
331
|
|
|
self::assertEquals( |
332
|
|
|
array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'), |
333
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
334
|
|
|
); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @group DBAL-1132 |
339
|
|
|
*/ |
340
|
|
|
public function testAlterPrimaryKeyWithAutoincrementColumn() |
341
|
|
|
{ |
342
|
|
|
$table = new Table("alter_primary_key"); |
343
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
344
|
|
|
$table->addColumn('foo', 'integer'); |
345
|
|
|
$table->setPrimaryKey(array('id')); |
346
|
|
|
|
347
|
|
|
$comparator = new Comparator(); |
348
|
|
|
$diffTable = clone $table; |
349
|
|
|
|
350
|
|
|
$diffTable->dropPrimaryKey(); |
351
|
|
|
$diffTable->setPrimaryKey(array('foo')); |
352
|
|
|
|
353
|
|
|
self::assertEquals( |
354
|
|
|
array( |
355
|
|
|
'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', |
356
|
|
|
'ALTER TABLE alter_primary_key DROP PRIMARY KEY', |
357
|
|
|
'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)' |
358
|
|
|
), |
359
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
360
|
|
|
); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @group DBAL-464 |
365
|
|
|
*/ |
366
|
|
|
public function testDropPrimaryKeyWithAutoincrementColumn() |
367
|
|
|
{ |
368
|
|
|
$table = new Table("drop_primary_key"); |
369
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
370
|
|
|
$table->addColumn('foo', 'integer'); |
371
|
|
|
$table->addColumn('bar', 'integer'); |
372
|
|
|
$table->setPrimaryKey(array('id', 'foo')); |
373
|
|
|
|
374
|
|
|
$comparator = new Comparator(); |
375
|
|
|
$diffTable = clone $table; |
376
|
|
|
|
377
|
|
|
$diffTable->dropPrimaryKey(); |
378
|
|
|
|
379
|
|
|
self::assertEquals( |
380
|
|
|
array( |
381
|
|
|
'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', |
382
|
|
|
'ALTER TABLE drop_primary_key DROP PRIMARY KEY' |
383
|
|
|
), |
384
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
385
|
|
|
); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* @group DBAL-2302 |
390
|
|
|
*/ |
391
|
|
|
public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() |
392
|
|
|
{ |
393
|
|
|
$table = new Table("tbl"); |
394
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
395
|
|
|
$table->addColumn('foo', 'integer'); |
396
|
|
|
$table->addColumn('bar', 'integer'); |
397
|
|
|
$table->setPrimaryKey(array('id', 'foo')); |
398
|
|
|
|
399
|
|
|
$comparator = new Comparator(); |
400
|
|
|
$diffTable = clone $table; |
401
|
|
|
|
402
|
|
|
$diffTable->dropPrimaryKey(); |
403
|
|
|
$diffTable->setPrimaryKey(array('id')); |
404
|
|
|
|
405
|
|
|
self::assertSame( |
406
|
|
|
array( |
407
|
|
|
'ALTER TABLE tbl MODIFY id INT NOT NULL', |
408
|
|
|
'ALTER TABLE tbl DROP PRIMARY KEY', |
409
|
|
|
'ALTER TABLE tbl ADD PRIMARY KEY (id)', |
410
|
|
|
), |
411
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
412
|
|
|
); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @group DBAL-2302 |
417
|
|
|
*/ |
418
|
|
|
public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() |
419
|
|
|
{ |
420
|
|
|
$table = new Table("tbl"); |
421
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
422
|
|
|
$table->addColumn('foo', 'integer'); |
423
|
|
|
$table->addColumn('bar', 'integer'); |
424
|
|
|
$table->setPrimaryKey(array('id')); |
425
|
|
|
|
426
|
|
|
$comparator = new Comparator(); |
427
|
|
|
$diffTable = clone $table; |
428
|
|
|
|
429
|
|
|
$diffTable->dropPrimaryKey(); |
430
|
|
|
$diffTable->setPrimaryKey(array('id', 'foo')); |
431
|
|
|
|
432
|
|
|
self::assertSame( |
433
|
|
|
array( |
434
|
|
|
'ALTER TABLE tbl MODIFY id INT NOT NULL', |
435
|
|
|
'ALTER TABLE tbl DROP PRIMARY KEY', |
436
|
|
|
'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', |
437
|
|
|
), |
438
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
439
|
|
|
); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @group DBAL-586 |
444
|
|
|
*/ |
445
|
|
|
public function testAddAutoIncrementPrimaryKey() |
446
|
|
|
{ |
447
|
|
|
$keyTable = new Table("foo"); |
448
|
|
|
$keyTable->addColumn("id", "integer", array('autoincrement' => true)); |
449
|
|
|
$keyTable->addColumn("baz", "string"); |
450
|
|
|
$keyTable->setPrimaryKey(array("id")); |
451
|
|
|
|
452
|
|
|
$oldTable = new Table("foo"); |
453
|
|
|
$oldTable->addColumn("baz", "string"); |
454
|
|
|
|
455
|
|
|
$c = new \Doctrine\DBAL\Schema\Comparator; |
456
|
|
|
$diff = $c->diffTable($oldTable, $keyTable); |
457
|
|
|
|
458
|
|
|
$sql = $this->_platform->getAlterTableSQL($diff); |
|
|
|
|
459
|
|
|
|
460
|
|
|
self::assertEquals(array( |
461
|
|
|
"ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)", |
462
|
|
|
), $sql); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
public function testNamedPrimaryKey() |
466
|
|
|
{ |
467
|
|
|
$diff = new TableDiff('mytable'); |
468
|
|
|
$diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true); |
469
|
|
|
|
470
|
|
|
$sql = $this->_platform->getAlterTableSQL($diff); |
471
|
|
|
|
472
|
|
|
self::assertEquals(array( |
473
|
|
|
"ALTER TABLE mytable DROP PRIMARY KEY", |
474
|
|
|
"ALTER TABLE mytable ADD PRIMARY KEY (foo)", |
475
|
|
|
), $sql); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
public function testAlterPrimaryKeyWithNewColumn() |
479
|
|
|
{ |
480
|
|
|
$table = new Table("yolo"); |
481
|
|
|
$table->addColumn('pkc1', 'integer'); |
482
|
|
|
$table->addColumn('col_a', 'integer'); |
483
|
|
|
$table->setPrimaryKey(array('pkc1')); |
484
|
|
|
|
485
|
|
|
$comparator = new Comparator(); |
486
|
|
|
$diffTable = clone $table; |
487
|
|
|
|
488
|
|
|
$diffTable->addColumn('pkc2', 'integer'); |
489
|
|
|
$diffTable->dropPrimaryKey(); |
490
|
|
|
$diffTable->setPrimaryKey(array('pkc1', 'pkc2')); |
491
|
|
|
|
492
|
|
|
self::assertSame( |
493
|
|
|
array( |
494
|
|
|
'ALTER TABLE yolo DROP PRIMARY KEY', |
495
|
|
|
'ALTER TABLE yolo ADD pkc2 INT NOT NULL', |
496
|
|
|
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', |
497
|
|
|
), |
498
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
|
|
|
|
499
|
|
|
); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
public function testInitializesDoctrineTypeMappings() |
503
|
|
|
{ |
504
|
|
|
self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary')); |
505
|
|
|
self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary')); |
506
|
|
|
|
507
|
|
|
self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary')); |
508
|
|
|
self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary')); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
protected function getBinaryMaxLength() |
512
|
|
|
{ |
513
|
|
|
return 65535; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
public function testReturnsBinaryTypeDeclarationSQL() |
517
|
|
|
{ |
518
|
|
|
self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); |
519
|
|
|
self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); |
520
|
|
|
self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535))); |
521
|
|
|
self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65536))); |
522
|
|
|
self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777215))); |
523
|
|
|
self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777216))); |
524
|
|
|
|
525
|
|
|
self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); |
526
|
|
|
self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); |
527
|
|
|
self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535))); |
528
|
|
|
self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65536))); |
529
|
|
|
self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777215))); |
530
|
|
|
self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777216))); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() |
534
|
|
|
{ |
535
|
|
|
$table = new Table("foreign_table"); |
536
|
|
|
$table->addColumn('id', 'integer'); |
537
|
|
|
$table->addColumn('fk_id', 'integer'); |
538
|
|
|
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); |
539
|
|
|
$table->setPrimaryKey(array('id')); |
540
|
|
|
$table->addOption('engine', 'MyISAM'); |
541
|
|
|
|
542
|
|
|
self::assertSame( |
543
|
|
|
array('CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), |
544
|
|
|
$this->_platform->getCreateTableSQL( |
545
|
|
|
$table, |
546
|
|
|
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS |
547
|
|
|
) |
548
|
|
|
); |
549
|
|
|
|
550
|
|
|
$table = clone $table; |
551
|
|
|
$table->addOption('engine', 'InnoDB'); |
552
|
|
|
|
553
|
|
|
self::assertSame( |
554
|
|
|
array( |
555
|
|
|
'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
556
|
|
|
'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)' |
557
|
|
|
), |
558
|
|
|
$this->_platform->getCreateTableSQL( |
559
|
|
|
$table, |
560
|
|
|
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS |
561
|
|
|
) |
562
|
|
|
); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() |
566
|
|
|
{ |
567
|
|
|
$table = new Table("foreign_table"); |
568
|
|
|
$table->addColumn('id', 'integer'); |
569
|
|
|
$table->addColumn('fk_id', 'integer'); |
570
|
|
|
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); |
571
|
|
|
$table->setPrimaryKey(array('id')); |
572
|
|
|
$table->addOption('engine', 'MyISAM'); |
573
|
|
|
|
574
|
|
|
$addedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add')); |
575
|
|
|
$changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change')); |
576
|
|
|
$removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove')); |
577
|
|
|
|
578
|
|
|
$tableDiff = new TableDiff('foreign_table'); |
579
|
|
|
$tableDiff->fromTable = $table; |
580
|
|
|
$tableDiff->addedForeignKeys = $addedForeignKeys; |
581
|
|
|
$tableDiff->changedForeignKeys = $changedForeignKeys; |
582
|
|
|
$tableDiff->removedForeignKeys = $removedForeignKeys; |
583
|
|
|
|
584
|
|
|
self::assertEmpty($this->_platform->getAlterTableSQL($tableDiff)); |
585
|
|
|
|
586
|
|
|
$table->addOption('engine', 'InnoDB'); |
587
|
|
|
|
588
|
|
|
$tableDiff = new TableDiff('foreign_table'); |
589
|
|
|
$tableDiff->fromTable = $table; |
590
|
|
|
$tableDiff->addedForeignKeys = $addedForeignKeys; |
591
|
|
|
$tableDiff->changedForeignKeys = $changedForeignKeys; |
592
|
|
|
$tableDiff->removedForeignKeys = $removedForeignKeys; |
593
|
|
|
|
594
|
|
|
self::assertSame( |
595
|
|
|
array( |
596
|
|
|
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove', |
597
|
|
|
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change', |
598
|
|
|
'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)', |
599
|
|
|
'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)', |
600
|
|
|
), |
601
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
602
|
|
|
); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* @group DBAL-234 |
607
|
|
|
*/ |
608
|
|
|
protected function getAlterTableRenameIndexSQL() |
609
|
|
|
{ |
610
|
|
|
return array( |
611
|
|
|
'DROP INDEX idx_foo ON mytable', |
612
|
|
|
'CREATE INDEX idx_bar ON mytable (id)', |
613
|
|
|
); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* @group DBAL-234 |
618
|
|
|
*/ |
619
|
|
|
protected function getQuotedAlterTableRenameIndexSQL() |
620
|
|
|
{ |
621
|
|
|
return array( |
622
|
|
|
'DROP INDEX `create` ON `table`', |
623
|
|
|
'CREATE INDEX `select` ON `table` (id)', |
624
|
|
|
'DROP INDEX `foo` ON `table`', |
625
|
|
|
'CREATE INDEX `bar` ON `table` (id)', |
626
|
|
|
); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* @group DBAL-807 |
631
|
|
|
*/ |
632
|
|
|
protected function getAlterTableRenameIndexInSchemaSQL() |
633
|
|
|
{ |
634
|
|
|
return array( |
635
|
|
|
'DROP INDEX idx_foo ON myschema.mytable', |
636
|
|
|
'CREATE INDEX idx_bar ON myschema.mytable (id)', |
637
|
|
|
); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* @group DBAL-807 |
642
|
|
|
*/ |
643
|
|
|
protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
644
|
|
|
{ |
645
|
|
|
return array( |
646
|
|
|
'DROP INDEX `create` ON `schema`.`table`', |
647
|
|
|
'CREATE INDEX `select` ON `schema`.`table` (id)', |
648
|
|
|
'DROP INDEX `foo` ON `schema`.`table`', |
649
|
|
|
'CREATE INDEX `bar` ON `schema`.`table` (id)', |
650
|
|
|
); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
protected function getQuotesDropForeignKeySQL() |
654
|
|
|
{ |
655
|
|
|
return 'ALTER TABLE `table` DROP FOREIGN KEY `select`'; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
protected function getQuotesDropConstraintSQL() |
659
|
|
|
{ |
660
|
|
|
return 'ALTER TABLE `table` DROP CONSTRAINT `select`'; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() |
664
|
|
|
{ |
665
|
|
|
$table = new Table("text_blob_default_value"); |
666
|
|
|
$table->addColumn('def_text', 'text', array('default' => 'def')); |
667
|
|
|
$table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def')); |
668
|
|
|
$table->addColumn('def_blob', 'blob', array('default' => 'def')); |
669
|
|
|
$table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def')); |
670
|
|
|
|
671
|
|
|
self::assertSame( |
672
|
|
|
array('CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'), |
673
|
|
|
$this->_platform->getCreateTableSQL($table) |
674
|
|
|
); |
675
|
|
|
|
676
|
|
|
$diffTable = clone $table; |
677
|
|
|
$diffTable->changeColumn('def_text', array('default' => null)); |
678
|
|
|
$diffTable->changeColumn('def_text_null', array('default' => null)); |
679
|
|
|
$diffTable->changeColumn('def_blob', array('default' => null)); |
680
|
|
|
$diffTable->changeColumn('def_blob_null', array('default' => null)); |
681
|
|
|
|
682
|
|
|
$comparator = new Comparator(); |
683
|
|
|
|
684
|
|
|
self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); |
|
|
|
|
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
/** |
688
|
|
|
* {@inheritdoc} |
689
|
|
|
*/ |
690
|
|
|
protected function getQuotedAlterTableRenameColumnSQL() |
691
|
|
|
{ |
692
|
|
|
return array( |
693
|
|
|
"ALTER TABLE mytable " . |
694
|
|
|
"CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . |
695
|
|
|
"CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " . |
696
|
|
|
"CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " . |
697
|
|
|
"CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " . |
698
|
|
|
"CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " . |
699
|
|
|
"CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " . |
700
|
|
|
"CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " . |
701
|
|
|
"CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " . |
702
|
|
|
"CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'" |
703
|
|
|
); |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
/** |
707
|
|
|
* {@inheritdoc} |
708
|
|
|
*/ |
709
|
|
|
protected function getQuotedAlterTableChangeColumnLengthSQL() |
710
|
|
|
{ |
711
|
|
|
return array( |
712
|
|
|
"ALTER TABLE mytable " . |
713
|
|
|
"CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . |
714
|
|
|
"CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . |
715
|
|
|
"CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . |
716
|
|
|
"CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . |
717
|
|
|
"CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . |
718
|
|
|
"CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'" |
719
|
|
|
); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* @group DBAL-423 |
724
|
|
|
*/ |
725
|
|
|
public function testReturnsGuidTypeDeclarationSQL() |
726
|
|
|
{ |
727
|
|
|
self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
/** |
731
|
|
|
* {@inheritdoc} |
732
|
|
|
*/ |
733
|
|
|
public function getAlterTableRenameColumnSQL() |
734
|
|
|
{ |
735
|
|
|
return array( |
736
|
|
|
"ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'", |
737
|
|
|
); |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
/** |
741
|
|
|
* {@inheritdoc} |
742
|
|
|
*/ |
743
|
|
|
protected function getQuotesTableIdentifiersInAlterTableSQL() |
744
|
|
|
{ |
745
|
|
|
return array( |
746
|
|
|
'ALTER TABLE `foo` DROP FOREIGN KEY fk1', |
747
|
|
|
'ALTER TABLE `foo` DROP FOREIGN KEY fk2', |
748
|
|
|
'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' . |
749
|
|
|
'CHANGE id war INT NOT NULL', |
750
|
|
|
'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', |
751
|
|
|
'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', |
752
|
|
|
); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* {@inheritdoc} |
757
|
|
|
*/ |
758
|
|
|
protected function getCommentOnColumnSQL() |
759
|
|
|
{ |
760
|
|
|
return array( |
761
|
|
|
"COMMENT ON COLUMN foo.bar IS 'comment'", |
762
|
|
|
"COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'", |
763
|
|
|
"COMMENT ON COLUMN `select`.`from` IS 'comment'", |
764
|
|
|
); |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
/** |
768
|
|
|
* {@inheritdoc} |
769
|
|
|
*/ |
770
|
|
|
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
771
|
|
|
{ |
772
|
|
|
return 'CONSTRAINT `select` UNIQUE (foo)'; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* {@inheritdoc} |
777
|
|
|
*/ |
778
|
|
|
protected function getQuotesReservedKeywordInIndexDeclarationSQL() |
779
|
|
|
{ |
780
|
|
|
return 'INDEX `select` (foo)'; |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* {@inheritdoc} |
785
|
|
|
*/ |
786
|
|
|
protected function getQuotesReservedKeywordInTruncateTableSQL() |
787
|
|
|
{ |
788
|
|
|
return 'TRUNCATE `select`'; |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
/** |
792
|
|
|
* {@inheritdoc} |
793
|
|
|
*/ |
794
|
|
|
protected function getAlterStringToFixedStringSQL() |
795
|
|
|
{ |
796
|
|
|
return array( |
797
|
|
|
'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL', |
798
|
|
|
); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
/** |
802
|
|
|
* {@inheritdoc} |
803
|
|
|
*/ |
804
|
|
|
protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
805
|
|
|
{ |
806
|
|
|
return array( |
807
|
|
|
'ALTER TABLE mytable DROP FOREIGN KEY fk_foo', |
808
|
|
|
'DROP INDEX idx_foo ON mytable', |
809
|
|
|
'CREATE INDEX idx_foo_renamed ON mytable (foo)', |
810
|
|
|
'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)', |
811
|
|
|
); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* {@inheritdoc} |
816
|
|
|
*/ |
817
|
|
|
public function getGeneratesDecimalTypeDeclarationSQL() |
818
|
|
|
{ |
819
|
|
|
return array( |
820
|
|
|
array(array(), 'NUMERIC(10, 0)'), |
821
|
|
|
array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'), |
822
|
|
|
array(array('unsigned' => false), 'NUMERIC(10, 0)'), |
823
|
|
|
array(array('precision' => 5), 'NUMERIC(5, 0)'), |
824
|
|
|
array(array('scale' => 5), 'NUMERIC(10, 5)'), |
825
|
|
|
array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), |
826
|
|
|
); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* {@inheritdoc} |
831
|
|
|
*/ |
832
|
|
|
public function getGeneratesFloatDeclarationSQL() |
833
|
|
|
{ |
834
|
|
|
return array( |
835
|
|
|
array(array(), 'DOUBLE PRECISION'), |
836
|
|
|
array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'), |
837
|
|
|
array(array('unsigned' => false), 'DOUBLE PRECISION'), |
838
|
|
|
array(array('precision' => 5), 'DOUBLE PRECISION'), |
839
|
|
|
array(array('scale' => 5), 'DOUBLE PRECISION'), |
840
|
|
|
array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), |
841
|
|
|
); |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* @group DBAL-2436 |
846
|
|
|
*/ |
847
|
|
|
public function testQuotesTableNameInListTableIndexesSQL() |
848
|
|
|
{ |
849
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true); |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
/** |
853
|
|
|
* @group DBAL-2436 |
854
|
|
|
*/ |
855
|
|
|
public function testQuotesDatabaseNameInListTableIndexesSQL() |
856
|
|
|
{ |
857
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* @group DBAL-2436 |
862
|
|
|
*/ |
863
|
|
|
public function testQuotesDatabaseNameInListViewsSQL() |
864
|
|
|
{ |
865
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListViewsSQL("Foo'Bar\\"), '', true); |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
/** |
869
|
|
|
* @group DBAL-2436 |
870
|
|
|
*/ |
871
|
|
|
public function testQuotesTableNameInListTableForeignKeysSQL() |
872
|
|
|
{ |
873
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
/** |
877
|
|
|
* @group DBAL-2436 |
878
|
|
|
*/ |
879
|
|
|
public function testQuotesDatabaseNameInListTableForeignKeysSQL() |
880
|
|
|
{ |
881
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true); |
|
|
|
|
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* @group DBAL-2436 |
886
|
|
|
*/ |
887
|
|
|
public function testQuotesTableNameInListTableColumnsSQL() |
888
|
|
|
{ |
889
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
/** |
893
|
|
|
* @group DBAL-2436 |
894
|
|
|
*/ |
895
|
|
|
public function testQuotesDatabaseNameInListTableColumnsSQL() |
896
|
|
|
{ |
897
|
|
|
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
public function testListTableForeignKeysSQLEvaluatesDatabase() |
901
|
|
|
{ |
902
|
|
|
$sql = $this->_platform->getListTableForeignKeysSQL('foo'); |
903
|
|
|
|
904
|
|
|
self::assertContains('DATABASE()', $sql); |
905
|
|
|
|
906
|
|
|
$sql = $this->_platform->getListTableForeignKeysSQL('foo', 'bar'); |
907
|
|
|
|
908
|
|
|
self::assertContains('bar', $sql); |
909
|
|
|
self::assertNotContains('DATABASE()', $sql); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
public function testSupportsColumnCollation() : void |
913
|
|
|
{ |
914
|
|
|
self::assertTrue($this->_platform->supportsColumnCollation()); |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
public function testColumnCollationDeclarationSQL() : void |
918
|
|
|
{ |
919
|
|
|
self::assertSame( |
920
|
|
|
'COLLATE ascii_general_ci', |
921
|
|
|
$this->_platform->getColumnCollationDeclarationSQL('ascii_general_ci') |
922
|
|
|
); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
public function testGetCreateTableSQLWithColumnCollation() : void |
926
|
|
|
{ |
927
|
|
|
$table = new Table('foo'); |
928
|
|
|
$table->addColumn('no_collation', 'string'); |
929
|
|
|
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci'); |
930
|
|
|
|
931
|
|
|
self::assertSame( |
932
|
|
|
['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE ascii_general_ci) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'], |
933
|
|
|
$this->_platform->getCreateTableSQL($table), |
934
|
|
|
'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column' |
935
|
|
|
); |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
|