|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Schema; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform; |
|
6
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
9
|
|
|
use Doctrine\DBAL\Types\Type; |
|
10
|
|
|
|
|
11
|
|
|
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase |
|
12
|
|
|
{ |
|
13
|
|
|
protected function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
if (!Type::hasType('point')) { |
|
18
|
|
|
Type::addType('point', 'Doctrine\Tests\Types\MySqlPointType'); |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testSwitchPrimaryKeyColumns() |
|
23
|
|
|
{ |
|
24
|
|
|
$tableOld = new Table("switch_primary_key_columns"); |
|
25
|
|
|
$tableOld->addColumn('foo_id', 'integer'); |
|
26
|
|
|
$tableOld->addColumn('bar_id', 'integer'); |
|
27
|
|
|
$tableNew = clone $tableOld; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$this->_sm->createTable($tableOld); |
|
30
|
|
|
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns"); |
|
31
|
|
|
$tableNew = clone $tableFetched; |
|
32
|
|
|
$tableNew->setPrimaryKey(array('bar_id', 'foo_id')); |
|
33
|
|
|
|
|
34
|
|
|
$comparator = new Comparator; |
|
35
|
|
|
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testDiffTableBug() |
|
39
|
|
|
{ |
|
40
|
|
|
$schema = new Schema(); |
|
41
|
|
|
$table = $schema->createTable('diffbug_routing_translations'); |
|
42
|
|
|
$table->addColumn('id', 'integer'); |
|
43
|
|
|
$table->addColumn('route', 'string'); |
|
44
|
|
|
$table->addColumn('locale', 'string'); |
|
45
|
|
|
$table->addColumn('attribute', 'string'); |
|
46
|
|
|
$table->addColumn('localized_value', 'string'); |
|
47
|
|
|
$table->addColumn('original_value', 'string'); |
|
48
|
|
|
$table->setPrimaryKey(array('id')); |
|
49
|
|
|
$table->addUniqueIndex(array('route', 'locale', 'attribute')); |
|
50
|
|
|
$table->addIndex(array('localized_value')); // this is much more selective than the unique index |
|
51
|
|
|
|
|
52
|
|
|
$this->_sm->createTable($table); |
|
53
|
|
|
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations"); |
|
54
|
|
|
|
|
55
|
|
|
$comparator = new Comparator; |
|
56
|
|
|
$diff = $comparator->diffTable($tableFetched, $table); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertFalse($diff, "no changes expected."); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
View Code Duplication |
public function testFulltextIndex() |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$table = new Table('fulltext_index'); |
|
64
|
|
|
$table->addColumn('text', 'text'); |
|
65
|
|
|
$table->addIndex(array('text'), 'f_index'); |
|
66
|
|
|
$table->addOption('engine', 'MyISAM'); |
|
67
|
|
|
|
|
68
|
|
|
$index = $table->getIndex('f_index'); |
|
69
|
|
|
$index->addFlag('fulltext'); |
|
70
|
|
|
|
|
71
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
72
|
|
|
|
|
73
|
|
|
$indexes = $this->_sm->listTableIndexes('fulltext_index'); |
|
74
|
|
|
$this->assertArrayHasKey('f_index', $indexes); |
|
75
|
|
|
$this->assertTrue($indexes['f_index']->hasFlag('fulltext')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
public function testSpatialIndex() |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$table = new Table('spatial_index'); |
|
81
|
|
|
$table->addColumn('point', 'point'); |
|
82
|
|
|
$table->addIndex(array('point'), 's_index'); |
|
83
|
|
|
$table->addOption('engine', 'MyISAM'); |
|
84
|
|
|
|
|
85
|
|
|
$index = $table->getIndex('s_index'); |
|
86
|
|
|
$index->addFlag('spatial'); |
|
87
|
|
|
|
|
88
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
89
|
|
|
|
|
90
|
|
|
$indexes = $this->_sm->listTableIndexes('spatial_index'); |
|
91
|
|
|
$this->assertArrayHasKey('s_index', $indexes); |
|
92
|
|
|
$this->assertTrue($indexes['s_index']->hasFlag('spatial')); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @group DBAL-400 |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testAlterTableAddPrimaryKey() |
|
99
|
|
|
{ |
|
100
|
|
|
$table = new Table('alter_table_add_pk'); |
|
101
|
|
|
$table->addColumn('id', 'integer'); |
|
102
|
|
|
$table->addColumn('foo', 'integer'); |
|
103
|
|
|
$table->addIndex(array('id'), 'idx_id'); |
|
104
|
|
|
|
|
105
|
|
|
$this->_sm->createTable($table); |
|
106
|
|
|
|
|
107
|
|
|
$comparator = new Comparator(); |
|
108
|
|
|
$diffTable = clone $table; |
|
109
|
|
|
|
|
110
|
|
|
$diffTable->dropIndex('idx_id'); |
|
111
|
|
|
$diffTable->setPrimaryKey(array('id')); |
|
112
|
|
|
|
|
113
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $diffTable)); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
$table = $this->_sm->listTableDetails("alter_table_add_pk"); |
|
116
|
|
|
|
|
117
|
|
|
$this->assertFalse($table->hasIndex('idx_id')); |
|
118
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @group DBAL-464 |
|
123
|
|
|
*/ |
|
124
|
|
|
public function testDropPrimaryKeyWithAutoincrementColumn() |
|
125
|
|
|
{ |
|
126
|
|
|
$table = new Table("drop_primary_key"); |
|
127
|
|
|
$table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true)); |
|
128
|
|
|
$table->addColumn('foo', 'integer', array('primary' => true)); |
|
129
|
|
|
$table->setPrimaryKey(array('id', 'foo')); |
|
130
|
|
|
|
|
131
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
132
|
|
|
|
|
133
|
|
|
$diffTable = clone $table; |
|
134
|
|
|
|
|
135
|
|
|
$diffTable->dropPrimaryKey(); |
|
136
|
|
|
|
|
137
|
|
|
$comparator = new Comparator(); |
|
138
|
|
|
|
|
139
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $diffTable)); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
$table = $this->_sm->listTableDetails("drop_primary_key"); |
|
142
|
|
|
|
|
143
|
|
|
$this->assertFalse($table->hasPrimaryKey()); |
|
144
|
|
|
$this->assertFalse($table->getColumn('id')->getAutoincrement()); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @group DBAL-789 |
|
149
|
|
|
*/ |
|
150
|
|
|
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() |
|
151
|
|
|
{ |
|
152
|
|
|
$table = new Table("text_blob_default_value"); |
|
153
|
|
|
$table->addColumn('def_text', 'text', array('default' => 'def')); |
|
154
|
|
|
$table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def')); |
|
155
|
|
|
$table->addColumn('def_blob', 'blob', array('default' => 'def')); |
|
156
|
|
|
$table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def')); |
|
157
|
|
|
|
|
158
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
159
|
|
|
|
|
160
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertNull($onlineTable->getColumn('def_text')->getDefault()); |
|
163
|
|
|
$this->assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
|
164
|
|
|
$this->assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
|
165
|
|
|
$this->assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
|
166
|
|
|
$this->assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
|
167
|
|
|
$this->assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
|
168
|
|
|
|
|
169
|
|
|
$comparator = new Comparator(); |
|
170
|
|
|
|
|
171
|
|
|
$this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); |
|
174
|
|
|
|
|
175
|
|
|
$this->assertNull($onlineTable->getColumn('def_text')->getDefault()); |
|
176
|
|
|
$this->assertNull($onlineTable->getColumn('def_text_null')->getDefault()); |
|
177
|
|
|
$this->assertFalse($onlineTable->getColumn('def_text_null')->getNotnull()); |
|
178
|
|
|
$this->assertNull($onlineTable->getColumn('def_blob')->getDefault()); |
|
179
|
|
|
$this->assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); |
|
180
|
|
|
$this->assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
View Code Duplication |
public function testColumnCollation() |
|
|
|
|
|
|
184
|
|
|
{ |
|
185
|
|
|
$table = new Table('test_collation'); |
|
186
|
|
|
$table->addOption('collate', $collation = 'latin1_swedish_ci'); |
|
187
|
|
|
$table->addOption('charset', 'latin1'); |
|
188
|
|
|
$table->addColumn('id', 'integer'); |
|
189
|
|
|
$table->addColumn('text', 'text'); |
|
190
|
|
|
$table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); |
|
191
|
|
|
$table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); |
|
192
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
193
|
|
|
|
|
194
|
|
|
$columns = $this->_sm->listTableColumns('test_collation'); |
|
195
|
|
|
|
|
196
|
|
|
$this->assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); |
|
197
|
|
|
$this->assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); |
|
198
|
|
|
$this->assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation')); |
|
199
|
|
|
$this->assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation')); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @group DBAL-843 |
|
204
|
|
|
*/ |
|
205
|
|
|
public function testListLobTypeColumns() |
|
206
|
|
|
{ |
|
207
|
|
|
$tableName = 'lob_type_columns'; |
|
208
|
|
|
$table = new Table($tableName); |
|
209
|
|
|
|
|
210
|
|
|
$table->addColumn('col_tinytext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT)); |
|
211
|
|
|
$table->addColumn('col_text', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TEXT)); |
|
212
|
|
|
$table->addColumn('col_mediumtext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT)); |
|
213
|
|
|
$table->addColumn('col_longtext', 'text'); |
|
214
|
|
|
|
|
215
|
|
|
$table->addColumn('col_tinyblob', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB)); |
|
216
|
|
|
$table->addColumn('col_blob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_BLOB)); |
|
217
|
|
|
$table->addColumn('col_mediumblob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB)); |
|
218
|
|
|
$table->addColumn('col_longblob', 'blob'); |
|
219
|
|
|
|
|
220
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
221
|
|
|
|
|
222
|
|
|
$platform = $this->_sm->getDatabasePlatform(); |
|
223
|
|
|
$offlineColumns = $table->getColumns(); |
|
224
|
|
|
$onlineColumns = $this->_sm->listTableColumns($tableName); |
|
225
|
|
|
|
|
226
|
|
|
$this->assertSame( |
|
227
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), |
|
228
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_tinytext']->toArray()) |
|
229
|
|
|
); |
|
230
|
|
|
$this->assertSame( |
|
231
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_text']->toArray()), |
|
232
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_text']->toArray()) |
|
233
|
|
|
); |
|
234
|
|
|
$this->assertSame( |
|
235
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_mediumtext']->toArray()), |
|
236
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_mediumtext']->toArray()) |
|
237
|
|
|
); |
|
238
|
|
|
$this->assertSame( |
|
239
|
|
|
$platform->getClobTypeDeclarationSQL($offlineColumns['col_longtext']->toArray()), |
|
240
|
|
|
$platform->getClobTypeDeclarationSQL($onlineColumns['col_longtext']->toArray()) |
|
241
|
|
|
); |
|
242
|
|
|
|
|
243
|
|
|
$this->assertSame( |
|
244
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_tinyblob']->toArray()), |
|
245
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_tinyblob']->toArray()) |
|
246
|
|
|
); |
|
247
|
|
|
$this->assertSame( |
|
248
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_blob']->toArray()), |
|
249
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_blob']->toArray()) |
|
250
|
|
|
); |
|
251
|
|
|
$this->assertSame( |
|
252
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_mediumblob']->toArray()), |
|
253
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_mediumblob']->toArray()) |
|
254
|
|
|
); |
|
255
|
|
|
$this->assertSame( |
|
256
|
|
|
$platform->getBlobTypeDeclarationSQL($offlineColumns['col_longblob']->toArray()), |
|
257
|
|
|
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_longblob']->toArray()) |
|
258
|
|
|
); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @group DBAL-423 |
|
263
|
|
|
*/ |
|
264
|
|
|
public function testDiffListGuidTableColumn() |
|
265
|
|
|
{ |
|
266
|
|
|
$offlineTable = new Table('list_guid_table_column'); |
|
267
|
|
|
$offlineTable->addColumn('col_guid', 'guid'); |
|
268
|
|
|
|
|
269
|
|
|
$this->_sm->dropAndCreateTable($offlineTable); |
|
270
|
|
|
|
|
271
|
|
|
$onlineTable = $this->_sm->listTableDetails('list_guid_table_column'); |
|
272
|
|
|
|
|
273
|
|
|
$comparator = new Comparator(); |
|
274
|
|
|
|
|
275
|
|
|
$this->assertFalse( |
|
276
|
|
|
$comparator->diffTable($offlineTable, $onlineTable), |
|
277
|
|
|
"No differences should be detected with the offline vs online schema." |
|
278
|
|
|
); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* @group DBAL-1082 |
|
283
|
|
|
*/ |
|
284
|
|
View Code Duplication |
public function testListDecimalTypeColumns() |
|
|
|
|
|
|
285
|
|
|
{ |
|
286
|
|
|
$tableName = 'test_list_decimal_columns'; |
|
287
|
|
|
$table = new Table($tableName); |
|
288
|
|
|
|
|
289
|
|
|
$table->addColumn('col', 'decimal'); |
|
290
|
|
|
$table->addColumn('col_unsigned', 'decimal', array('unsigned' => true)); |
|
291
|
|
|
|
|
292
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
293
|
|
|
|
|
294
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
|
295
|
|
|
|
|
296
|
|
|
$this->assertArrayHasKey('col', $columns); |
|
297
|
|
|
$this->assertArrayHasKey('col_unsigned', $columns); |
|
298
|
|
|
$this->assertFalse($columns['col']->getUnsigned()); |
|
299
|
|
|
$this->assertTrue($columns['col_unsigned']->getUnsigned()); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @group DBAL-1082 |
|
304
|
|
|
*/ |
|
305
|
|
View Code Duplication |
public function testListFloatTypeColumns() |
|
|
|
|
|
|
306
|
|
|
{ |
|
307
|
|
|
$tableName = 'test_list_float_columns'; |
|
308
|
|
|
$table = new Table($tableName); |
|
309
|
|
|
|
|
310
|
|
|
$table->addColumn('col', 'float'); |
|
311
|
|
|
$table->addColumn('col_unsigned', 'float', array('unsigned' => true)); |
|
312
|
|
|
|
|
313
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
314
|
|
|
|
|
315
|
|
|
$columns = $this->_sm->listTableColumns($tableName); |
|
316
|
|
|
|
|
317
|
|
|
$this->assertArrayHasKey('col', $columns); |
|
318
|
|
|
$this->assertArrayHasKey('col_unsigned', $columns); |
|
319
|
|
|
$this->assertFalse($columns['col']->getUnsigned()); |
|
320
|
|
|
$this->assertTrue($columns['col_unsigned']->getUnsigned()); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
public function testColumnDefaultsUsingDoctrineTable(): void |
|
324
|
|
|
{ |
|
325
|
|
|
|
|
326
|
|
|
$table = new Table("test_column_defaults_with_table"); |
|
327
|
|
|
$table->addColumn('col0', 'integer', ['notnull' => false]); |
|
328
|
|
|
$table->addColumn('col1', 'integer', ['notnull' => false, 'default' => null]); |
|
329
|
|
|
$table->addColumn('col2', 'string', ['notnull' => false, 'default' => null]); |
|
330
|
|
|
$table->addColumn('col3', 'string', ['notnull' => false, 'default' => 'NULL']); |
|
331
|
|
|
$table->addColumn('col4', 'string', ['notnull' => false, 'default' => 'Hello world']); |
|
332
|
|
|
$table->addColumn('col5', 'datetime', ['notnull' => false, 'default' => null]); |
|
333
|
|
|
$table->addColumn('col6', 'decimal', ['scale' => 3, 'precision' => 6, 'notnull' => false, 'default' => -2.3]); |
|
334
|
|
|
$table->addColumn('col7', 'date', ['notnull' => false, 'default' => '2012-12-12']); |
|
335
|
|
|
$table->addColumn('col8', 'string', ['notnull' => true, 'default' => '']); |
|
336
|
|
|
$table->addColumn('col9', 'integer', ['notnull' => false, 'default' => 0]); |
|
337
|
|
|
$table->addColumn('col10', 'string', ['notnull' => false, 'default' => 'He"ll"o world']); |
|
338
|
|
|
|
|
339
|
|
|
$this->_sm->dropAndCreateTable($table); |
|
340
|
|
|
|
|
341
|
|
|
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_table"); |
|
342
|
|
|
self::assertNull($onlineTable->getColumn('col0')->getDefault()); |
|
343
|
|
|
self::assertNull($onlineTable->getColumn('col1')->getDefault()); |
|
344
|
|
|
self::assertNull($onlineTable->getColumn('col2')->getDefault()); |
|
345
|
|
|
self::assertEquals('NULL', $onlineTable->getColumn('col3')->getDefault()); |
|
346
|
|
|
self::assertEquals('Hello world', $onlineTable->getColumn('col4')->getDefault()); |
|
347
|
|
|
self::assertNull($onlineTable->getColumn('col5')->getDefault()); |
|
348
|
|
|
self::assertEquals(-2.3, $onlineTable->getColumn('col6')->getDefault()); |
|
349
|
|
|
self::assertEquals('2012-12-12', $onlineTable->getColumn('col7')->getDefault()); |
|
350
|
|
|
self::assertTrue($onlineTable->getColumn('col8')->getNotnull()); |
|
351
|
|
|
self::assertEquals('', $onlineTable->getColumn('col8')->getDefault()); |
|
352
|
|
|
self::assertEquals(0, $onlineTable->getColumn('col9')->getDefault()); |
|
353
|
|
|
self::assertEquals('He"ll"o world', $onlineTable->getColumn('col10')->getDefault()); |
|
354
|
|
|
|
|
355
|
|
|
$comparator = new Comparator(); |
|
356
|
|
|
|
|
357
|
|
|
$diff = $comparator->diffTable($table, $onlineTable); |
|
358
|
|
|
$this->assertFalse($diff, "Tables should be identical with column defaults."); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
public function testColumnDefaultsUsingSql(): void |
|
362
|
|
|
{ |
|
363
|
|
|
|
|
364
|
|
|
$this->_conn->query('DROP TABLE IF EXISTS `test_column_defaults_with_create`'); |
|
365
|
|
|
$sql = sprintf(" |
|
366
|
|
|
CREATE TABLE `test_column_defaults_with_create` ( |
|
367
|
|
|
`col0` INT(11) NULL, |
|
368
|
|
|
`col1` INT(10) UNSIGNED NULL DEFAULT NULL, |
|
369
|
|
|
`col2` VARCHAR(10) CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI NULL DEFAULT NULL, |
|
370
|
|
|
`col3` VARCHAR(10) CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI NULL DEFAULT 'NULL', |
|
371
|
|
|
`col4` VARCHAR(20) NULL DEFAULT 'Hello world', |
|
372
|
|
|
`col5` DATETIME NULL DEFAULT NULL, |
|
373
|
|
|
`col6` DECIMAL(6, 3) NULL DEFAULT -2.3, |
|
374
|
|
|
`col7` DATE NULL DEFAULT '2012-12-12', |
|
375
|
|
|
`col8` VARCHAR(20) NOT NULL DEFAULT '', |
|
376
|
|
|
`col9` INT(11) NULL DEFAULT 0, |
|
377
|
|
|
`col10` VARCHAR(20) NULL DEFAULT '%s' |
|
378
|
|
|
) ENGINE=INNODB; |
|
379
|
|
|
", 'He"ll"o world'); |
|
380
|
|
|
|
|
381
|
|
|
$this->_conn->query($sql); |
|
382
|
|
|
$t = $this->_sm->listTableDetails("test_column_defaults_with_create"); |
|
383
|
|
|
self::assertNull($t->getColumn('col0')->getDefault()); |
|
384
|
|
|
self::assertNull($t->getColumn('col1')->getDefault()); |
|
385
|
|
|
self::assertNull($t->getColumn('col2')->getDefault()); |
|
386
|
|
|
self::assertEquals('NULL', $t->getColumn('col3')->getDefault()); |
|
387
|
|
|
self::assertEquals('Hello world', $t->getColumn('col4')->getDefault()); |
|
388
|
|
|
self::assertNull($t->getColumn('col5')->getDefault()); |
|
389
|
|
|
self::assertEquals(-2.3, $t->getColumn('col6')->getDefault()); |
|
390
|
|
|
self::assertEquals('2012-12-12', $t->getColumn('col7')->getDefault()); |
|
391
|
|
|
self::assertTrue($t->getColumn('col8')->getNotnull()); |
|
392
|
|
|
self::assertEquals('', $t->getColumn('col8')->getDefault()); |
|
393
|
|
|
self::assertEquals(0, $t->getColumn('col9')->getDefault()); |
|
394
|
|
|
self::assertEquals('He"ll"o world', $t->getColumn('col10')->getDefault()); |
|
395
|
|
|
|
|
396
|
|
|
// @todo mariadb returns 'current_timestamp()' |
|
397
|
|
|
// `col10` DATETIME NULL DEFAULT CURRENT_TIMESTAMP |
|
398
|
|
|
// $this->assertEquals('current_timestamp', strtolower($t->getColumn('col10')->getDefault())); |
|
|
|
|
|
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
} |
|
402
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.