1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Schema; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\MariaDb1027Platform; |
6
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform; |
7
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
8
|
|
|
use Doctrine\DBAL\Schema\Schema; |
9
|
|
|
use Doctrine\DBAL\Schema\Table; |
10
|
|
|
use Doctrine\DBAL\Types\Type; |
11
|
|
|
use Doctrine\Tests\Types\MySqlPointType; |
12
|
|
|
|
13
|
|
|
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
if (!Type::hasType('point')) { |
21
|
|
|
Type::addType('point', MySqlPointType::class); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testSwitchPrimaryKeyColumns() |
26
|
|
|
{ |
27
|
|
|
$tableOld = new Table("switch_primary_key_columns"); |
28
|
|
|
$tableOld->addColumn('foo_id', 'integer'); |
29
|
|
|
$tableOld->addColumn('bar_id', 'integer'); |
30
|
|
|
|
31
|
|
|
$this->_sm->createTable($tableOld); |
32
|
|
|
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns"); |
33
|
|
|
$tableNew = clone $tableFetched; |
34
|
|
|
$tableNew->setPrimaryKey(array('bar_id', 'foo_id')); |
35
|
|
|
|
36
|
|
|
$comparator = new Comparator; |
37
|
|
|
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$table = $this->_sm->listTableDetails('switch_primary_key_columns'); |
40
|
|
|
$primaryKey = $table->getPrimaryKeyColumns(); |
41
|
|
|
|
42
|
|
|
self::assertCount(2, $primaryKey); |
43
|
|
|
self::assertContains('bar_id', $primaryKey); |
44
|
|
|
self::assertContains('foo_id', $primaryKey); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testDiffTableBug() |
48
|
|
|
{ |
49
|
|
|
$schema = new Schema(); |
50
|
|
|
$table = $schema->createTable('diffbug_routing_translations'); |
51
|
|
|
$table->addColumn('id', 'integer'); |
52
|
|
|
$table->addColumn('route', 'string'); |
53
|
|
|
$table->addColumn('locale', 'string'); |
54
|
|
|
$table->addColumn('attribute', 'string'); |
55
|
|
|
$table->addColumn('localized_value', 'string'); |
56
|
|
|
$table->addColumn('original_value', 'string'); |
57
|
|
|
$table->setPrimaryKey(array('id')); |
58
|
|
|
$table->addUniqueIndex(array('route', 'locale', 'attribute')); |
59
|
|
|
$table->addIndex(array('localized_value')); // this is much more selective than the unique index |
60
|
|
|
|
61
|
|
|
$this->_sm->createTable($table); |
62
|
|
|
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations"); |
63
|
|
|
|
64
|
|
|
$comparator = new Comparator; |
65
|
|
|
$diff = $comparator->diffTable($tableFetched, $table); |
66
|
|
|
|
67
|
|
|
self::assertFalse($diff, "no changes expected."); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function testFulltextIndex() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$table = new Table('fulltext_index'); |
73
|
|
|
$table->addColumn('text', 'text'); |
74
|
|
|
$table->addIndex(array('text'), 'f_index'); |
75
|
|
|
$table->addOption('engine', 'MyISAM'); |
76
|
|
|
|
77
|
|
|
$index = $table->getIndex('f_index'); |
78
|
|
|
$index->addFlag('fulltext'); |
79
|
|
|
|
80
|
|
|
$this->_sm->dropAndCreateTable($table); |
81
|
|
|
|
82
|
|
|
$indexes = $this->_sm->listTableIndexes('fulltext_index'); |
83
|
|
|
self::assertArrayHasKey('f_index', $indexes); |
84
|
|
|
self::assertTrue($indexes['f_index']->hasFlag('fulltext')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function testSpatialIndex() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$table = new Table('spatial_index'); |
90
|
|
|
$table->addColumn('point', 'point'); |
91
|
|
|
$table->addIndex(array('point'), 's_index'); |
92
|
|
|
$table->addOption('engine', 'MyISAM'); |
93
|
|
|
|
94
|
|
|
$index = $table->getIndex('s_index'); |
95
|
|
|
$index->addFlag('spatial'); |
96
|
|
|
|
97
|
|
|
$this->_sm->dropAndCreateTable($table); |
98
|
|
|
|
99
|
|
|
$indexes = $this->_sm->listTableIndexes('spatial_index'); |
100
|
|
|
self::assertArrayHasKey('s_index', $indexes); |
101
|
|
|
self::assertTrue($indexes['s_index']->hasFlag('spatial')); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @group DBAL-400 |
106
|
|
|
*/ |
107
|
|
|
public function testAlterTableAddPrimaryKey() |
108
|
|
|
{ |
109
|
|
|
$table = new Table('alter_table_add_pk'); |
110
|
|
|
$table->addColumn('id', 'integer'); |
111
|
|
|
$table->addColumn('foo', 'integer'); |
112
|
|
|
$table->addIndex(array('id'), 'idx_id'); |
113
|
|
|
|
114
|
|
|
$this->_sm->createTable($table); |
115
|
|
|
|
116
|
|
|
$comparator = new Comparator(); |
117
|
|
|
$diffTable = clone $table; |
118
|
|
|
|
119
|
|
|
$diffTable->dropIndex('idx_id'); |
120
|
|
|
$diffTable->setPrimaryKey(array('id')); |
121
|
|
|
|
122
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $diffTable)); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$table = $this->_sm->listTableDetails("alter_table_add_pk"); |
125
|
|
|
|
126
|
|
|
self::assertFalse($table->hasIndex('idx_id')); |
127
|
|
|
self::assertTrue($table->hasPrimaryKey()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @group DBAL-464 |
132
|
|
|
*/ |
133
|
|
|
public function testDropPrimaryKeyWithAutoincrementColumn() |
134
|
|
|
{ |
135
|
|
|
$table = new Table("drop_primary_key"); |
136
|
|
|
$table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true)); |
137
|
|
|
$table->addColumn('foo', 'integer', array('primary' => true)); |
138
|
|
|
$table->setPrimaryKey(array('id', 'foo')); |
139
|
|
|
|
140
|
|
|
$this->_sm->dropAndCreateTable($table); |
141
|
|
|
|
142
|
|
|
$diffTable = clone $table; |
143
|
|
|
|
144
|
|
|
$diffTable->dropPrimaryKey(); |
145
|
|
|
|
146
|
|
|
$comparator = new Comparator(); |
147
|
|
|
|
148
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $diffTable)); |
|
|
|
|
149
|
|
|
|
150
|
|
|
$table = $this->_sm->listTableDetails("drop_primary_key"); |
151
|
|
|
|
152
|
|
|
self::assertFalse($table->hasPrimaryKey()); |
153
|
|
|
self::assertFalse($table->getColumn('id')->getAutoincrement()); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @group DBAL-789 |
158
|
|
|
*/ |
159
|
|
|
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() |
160
|
|
|
{ |
161
|
|
|
if ($this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { |
162
|
|
|
$this->markTestSkipped( |
163
|
|
|
'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values' |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$table = new Table("text_blob_default_value"); |
168
|
|
|
$table->addColumn('def_text', 'text', ['default' => 'def']); |
169
|
|
|
$table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); |
170
|
|
|
$table->addColumn('def_blob', 'blob', ['default' => 'def']); |
171
|
|
|
$table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); |
172
|
|
|
|
173
|
|
|
$this->_sm->dropAndCreateTable($table); |
174
|
|
|
|
175
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
176
|
|
|
|
177
|
|
|
self::assertNull($onlineTable->getColumn('def_text')->getDefault()); |
178
|
|
|
self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
179
|
|
|
self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
180
|
|
|
self::assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
181
|
|
|
self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
182
|
|
|
self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
183
|
|
|
|
184
|
|
|
$comparator = new Comparator(); |
185
|
|
|
|
186
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); |
|
|
|
|
187
|
|
|
|
188
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
189
|
|
|
|
190
|
|
|
self::assertNull($onlineTable->getColumn('def_text')->getDefault()); |
191
|
|
|
self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
192
|
|
|
self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
193
|
|
|
self::assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
194
|
|
|
self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
195
|
|
|
self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
View Code Duplication |
public function testColumnCollation() |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
$table = new Table('test_collation'); |
201
|
|
|
$table->addOption('collate', $collation = 'latin1_swedish_ci'); |
202
|
|
|
$table->addOption('charset', 'latin1'); |
203
|
|
|
$table->addColumn('id', 'integer'); |
204
|
|
|
$table->addColumn('text', 'text'); |
205
|
|
|
$table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); |
206
|
|
|
$table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); |
207
|
|
|
$this->_sm->dropAndCreateTable($table); |
208
|
|
|
|
209
|
|
|
$columns = $this->_sm->listTableColumns('test_collation'); |
210
|
|
|
|
211
|
|
|
self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); |
212
|
|
|
self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); |
213
|
|
|
self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation')); |
214
|
|
|
self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation')); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @group DBAL-843 |
219
|
|
|
*/ |
220
|
|
|
public function testListLobTypeColumns() |
221
|
|
|
{ |
222
|
|
|
$tableName = 'lob_type_columns'; |
223
|
|
|
$table = new Table($tableName); |
224
|
|
|
|
225
|
|
|
$table->addColumn('col_tinytext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT)); |
226
|
|
|
$table->addColumn('col_text', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TEXT)); |
227
|
|
|
$table->addColumn('col_mediumtext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT)); |
228
|
|
|
$table->addColumn('col_longtext', 'text'); |
229
|
|
|
|
230
|
|
|
$table->addColumn('col_tinyblob', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB)); |
231
|
|
|
$table->addColumn('col_blob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_BLOB)); |
232
|
|
|
$table->addColumn('col_mediumblob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB)); |
233
|
|
|
$table->addColumn('col_longblob', 'blob'); |
234
|
|
|
|
235
|
|
|
$this->_sm->dropAndCreateTable($table); |
236
|
|
|
|
237
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
238
|
|
|
$offlineColumns = $table->getColumns(); |
239
|
|
|
$onlineColumns = $this->_sm->listTableColumns($tableName); |
240
|
|
|
|
241
|
|
|
self::assertSame( |
242
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), |
243
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_tinytext']->toArray()) |
244
|
|
|
); |
245
|
|
|
self::assertSame( |
246
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_text']->toArray()), |
247
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_text']->toArray()) |
248
|
|
|
); |
249
|
|
|
self::assertSame( |
250
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_mediumtext']->toArray()), |
251
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_mediumtext']->toArray()) |
252
|
|
|
); |
253
|
|
|
self::assertSame( |
254
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_longtext']->toArray()), |
255
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_longtext']->toArray()) |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
self::assertSame( |
259
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_tinyblob']->toArray()), |
260
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_tinyblob']->toArray()) |
261
|
|
|
); |
262
|
|
|
self::assertSame( |
263
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_blob']->toArray()), |
264
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_blob']->toArray()) |
265
|
|
|
); |
266
|
|
|
self::assertSame( |
267
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_mediumblob']->toArray()), |
268
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_mediumblob']->toArray()) |
269
|
|
|
); |
270
|
|
|
self::assertSame( |
271
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_longblob']->toArray()), |
272
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_longblob']->toArray()) |
273
|
|
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @group DBAL-423 |
278
|
|
|
*/ |
279
|
|
View Code Duplication |
public function testDiffListGuidTableColumn() |
|
|
|
|
280
|
|
|
{ |
281
|
|
|
$offlineTable = new Table('list_guid_table_column'); |
282
|
|
|
$offlineTable->addColumn('col_guid', 'guid'); |
283
|
|
|
|
284
|
|
|
$this->_sm->dropAndCreateTable($offlineTable); |
285
|
|
|
|
286
|
|
|
$onlineTable = $this->_sm->listTableDetails('list_guid_table_column'); |
287
|
|
|
|
288
|
|
|
$comparator = new Comparator(); |
289
|
|
|
|
290
|
|
|
self::assertFalse( |
291
|
|
|
$comparator->diffTable($offlineTable, $onlineTable), |
292
|
|
|
"No differences should be detected with the offline vs online schema." |
293
|
|
|
); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @group DBAL-1082 |
298
|
|
|
*/ |
299
|
|
View Code Duplication |
public function testListDecimalTypeColumns() |
|
|
|
|
300
|
|
|
{ |
301
|
|
|
$tableName = 'test_list_decimal_columns'; |
302
|
|
|
$table = new Table($tableName); |
303
|
|
|
|
304
|
|
|
$table->addColumn('col', 'decimal'); |
305
|
|
|
$table->addColumn('col_unsigned', 'decimal', array('unsigned' => true)); |
306
|
|
|
|
307
|
|
|
$this->_sm->dropAndCreateTable($table); |
308
|
|
|
|
309
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
310
|
|
|
|
311
|
|
|
self::assertArrayHasKey('col', $columns); |
312
|
|
|
self::assertArrayHasKey('col_unsigned', $columns); |
313
|
|
|
self::assertFalse($columns['col']->getUnsigned()); |
314
|
|
|
self::assertTrue($columns['col_unsigned']->getUnsigned()); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @group DBAL-1082 |
319
|
|
|
*/ |
320
|
|
View Code Duplication |
public function testListFloatTypeColumns() |
|
|
|
|
321
|
|
|
{ |
322
|
|
|
$tableName = 'test_list_float_columns'; |
323
|
|
|
$table = new Table($tableName); |
324
|
|
|
|
325
|
|
|
$table->addColumn('col', 'float'); |
326
|
|
|
$table->addColumn('col_unsigned', 'float', array('unsigned' => true)); |
327
|
|
|
|
328
|
|
|
$this->_sm->dropAndCreateTable($table); |
329
|
|
|
|
330
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
331
|
|
|
|
332
|
|
|
self::assertArrayHasKey('col', $columns); |
333
|
|
|
self::assertArrayHasKey('col_unsigned', $columns); |
334
|
|
|
self::assertFalse($columns['col']->getUnsigned()); |
335
|
|
|
self::assertTrue($columns['col_unsigned']->getUnsigned()); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
View Code Duplication |
public function testJsonColumnType() : void |
|
|
|
|
339
|
|
|
{ |
340
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
341
|
|
|
if ( ! $platform->hasNativeJsonType()) { |
342
|
|
|
$this->markTestSkipped("Requires native JSON type"); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
$table = new Table('test_mysql_json'); |
346
|
|
|
$table->addColumn('col_json', 'json'); |
347
|
|
|
$this->_sm->dropAndCreateTable($table); |
348
|
|
|
|
349
|
|
|
$columns = $this->_sm->listTableColumns('test_mysql_json'); |
350
|
|
|
|
351
|
|
|
self::assertSame(TYPE::JSON, $columns['col_json']->getType()->getName()); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
public function testColumnDefaultCurrentTimestamp() : void |
355
|
|
|
{ |
356
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
357
|
|
|
|
358
|
|
|
$table = new Table("test_column_defaults_current_timestamp"); |
359
|
|
|
|
360
|
|
|
$currentTimeStampSql = $platform->getCurrentTimestampSQL(); |
361
|
|
|
|
362
|
|
|
$table->addColumn('col_datetime', 'datetime', ['notnull' => true, 'default' => $currentTimeStampSql]); |
363
|
|
|
$table->addColumn('col_datetime_nullable', 'datetime', ['default' => $currentTimeStampSql]); |
364
|
|
|
|
365
|
|
|
$this->_sm->dropAndCreateTable($table); |
366
|
|
|
|
367
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_timestamp"); |
368
|
|
|
self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault()); |
369
|
|
|
self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault()); |
370
|
|
|
|
371
|
|
|
$comparator = new Comparator(); |
372
|
|
|
|
373
|
|
|
$diff = $comparator->diffTable($table, $onlineTable); |
374
|
|
|
self::assertFalse($diff, "Tables should be identical with column defaults."); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
public function testColumnDefaultsAreValid() |
378
|
|
|
{ |
379
|
|
|
$table = new Table("test_column_defaults_are_valid"); |
380
|
|
|
|
381
|
|
|
$currentTimeStampSql = $this->_sm->getDatabasePlatform()->getCurrentTimestampSQL(); |
382
|
|
|
$table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]); |
383
|
|
|
$table->addColumn('col_datetime_null', 'datetime', ['notnull' => false, 'default' => null]); |
384
|
|
|
$table->addColumn('col_int', 'integer', ['default' => 1]); |
385
|
|
|
$table->addColumn('col_neg_int', 'integer', ['default' => -1]); |
386
|
|
|
$table->addColumn('col_string', 'string', ['default' => 'A']); |
387
|
|
|
$table->addColumn('col_decimal', 'decimal', ['scale' => 3, 'precision' => 6, 'default' => -2.3]); |
388
|
|
|
$table->addColumn('col_date', 'date', ['default' => '2012-12-12']); |
389
|
|
|
|
390
|
|
|
$this->_sm->dropAndCreateTable($table); |
391
|
|
|
|
392
|
|
|
$this->_conn->executeUpdate( |
393
|
|
|
"INSERT INTO test_column_defaults_are_valid () VALUES()" |
394
|
|
|
); |
395
|
|
|
|
396
|
|
|
$row = $this->_conn->fetchAssoc( |
397
|
|
|
'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' |
398
|
|
|
); |
399
|
|
|
|
400
|
|
|
self::assertInstanceOf(\DateTime::class, \DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); |
401
|
|
|
self::assertNull($row['col_datetime_null']); |
402
|
|
|
self::assertSame('2012-12-12', $row['col_date']); |
403
|
|
|
self::assertSame('A', $row['col_string']); |
404
|
|
|
self::assertEquals(1, $row['col_int']); |
405
|
|
|
self::assertEquals(-1, $row['col_neg_int']); |
406
|
|
|
self::assertEquals('-2.300', $row['col_decimal']); |
407
|
|
|
self::assertLessThan(5, $row['diff_seconds']); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* MariaDB 10.2+ does support CURRENT_TIME and CURRENT_DATE as |
412
|
|
|
* column default values for time and date columns. |
413
|
|
|
* (Not supported on Mysql as of 5.7.19) |
414
|
|
|
* |
415
|
|
|
* Note that MariaDB 10.2+, when storing default in information_schema, |
416
|
|
|
* silently change CURRENT_TIMESTAMP as 'current_timestamp()', |
417
|
|
|
* CURRENT_TIME as 'currtime()' and CURRENT_DATE as 'currdate()'. |
418
|
|
|
* This test also ensure proper aliasing to not trigger a table diff. |
419
|
|
|
*/ |
420
|
|
|
public function testColumnDefaultValuesCurrentTimeAndDate() : void |
421
|
|
|
{ |
422
|
|
|
if ( ! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { |
423
|
|
|
$this->markTestSkipped('Only relevant for MariaDb102Platform.'); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
427
|
|
|
|
428
|
|
|
$table = new Table("test_column_defaults_current_time_and_date"); |
429
|
|
|
|
430
|
|
|
$currentTimestampSql = $platform->getCurrentTimestampSQL(); |
431
|
|
|
$currentTimeSql = $platform->getCurrentTimeSQL(); |
432
|
|
|
$currentDateSql = $platform->getCurrentDateSQL(); |
433
|
|
|
|
434
|
|
|
$table->addColumn('col_datetime', 'datetime', ['default' => $currentTimestampSql]); |
435
|
|
|
$table->addColumn('col_date', 'date', ['default' => $currentDateSql]); |
436
|
|
|
$table->addColumn('col_time', 'time', ['default' => $currentTimeSql]); |
437
|
|
|
|
438
|
|
|
$this->_sm->dropAndCreateTable($table); |
439
|
|
|
|
440
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_time_and_date"); |
441
|
|
|
|
442
|
|
|
self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault()); |
443
|
|
|
self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault()); |
444
|
|
|
self::assertSame($currentTimeSql, $onlineTable->getColumn('col_time')->getDefault()); |
445
|
|
|
|
446
|
|
|
$comparator = new Comparator(); |
447
|
|
|
|
448
|
|
|
$diff = $comparator->diffTable($table, $onlineTable); |
449
|
|
|
self::assertFalse($diff, "Tables should be identical with column defauts time and date."); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Ensure default values (un-)escaping is properly done by mysql platforms. |
454
|
|
|
* The test is voluntarily relying on schema introspection due to current |
455
|
|
|
* doctrine limitations. Once #2850 is landed, this test can be removed. |
456
|
|
|
* @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html |
457
|
|
|
*/ |
458
|
|
|
public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void |
459
|
|
|
{ |
460
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
461
|
|
|
$this->_conn->query('DROP TABLE IF EXISTS test_column_defaults_with_create'); |
462
|
|
|
|
463
|
|
|
$escapeSequences = [ |
464
|
|
|
"\\0", // An ASCII NUL (X'00') character |
465
|
|
|
"\\'", "''", // Single quote |
466
|
|
|
'\\"', '""', // Double quote |
467
|
|
|
'\\b', // A backspace character |
468
|
|
|
'\\n', // A new-line character |
469
|
|
|
'\\r', // A carriage return character |
470
|
|
|
'\\t', // A tab character |
471
|
|
|
'\\Z', // ASCII 26 (Control+Z) |
472
|
|
|
'\\\\', // A backslash (\) character |
473
|
|
|
'\\%', // A percent (%) character |
474
|
|
|
'\\_', // An underscore (_) character |
475
|
|
|
]; |
476
|
|
|
|
477
|
|
|
$default = implode('+', $escapeSequences); |
478
|
|
|
|
479
|
|
|
$sql = "CREATE TABLE test_column_defaults_with_create( |
480
|
|
|
col1 VARCHAR(255) NULL DEFAULT {$platform->quoteStringLiteral($default)} |
481
|
|
|
)"; |
482
|
|
|
$this->_conn->query($sql); |
483
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_create"); |
484
|
|
|
self::assertSame($default, $onlineTable->getColumn('col1')->getDefault()); |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
|