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('MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
$table = new Table("text_blob_default_value"); |
166
|
|
|
$table->addColumn('def_text', 'text', ['default' => 'def']); |
167
|
|
|
$table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); |
168
|
|
|
$table->addColumn('def_blob', 'blob', ['default' => 'def']); |
169
|
|
|
$table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); |
170
|
|
|
|
171
|
|
|
$this->_sm->dropAndCreateTable($table); |
172
|
|
|
|
173
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
174
|
|
|
|
175
|
|
|
self::assertNull($onlineTable->getColumn('def_text')->getDefault()); |
176
|
|
|
self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
177
|
|
|
self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
178
|
|
|
self::assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
179
|
|
|
self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
180
|
|
|
self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
181
|
|
|
|
182
|
|
|
$comparator = new Comparator(); |
183
|
|
|
|
184
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); |
|
|
|
|
185
|
|
|
|
186
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
187
|
|
|
|
188
|
|
|
self::assertNull($onlineTable->getColumn('def_text')->getDefault()); |
189
|
|
|
self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
190
|
|
|
self::assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
191
|
|
|
self::assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
192
|
|
|
self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
193
|
|
|
self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
View Code Duplication |
public function testColumnCollation() |
|
|
|
|
197
|
|
|
{ |
198
|
|
|
$table = new Table('test_collation'); |
199
|
|
|
$table->addOption('collate', $collation = 'latin1_swedish_ci'); |
200
|
|
|
$table->addOption('charset', 'latin1'); |
201
|
|
|
$table->addColumn('id', 'integer'); |
202
|
|
|
$table->addColumn('text', 'text'); |
203
|
|
|
$table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); |
204
|
|
|
$table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); |
205
|
|
|
$this->_sm->dropAndCreateTable($table); |
206
|
|
|
|
207
|
|
|
$columns = $this->_sm->listTableColumns('test_collation'); |
208
|
|
|
|
209
|
|
|
self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); |
210
|
|
|
self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); |
211
|
|
|
self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation')); |
212
|
|
|
self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation')); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @group DBAL-843 |
217
|
|
|
*/ |
218
|
|
|
public function testListLobTypeColumns() |
219
|
|
|
{ |
220
|
|
|
$tableName = 'lob_type_columns'; |
221
|
|
|
$table = new Table($tableName); |
222
|
|
|
|
223
|
|
|
$table->addColumn('col_tinytext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT)); |
224
|
|
|
$table->addColumn('col_text', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TEXT)); |
225
|
|
|
$table->addColumn('col_mediumtext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT)); |
226
|
|
|
$table->addColumn('col_longtext', 'text'); |
227
|
|
|
|
228
|
|
|
$table->addColumn('col_tinyblob', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB)); |
229
|
|
|
$table->addColumn('col_blob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_BLOB)); |
230
|
|
|
$table->addColumn('col_mediumblob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB)); |
231
|
|
|
$table->addColumn('col_longblob', 'blob'); |
232
|
|
|
|
233
|
|
|
$this->_sm->dropAndCreateTable($table); |
234
|
|
|
|
235
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
236
|
|
|
$offlineColumns = $table->getColumns(); |
237
|
|
|
$onlineColumns = $this->_sm->listTableColumns($tableName); |
238
|
|
|
|
239
|
|
|
self::assertSame( |
240
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), |
241
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_tinytext']->toArray()) |
242
|
|
|
); |
243
|
|
|
self::assertSame( |
244
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_text']->toArray()), |
245
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_text']->toArray()) |
246
|
|
|
); |
247
|
|
|
self::assertSame( |
248
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_mediumtext']->toArray()), |
249
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_mediumtext']->toArray()) |
250
|
|
|
); |
251
|
|
|
self::assertSame( |
252
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_longtext']->toArray()), |
253
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_longtext']->toArray()) |
254
|
|
|
); |
255
|
|
|
|
256
|
|
|
self::assertSame( |
257
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_tinyblob']->toArray()), |
258
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_tinyblob']->toArray()) |
259
|
|
|
); |
260
|
|
|
self::assertSame( |
261
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_blob']->toArray()), |
262
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_blob']->toArray()) |
263
|
|
|
); |
264
|
|
|
self::assertSame( |
265
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_mediumblob']->toArray()), |
266
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_mediumblob']->toArray()) |
267
|
|
|
); |
268
|
|
|
self::assertSame( |
269
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_longblob']->toArray()), |
270
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_longblob']->toArray()) |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @group DBAL-423 |
276
|
|
|
*/ |
277
|
|
|
public function testDiffListGuidTableColumn() |
278
|
|
|
{ |
279
|
|
|
$offlineTable = new Table('list_guid_table_column'); |
280
|
|
|
$offlineTable->addColumn('col_guid', 'guid'); |
281
|
|
|
|
282
|
|
|
$this->_sm->dropAndCreateTable($offlineTable); |
283
|
|
|
|
284
|
|
|
$onlineTable = $this->_sm->listTableDetails('list_guid_table_column'); |
285
|
|
|
|
286
|
|
|
$comparator = new Comparator(); |
287
|
|
|
|
288
|
|
|
self::assertFalse( |
289
|
|
|
$comparator->diffTable($offlineTable, $onlineTable), |
|
|
|
|
290
|
|
|
"No differences should be detected with the offline vs online schema." |
291
|
|
|
); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @group DBAL-1082 |
296
|
|
|
*/ |
297
|
|
View Code Duplication |
public function testListDecimalTypeColumns() |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
$tableName = 'test_list_decimal_columns'; |
300
|
|
|
$table = new Table($tableName); |
301
|
|
|
|
302
|
|
|
$table->addColumn('col', 'decimal'); |
303
|
|
|
$table->addColumn('col_unsigned', 'decimal', array('unsigned' => true)); |
304
|
|
|
|
305
|
|
|
$this->_sm->dropAndCreateTable($table); |
306
|
|
|
|
307
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
308
|
|
|
|
309
|
|
|
self::assertArrayHasKey('col', $columns); |
310
|
|
|
self::assertArrayHasKey('col_unsigned', $columns); |
311
|
|
|
self::assertFalse($columns['col']->getUnsigned()); |
312
|
|
|
self::assertTrue($columns['col_unsigned']->getUnsigned()); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @group DBAL-1082 |
317
|
|
|
*/ |
318
|
|
View Code Duplication |
public function testListFloatTypeColumns() |
|
|
|
|
319
|
|
|
{ |
320
|
|
|
$tableName = 'test_list_float_columns'; |
321
|
|
|
$table = new Table($tableName); |
322
|
|
|
|
323
|
|
|
$table->addColumn('col', 'float'); |
324
|
|
|
$table->addColumn('col_unsigned', 'float', array('unsigned' => true)); |
325
|
|
|
|
326
|
|
|
$this->_sm->dropAndCreateTable($table); |
327
|
|
|
|
328
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
329
|
|
|
|
330
|
|
|
self::assertArrayHasKey('col', $columns); |
331
|
|
|
self::assertArrayHasKey('col_unsigned', $columns); |
332
|
|
|
self::assertFalse($columns['col']->getUnsigned()); |
333
|
|
|
self::assertTrue($columns['col_unsigned']->getUnsigned()); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function testJsonColumnType() : void |
337
|
|
|
{ |
338
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
339
|
|
|
if (!$platform->hasNativeJsonType()) { |
340
|
|
|
$this->markTestSkipped("Requires native JSON type"); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$table = new Table('test_mysql_json'); |
344
|
|
|
$table->addColumn('col_json', 'json'); |
345
|
|
|
$this->_sm->dropAndCreateTable($table); |
346
|
|
|
|
347
|
|
|
$columns = $this->_sm->listTableColumns('test_mysql_json'); |
348
|
|
|
|
349
|
|
|
self::assertSame(TYPE::JSON, $columns['col_json']->getType()->getName()); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
public function testColumnDefaultCurrentTimestamp() : void |
353
|
|
|
{ |
354
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
355
|
|
|
|
356
|
|
|
$table = new Table("test_column_defaults_current_timestamp"); |
357
|
|
|
|
358
|
|
|
$currentTimeStampSql = $platform->getCurrentTimestampSQL(); |
359
|
|
|
|
360
|
|
|
$table->addColumn('col_datetime', 'datetime', ['notnull' => true, 'default' => $currentTimeStampSql]); |
361
|
|
|
$table->addColumn('col_datetime_nullable', 'datetime', ['default' => $currentTimeStampSql]); |
362
|
|
|
|
363
|
|
|
$this->_sm->dropAndCreateTable($table); |
364
|
|
|
|
365
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_timestamp"); |
366
|
|
|
self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault()); |
367
|
|
|
self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault()); |
368
|
|
|
|
369
|
|
|
$comparator = new Comparator(); |
370
|
|
|
|
371
|
|
|
$diff = $comparator->diffTable($table, $onlineTable); |
372
|
|
|
self::assertFalse($diff, "Tables should be identical with column defaults."); |
|
|
|
|
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public function testColumnDefaultsAreValid() { |
376
|
|
|
|
377
|
|
|
$table = new Table("test_column_defaults_are_valid"); |
378
|
|
|
|
379
|
|
|
$currentTimeStampSql = $this->_sm->getDatabasePlatform()->getCurrentTimestampSQL(); |
380
|
|
|
$table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]); |
381
|
|
|
$table->addColumn('col_datetime_null', 'datetime', ['notnull' => false, 'default' => null]); |
382
|
|
|
$table->addColumn('col_int', 'integer', ['default' => 1]); |
383
|
|
|
$table->addColumn('col_neg_int', 'integer', ['default' => -1]); |
384
|
|
|
$table->addColumn('col_string', 'string', ['default' => 'A']); |
385
|
|
|
$table->addColumn('col_decimal', 'decimal', ['scale' => 3, 'precision' => 6, 'default' => -2.3]); |
386
|
|
|
$table->addColumn('col_date', 'date', ['default' => '2012-12-12']); |
387
|
|
|
|
388
|
|
|
$this->_sm->dropAndCreateTable($table); |
389
|
|
|
|
390
|
|
|
$this->_conn->executeUpdate( |
391
|
|
|
"INSERT INTO test_column_defaults_are_valid () VALUES()" |
392
|
|
|
); |
393
|
|
|
|
394
|
|
|
$row = $this->_conn->fetchAssoc( |
395
|
|
|
'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' |
396
|
|
|
); |
397
|
|
|
|
398
|
|
|
self::assertInstanceOf(\DateTime::class, \DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); |
399
|
|
|
self::assertNull($row['col_datetime_null']); |
400
|
|
|
self::assertSame('2012-12-12', $row['col_date']); |
401
|
|
|
self::assertSame('A', $row['col_string']); |
402
|
|
|
self::assertEquals(1, $row['col_int']); |
403
|
|
|
self::assertEquals(-1, $row['col_neg_int']); |
404
|
|
|
self::assertEquals('-2.300', $row['col_decimal']); |
405
|
|
|
self::assertLessThan(5, $row['diff_seconds']); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* MariaDB 10.2+ does support CURRENT_TIME and CURRENT_DATE as |
410
|
|
|
* column default values for time and date columns. |
411
|
|
|
* (Not supported on Mysql as of 5.7.19) |
412
|
|
|
* |
413
|
|
|
* Note that MariaDB 10.2+, when storing default in information_schema, |
414
|
|
|
* silently change CURRENT_TIMESTAMP as 'current_timestamp()', |
415
|
|
|
* CURRENT_TIME as 'currtime()' and CURRENT_DATE as 'currdate()'. |
416
|
|
|
* This test also ensure proper aliasing to not trigger a table diff. |
417
|
|
|
*/ |
418
|
|
|
public function testColumnDefaultValuesCurrentTimeAndDate() : void |
419
|
|
|
{ |
420
|
|
|
if (!$this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { |
421
|
|
|
$this->markTestSkipped('Only relevant for MariaDb102Platform.'); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
425
|
|
|
|
426
|
|
|
$table = new Table("test_column_defaults_current_time_and_date"); |
427
|
|
|
|
428
|
|
|
$currentTimestampSql = $platform->getCurrentTimestampSQL(); |
429
|
|
|
$currentTimeSql = $platform->getCurrentTimeSQL(); |
430
|
|
|
$currentDateSql = $platform->getCurrentDateSQL(); |
431
|
|
|
|
432
|
|
|
$table->addColumn('col_datetime', 'datetime', ['default' => $currentTimestampSql]); |
433
|
|
|
$table->addColumn('col_date', 'date', ['default' => $currentDateSql]); |
434
|
|
|
$table->addColumn('col_time', 'time', ['default' => $currentTimeSql]); |
435
|
|
|
|
436
|
|
|
$this->_sm->dropAndCreateTable($table); |
437
|
|
|
|
438
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_time_and_date"); |
439
|
|
|
|
440
|
|
|
self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault()); |
441
|
|
|
self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault()); |
442
|
|
|
self::assertSame($currentTimeSql, $onlineTable->getColumn('col_time')->getDefault()); |
443
|
|
|
|
444
|
|
|
$comparator = new Comparator(); |
445
|
|
|
|
446
|
|
|
$diff = $comparator->diffTable($table, $onlineTable); |
447
|
|
|
self::assertFalse($diff, "Tables should be identical with column defauts time and date."); |
|
|
|
|
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Ensure default values (un-)escaping is properly done by mysql platforms. |
452
|
|
|
* The test is voluntarily relying on schema introspection due to current |
453
|
|
|
* doctrine limitations. Once #2850 is landed, this test can be removed. |
454
|
|
|
*/ |
455
|
|
|
public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void |
456
|
|
|
{ |
457
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
458
|
|
|
$this->_conn->query('DROP TABLE IF EXISTS test_column_defaults_with_create'); |
459
|
|
|
|
460
|
|
|
$default = "a\\0b\\'c\"d\te\\Zf\\\\g''h"; |
461
|
|
|
$sql = "CREATE TABLE test_column_defaults_with_create( |
462
|
|
|
col1 VARCHAR(255) NULL DEFAULT {$platform->quoteStringLiteral($default)} |
463
|
|
|
)"; |
464
|
|
|
|
465
|
|
|
$this->_conn->query($sql); |
466
|
|
|
|
467
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_create"); |
468
|
|
|
self::assertSame($default, $onlineTable->getColumn('col1')->getDefault()); |
469
|
|
|
} |
470
|
|
|
} |
471
|
|
|
|