1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\EventManager; |
6
|
|
|
use Doctrine\DBAL\Events; |
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
8
|
|
|
use Doctrine\DBAL\Schema\Column; |
9
|
|
|
use Doctrine\DBAL\Schema\ColumnDiff; |
10
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
11
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
12
|
|
|
use Doctrine\DBAL\Schema\Index; |
13
|
|
|
use Doctrine\DBAL\Schema\Table; |
14
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
15
|
|
|
use Doctrine\DBAL\Types\Type; |
16
|
|
|
use Doctrine\Tests\Types\CommentedType; |
17
|
|
|
|
18
|
|
|
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
22
|
|
|
*/ |
23
|
|
|
protected $_platform; |
24
|
|
|
|
25
|
|
|
abstract public function createPlatform(); |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->_platform = $this->createPlatform(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @group DDC-1360 |
34
|
|
|
*/ |
35
|
|
|
public function testQuoteIdentifier() |
36
|
|
|
{ |
37
|
|
|
if ($this->_platform->getName() == "mssql") { |
38
|
|
|
$this->markTestSkipped('Not working this way on mssql.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$c = $this->_platform->getIdentifierQuoteCharacter(); |
42
|
|
|
self::assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test")); |
43
|
|
|
self::assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test")); |
44
|
|
|
self::assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @group DDC-1360 |
49
|
|
|
*/ |
50
|
|
|
public function testQuoteSingleIdentifier() |
51
|
|
|
{ |
52
|
|
|
if ($this->_platform->getName() == "mssql") { |
53
|
|
|
$this->markTestSkipped('Not working this way on mssql.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$c = $this->_platform->getIdentifierQuoteCharacter(); |
57
|
|
|
self::assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test")); |
58
|
|
|
self::assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test")); |
59
|
|
|
self::assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @group DBAL-1029 |
64
|
|
|
* |
65
|
|
|
* @dataProvider getReturnsForeignKeyReferentialActionSQL |
66
|
|
|
*/ |
67
|
|
|
public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) |
68
|
|
|
{ |
69
|
|
|
self::assertSame($expectedSQL, $this->_platform->getForeignKeyReferentialActionSQL($action)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getReturnsForeignKeyReferentialActionSQL() |
76
|
|
|
{ |
77
|
|
|
return array( |
78
|
|
|
array('CASCADE', 'CASCADE'), |
79
|
|
|
array('SET NULL', 'SET NULL'), |
80
|
|
|
array('NO ACTION', 'NO ACTION'), |
81
|
|
|
array('RESTRICT', 'RESTRICT'), |
82
|
|
|
array('SET DEFAULT', 'SET DEFAULT'), |
83
|
|
|
array('CaScAdE', 'CASCADE'), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testGetInvalidForeignKeyReferentialActionSQL() |
88
|
|
|
{ |
89
|
|
|
$this->expectException('InvalidArgumentException'); |
90
|
|
|
$this->_platform->getForeignKeyReferentialActionSQL('unknown'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testGetUnknownDoctrineMappingType() |
94
|
|
|
{ |
95
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
96
|
|
|
$this->_platform->getDoctrineTypeMapping('foobar'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testRegisterDoctrineMappingType() |
100
|
|
|
{ |
101
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'integer'); |
102
|
|
|
self::assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo')); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testRegisterUnknownDoctrineMappingType() |
106
|
|
|
{ |
107
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
108
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'bar'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @group DBAL-2594 |
113
|
|
|
*/ |
114
|
|
|
public function testRegistersCommentedDoctrineMappingTypeImplicitly() |
115
|
|
|
{ |
116
|
|
|
if (!Type::hasType('my_commented')) { |
117
|
|
|
Type::addType('my_commented', CommentedType::class); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$type = Type::getType('my_commented'); |
121
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'my_commented'); |
122
|
|
|
|
123
|
|
|
self::assertTrue($this->_platform->isCommentedDoctrineType($type)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @group DBAL-939 |
128
|
|
|
* |
129
|
|
|
* @dataProvider getIsCommentedDoctrineType |
130
|
|
|
*/ |
131
|
|
|
public function testIsCommentedDoctrineType(Type $type, $commented) |
132
|
|
|
{ |
133
|
|
|
self::assertSame($commented, $this->_platform->isCommentedDoctrineType($type)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getIsCommentedDoctrineType() |
137
|
|
|
{ |
138
|
|
|
$this->setUp(); |
139
|
|
|
|
140
|
|
|
$data = array(); |
141
|
|
|
|
142
|
|
|
foreach (Type::getTypesMap() as $typeName => $className) { |
143
|
|
|
$type = Type::getType($typeName); |
144
|
|
|
|
145
|
|
|
$data[$typeName] = array( |
146
|
|
|
$type, |
147
|
|
|
$type->requiresSQLCommentHint($this->_platform), |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $data; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testCreateWithNoColumns() |
155
|
|
|
{ |
156
|
|
|
$table = new Table('test'); |
157
|
|
|
|
158
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
159
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testGeneratesTableCreationSql() |
163
|
|
|
{ |
164
|
|
|
$table = new Table('test'); |
165
|
|
|
$table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true)); |
166
|
|
|
$table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); |
167
|
|
|
$table->setPrimaryKey(array('id')); |
168
|
|
|
|
169
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
170
|
|
|
self::assertEquals($this->getGenerateTableSql(), $sql[0]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
abstract public function getGenerateTableSql(); |
174
|
|
|
|
175
|
|
|
public function testGenerateTableWithMultiColumnUniqueIndex() |
176
|
|
|
{ |
177
|
|
|
$table = new Table('test'); |
178
|
|
|
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); |
179
|
|
|
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); |
180
|
|
|
$table->addUniqueIndex(array("foo", "bar")); |
181
|
|
|
|
182
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
183
|
|
|
self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
abstract public function getGenerateTableWithMultiColumnUniqueIndexSql(); |
187
|
|
|
|
188
|
|
|
public function testGeneratesIndexCreationSql() |
189
|
|
|
{ |
190
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('my_idx', array('user_name', 'last_login')); |
191
|
|
|
|
192
|
|
|
self::assertEquals( |
193
|
|
|
$this->getGenerateIndexSql(), |
194
|
|
|
$this->_platform->getCreateIndexSQL($indexDef, 'mytable') |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
abstract public function getGenerateIndexSql(); |
199
|
|
|
|
200
|
|
|
public function testGeneratesUniqueIndexCreationSql() |
201
|
|
|
{ |
202
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true); |
203
|
|
|
|
204
|
|
|
$sql = $this->_platform->getCreateIndexSQL($indexDef, 'test'); |
205
|
|
|
self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
abstract public function getGenerateUniqueIndexSql(); |
209
|
|
|
|
210
|
|
|
public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() |
211
|
|
|
{ |
212
|
|
|
$where = 'test IS NULL AND test2 IS NOT NULL'; |
213
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where)); |
214
|
|
|
$uniqueIndex = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), true, false, array(), array('where' => $where)); |
215
|
|
|
|
216
|
|
|
$expected = ' WHERE ' . $where; |
217
|
|
|
|
218
|
|
|
$actuals = array(); |
219
|
|
|
|
220
|
|
|
if ($this->supportsInlineIndexDeclaration()) { |
221
|
|
|
$actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); |
225
|
|
|
$actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table'); |
226
|
|
|
|
227
|
|
|
foreach ($actuals as $actual) { |
228
|
|
|
if ($this->_platform->supportsPartialIndexes()) { |
229
|
|
|
self::assertStringEndsWith($expected, $actual, 'WHERE clause should be present'); |
230
|
|
|
} else { |
231
|
|
|
self::assertStringEndsNotWith($expected, $actual, 'WHERE clause should NOT be present'); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function testGeneratesForeignKeyCreationSql() |
237
|
|
|
{ |
238
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), ''); |
239
|
|
|
|
240
|
|
|
$sql = $this->_platform->getCreateForeignKeySQL($fk, 'test'); |
241
|
|
|
self::assertEquals($sql, $this->getGenerateForeignKeySql()); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
abstract public function getGenerateForeignKeySql(); |
245
|
|
|
|
246
|
|
|
public function testGeneratesConstraintCreationSql() |
247
|
|
|
{ |
248
|
|
|
$idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false); |
249
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($idx, 'test'); |
250
|
|
|
self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); |
251
|
|
|
|
252
|
|
|
$pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true); |
253
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($pk, 'test'); |
254
|
|
|
self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql); |
255
|
|
|
|
256
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); |
257
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); |
258
|
|
|
self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() |
262
|
|
|
{ |
263
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); |
264
|
|
|
|
265
|
|
|
if ($this->_platform->supportsForeignKeyConstraints()) { |
266
|
|
|
self::assertInternalType( |
267
|
|
|
'string', |
268
|
|
|
$this->_platform->getCreateForeignKeySQL($fk, 'test') |
269
|
|
|
); |
270
|
|
|
} else { |
271
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
272
|
|
|
$this->_platform->getCreateForeignKeySQL($fk, 'test'); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
protected function getBitAndComparisonExpressionSql($value1, $value2) |
277
|
|
|
{ |
278
|
|
|
return '(' . $value1 . ' & ' . $value2 . ')'; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @group DDC-1213 |
283
|
|
|
*/ |
284
|
|
|
public function testGeneratesBitAndComparisonExpressionSql() |
285
|
|
|
{ |
286
|
|
|
$sql = $this->_platform->getBitAndComparisonExpression(2, 4); |
287
|
|
|
self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
protected function getBitOrComparisonExpressionSql($value1, $value2) |
291
|
|
|
{ |
292
|
|
|
return '(' . $value1 . ' | ' . $value2 . ')'; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @group DDC-1213 |
297
|
|
|
*/ |
298
|
|
|
public function testGeneratesBitOrComparisonExpressionSql() |
299
|
|
|
{ |
300
|
|
|
$sql = $this->_platform->getBitOrComparisonExpression(2, 4); |
301
|
|
|
self::assertEquals($this->getBitOrComparisonExpressionSql(2, 4), $sql); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function getGenerateConstraintUniqueIndexSql() |
305
|
|
|
{ |
306
|
|
|
return 'ALTER TABLE test ADD CONSTRAINT constraint_name UNIQUE (test)'; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
public function getGenerateConstraintPrimaryIndexSql() |
310
|
|
|
{ |
311
|
|
|
return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)'; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) |
315
|
|
|
{ |
316
|
|
|
$quotedForeignTable = $fk->getQuotedForeignTableName($this->_platform); |
317
|
|
|
|
318
|
|
|
return "ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES $quotedForeignTable (id)"; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
abstract public function getGenerateAlterTableSql(); |
322
|
|
|
|
323
|
|
|
public function testGeneratesTableAlterationSql() |
324
|
|
|
{ |
325
|
|
|
$expectedSql = $this->getGenerateAlterTableSql(); |
326
|
|
|
|
327
|
|
|
$table = new Table('mytable'); |
328
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
329
|
|
|
$table->addColumn('foo', 'integer'); |
330
|
|
|
$table->addColumn('bar', 'string'); |
331
|
|
|
$table->addColumn('bloo', 'boolean'); |
332
|
|
|
$table->setPrimaryKey(array('id')); |
333
|
|
|
|
334
|
|
|
$tableDiff = new TableDiff('mytable'); |
335
|
|
|
$tableDiff->fromTable = $table; |
336
|
|
|
$tableDiff->newName = 'userlist'; |
337
|
|
|
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false)); |
338
|
|
|
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer')); |
339
|
|
|
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
340
|
|
|
'bar', new \Doctrine\DBAL\Schema\Column( |
341
|
|
|
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def') |
342
|
|
|
), |
343
|
|
|
array('type', 'notnull', 'default') |
344
|
|
|
); |
345
|
|
|
$tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
346
|
|
|
'bloo', new \Doctrine\DBAL\Schema\Column( |
347
|
|
|
'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false) |
348
|
|
|
), |
349
|
|
|
array('type', 'notnull', 'default') |
350
|
|
|
); |
351
|
|
|
|
352
|
|
|
$sql = $this->_platform->getAlterTableSQL($tableDiff); |
353
|
|
|
|
354
|
|
|
self::assertEquals($expectedSql, $sql); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
public function testGetCustomColumnDeclarationSql() |
358
|
|
|
{ |
359
|
|
|
$field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED'); |
360
|
|
|
self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field)); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
public function testGetCreateTableSqlDispatchEvent() |
364
|
|
|
{ |
365
|
|
|
$listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') |
366
|
|
|
->setMethods(array('onSchemaCreateTable', 'onSchemaCreateTableColumn')) |
367
|
|
|
->getMock(); |
368
|
|
|
$listenerMock |
369
|
|
|
->expects($this->once()) |
370
|
|
|
->method('onSchemaCreateTable'); |
371
|
|
|
$listenerMock |
372
|
|
|
->expects($this->exactly(2)) |
373
|
|
|
->method('onSchemaCreateTableColumn'); |
374
|
|
|
|
375
|
|
|
$eventManager = new EventManager(); |
376
|
|
|
$eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock); |
377
|
|
|
|
378
|
|
|
$this->_platform->setEventManager($eventManager); |
379
|
|
|
|
380
|
|
|
$table = new Table('test'); |
381
|
|
|
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); |
382
|
|
|
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); |
383
|
|
|
|
384
|
|
|
$this->_platform->getCreateTableSQL($table); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
public function testGetDropTableSqlDispatchEvent() |
388
|
|
|
{ |
389
|
|
|
$listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') |
390
|
|
|
->setMethods(array('onSchemaDropTable')) |
391
|
|
|
->getMock(); |
392
|
|
|
$listenerMock |
393
|
|
|
->expects($this->once()) |
394
|
|
|
->method('onSchemaDropTable'); |
395
|
|
|
|
396
|
|
|
$eventManager = new EventManager(); |
397
|
|
|
$eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock); |
398
|
|
|
|
399
|
|
|
$this->_platform->setEventManager($eventManager); |
400
|
|
|
|
401
|
|
|
$this->_platform->getDropTableSQL('TABLE'); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
public function testGetAlterTableSqlDispatchEvent() |
405
|
|
|
{ |
406
|
|
|
$events = array( |
407
|
|
|
'onSchemaAlterTable', |
408
|
|
|
'onSchemaAlterTableAddColumn', |
409
|
|
|
'onSchemaAlterTableRemoveColumn', |
410
|
|
|
'onSchemaAlterTableChangeColumn', |
411
|
|
|
'onSchemaAlterTableRenameColumn' |
412
|
|
|
); |
413
|
|
|
|
414
|
|
|
$listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') |
415
|
|
|
->setMethods($events) |
416
|
|
|
->getMock(); |
417
|
|
|
$listenerMock |
418
|
|
|
->expects($this->once()) |
419
|
|
|
->method('onSchemaAlterTable'); |
420
|
|
|
$listenerMock |
421
|
|
|
->expects($this->once()) |
422
|
|
|
->method('onSchemaAlterTableAddColumn'); |
423
|
|
|
$listenerMock |
424
|
|
|
->expects($this->once()) |
425
|
|
|
->method('onSchemaAlterTableRemoveColumn'); |
426
|
|
|
$listenerMock |
427
|
|
|
->expects($this->once()) |
428
|
|
|
->method('onSchemaAlterTableChangeColumn'); |
429
|
|
|
$listenerMock |
430
|
|
|
->expects($this->once()) |
431
|
|
|
->method('onSchemaAlterTableRenameColumn'); |
432
|
|
|
|
433
|
|
|
$eventManager = new EventManager(); |
434
|
|
|
$events = array( |
435
|
|
|
Events::onSchemaAlterTable, |
436
|
|
|
Events::onSchemaAlterTableAddColumn, |
437
|
|
|
Events::onSchemaAlterTableRemoveColumn, |
438
|
|
|
Events::onSchemaAlterTableChangeColumn, |
439
|
|
|
Events::onSchemaAlterTableRenameColumn |
440
|
|
|
); |
441
|
|
|
$eventManager->addEventListener($events, $listenerMock); |
442
|
|
|
|
443
|
|
|
$this->_platform->setEventManager($eventManager); |
444
|
|
|
|
445
|
|
|
$table = new Table('mytable'); |
446
|
|
|
$table->addColumn('removed', 'integer'); |
447
|
|
|
$table->addColumn('changed', 'integer'); |
448
|
|
|
$table->addColumn('renamed', 'integer'); |
449
|
|
|
|
450
|
|
|
$tableDiff = new TableDiff('mytable'); |
451
|
|
|
$tableDiff->fromTable = $table; |
452
|
|
|
$tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
453
|
|
|
$tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
454
|
|
|
$tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
455
|
|
|
'changed', new \Doctrine\DBAL\Schema\Column( |
456
|
|
|
'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array() |
457
|
|
|
), |
458
|
|
|
array() |
459
|
|
|
); |
460
|
|
|
$tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
461
|
|
|
|
462
|
|
|
$this->_platform->getAlterTableSQL($tableDiff); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* @group DBAL-42 |
467
|
|
|
*/ |
468
|
|
|
public function testCreateTableColumnComments() |
469
|
|
|
{ |
470
|
|
|
$table = new Table('test'); |
471
|
|
|
$table->addColumn('id', 'integer', array('comment' => 'This is a comment')); |
472
|
|
|
$table->setPrimaryKey(array('id')); |
473
|
|
|
|
474
|
|
|
self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table)); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @group DBAL-42 |
479
|
|
|
*/ |
480
|
|
|
public function testAlterTableColumnComments() |
481
|
|
|
{ |
482
|
|
|
$tableDiff = new TableDiff('mytable'); |
483
|
|
|
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment')); |
484
|
|
|
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
485
|
|
|
'foo', new \Doctrine\DBAL\Schema\Column( |
486
|
|
|
'foo', \Doctrine\DBAL\Types\Type::getType('string') |
487
|
|
|
), |
488
|
|
|
array('comment') |
489
|
|
|
); |
490
|
|
|
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
491
|
|
|
'bar', new \Doctrine\DBAL\Schema\Column( |
492
|
|
|
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment') |
493
|
|
|
), |
494
|
|
|
array('comment') |
495
|
|
|
); |
496
|
|
|
|
497
|
|
|
self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
public function testCreateTableColumnTypeComments() |
501
|
|
|
{ |
502
|
|
|
$table = new Table('test'); |
503
|
|
|
$table->addColumn('id', 'integer'); |
504
|
|
|
$table->addColumn('data', 'array'); |
505
|
|
|
$table->setPrimaryKey(array('id')); |
506
|
|
|
|
507
|
|
|
self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
public function getCreateTableColumnCommentsSQL() |
511
|
|
|
{ |
512
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
public function getAlterTableColumnCommentsSQL() |
516
|
|
|
{ |
517
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function getCreateTableColumnTypeCommentsSQL() |
521
|
|
|
{ |
522
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
public function testGetDefaultValueDeclarationSQL() |
526
|
|
|
{ |
527
|
|
|
// non-timestamp value will get single quotes |
528
|
|
|
$field = array( |
529
|
|
|
'type' => Type::getType('string'), |
530
|
|
|
'default' => 'non_timestamp' |
531
|
|
|
); |
532
|
|
|
|
533
|
|
|
self::assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field)); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @group 2859 |
538
|
|
|
*/ |
539
|
|
|
public function testGetDefaultValueDeclarationSQLDateTime() : void |
540
|
|
|
{ |
541
|
|
|
// timestamps on datetime types should not be quoted |
542
|
|
|
foreach (['datetime', 'datetimetz', 'datetime_immutable', 'datetimetz_immutable'] as $type) { |
543
|
|
|
$field = [ |
544
|
|
|
'type' => Type::getType($type), |
545
|
|
|
'default' => $this->_platform->getCurrentTimestampSQL(), |
546
|
|
|
]; |
547
|
|
|
|
548
|
|
|
self::assertSame( |
549
|
|
|
' DEFAULT ' . $this->_platform->getCurrentTimestampSQL(), |
550
|
|
|
$this->_platform->getDefaultValueDeclarationSQL($field) |
551
|
|
|
); |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
public function testGetDefaultValueDeclarationSQLForIntegerTypes() |
556
|
|
|
{ |
557
|
|
|
foreach(array('bigint', 'integer', 'smallint') as $type) { |
558
|
|
|
$field = array( |
559
|
|
|
'type' => Type::getType($type), |
560
|
|
|
'default' => 1 |
561
|
|
|
); |
562
|
|
|
|
563
|
|
|
self::assertEquals( |
564
|
|
|
' DEFAULT 1', |
565
|
|
|
$this->_platform->getDefaultValueDeclarationSQL($field) |
566
|
|
|
); |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* @group 2859 |
572
|
|
|
*/ |
573
|
|
|
public function testGetDefaultValueDeclarationSQLForDateType() : void |
574
|
|
|
{ |
575
|
|
|
$currentDateSql = $this->_platform->getCurrentDateSQL(); |
576
|
|
|
foreach (['date', 'date_immutable'] as $type) { |
577
|
|
|
$field = [ |
578
|
|
|
'type' => Type::getType($type), |
579
|
|
|
'default' => $currentDateSql, |
580
|
|
|
]; |
581
|
|
|
|
582
|
|
|
self::assertSame( |
583
|
|
|
' DEFAULT ' . $currentDateSql, |
584
|
|
|
$this->_platform->getDefaultValueDeclarationSQL($field) |
585
|
|
|
); |
586
|
|
|
} |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* @group DBAL-45 |
591
|
|
|
*/ |
592
|
|
|
public function testKeywordList() |
593
|
|
|
{ |
594
|
|
|
$keywordList = $this->_platform->getReservedKeywordsList(); |
595
|
|
|
self::assertInstanceOf('Doctrine\DBAL\Platforms\Keywords\KeywordList', $keywordList); |
596
|
|
|
|
597
|
|
|
self::assertTrue($keywordList->isKeyword('table')); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* @group DBAL-374 |
602
|
|
|
*/ |
603
|
|
|
public function testQuotedColumnInPrimaryKeyPropagation() |
604
|
|
|
{ |
605
|
|
|
$table = new Table('`quoted`'); |
606
|
|
|
$table->addColumn('create', 'string'); |
607
|
|
|
$table->setPrimaryKey(array('create')); |
608
|
|
|
|
609
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
610
|
|
|
self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
abstract protected function getQuotedColumnInPrimaryKeySQL(); |
614
|
|
|
abstract protected function getQuotedColumnInIndexSQL(); |
615
|
|
|
abstract protected function getQuotedNameInIndexSQL(); |
616
|
|
|
abstract protected function getQuotedColumnInForeignKeySQL(); |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* @group DBAL-374 |
620
|
|
|
*/ |
621
|
|
|
public function testQuotedColumnInIndexPropagation() |
622
|
|
|
{ |
623
|
|
|
$table = new Table('`quoted`'); |
624
|
|
|
$table->addColumn('create', 'string'); |
625
|
|
|
$table->addIndex(array('create')); |
626
|
|
|
|
627
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
628
|
|
|
self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
public function testQuotedNameInIndexSQL() |
632
|
|
|
{ |
633
|
|
|
$table = new Table('test'); |
634
|
|
|
$table->addColumn('column1', 'string'); |
635
|
|
|
$table->addIndex(array('column1'), '`key`'); |
636
|
|
|
|
637
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
638
|
|
|
self::assertEquals($this->getQuotedNameInIndexSQL(), $sql); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* @group DBAL-374 |
643
|
|
|
*/ |
644
|
|
|
public function testQuotedColumnInForeignKeyPropagation() |
645
|
|
|
{ |
646
|
|
|
$table = new Table('`quoted`'); |
647
|
|
|
$table->addColumn('create', 'string'); |
648
|
|
|
$table->addColumn('foo', 'string'); |
649
|
|
|
$table->addColumn('`bar`', 'string'); |
650
|
|
|
|
651
|
|
|
// Foreign table with reserved keyword as name (needs quotation). |
652
|
|
|
$foreignTable = new Table('foreign'); |
653
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
654
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
655
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
656
|
|
|
|
657
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_RESERVED_KEYWORD'); |
658
|
|
|
|
659
|
|
|
// Foreign table with non-reserved keyword as name (does not need quotation). |
660
|
|
|
$foreignTable = new Table('foo'); |
661
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
662
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
663
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
664
|
|
|
|
665
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_NON_RESERVED_KEYWORD'); |
666
|
|
|
|
667
|
|
|
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
668
|
|
|
$foreignTable = new Table('`foo-bar`'); |
669
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
670
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
671
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
672
|
|
|
|
673
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_INTENDED_QUOTATION'); |
674
|
|
|
|
675
|
|
|
$sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); |
676
|
|
|
self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* @group DBAL-1051 |
681
|
|
|
*/ |
682
|
|
|
public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
683
|
|
|
{ |
684
|
|
|
$index = new Index('select', array('foo'), true); |
685
|
|
|
|
686
|
|
|
self::assertSame( |
687
|
|
|
$this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(), |
688
|
|
|
$this->_platform->getUniqueConstraintDeclarationSQL('select', $index) |
689
|
|
|
); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* @return string |
694
|
|
|
*/ |
695
|
|
|
abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(); |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* @group DBAL-2270 |
699
|
|
|
*/ |
700
|
|
|
public function testQuotesReservedKeywordInTruncateTableSQL() |
701
|
|
|
{ |
702
|
|
|
self::assertSame( |
703
|
|
|
$this->getQuotesReservedKeywordInTruncateTableSQL(), |
704
|
|
|
$this->_platform->getTruncateTableSQL('select') |
705
|
|
|
); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
/** |
709
|
|
|
* @return string |
710
|
|
|
*/ |
711
|
|
|
abstract protected function getQuotesReservedKeywordInTruncateTableSQL(); |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* @group DBAL-1051 |
715
|
|
|
*/ |
716
|
|
|
public function testQuotesReservedKeywordInIndexDeclarationSQL() |
717
|
|
|
{ |
718
|
|
|
$index = new Index('select', array('foo')); |
719
|
|
|
|
720
|
|
|
if (! $this->supportsInlineIndexDeclaration()) { |
721
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
self::assertSame( |
725
|
|
|
$this->getQuotesReservedKeywordInIndexDeclarationSQL(), |
726
|
|
|
$this->_platform->getIndexDeclarationSQL('select', $index) |
727
|
|
|
); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
/** |
731
|
|
|
* @return string |
732
|
|
|
*/ |
733
|
|
|
abstract protected function getQuotesReservedKeywordInIndexDeclarationSQL(); |
734
|
|
|
|
735
|
|
|
/** |
736
|
|
|
* @return bool |
737
|
|
|
*/ |
738
|
|
|
protected function supportsInlineIndexDeclaration() |
739
|
|
|
{ |
740
|
|
|
return true; |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
public function testSupportsCommentOnStatement() |
744
|
|
|
{ |
745
|
|
|
self::assertSame($this->supportsCommentOnStatement(), $this->_platform->supportsCommentOnStatement()); |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
/** |
749
|
|
|
* @return bool |
750
|
|
|
*/ |
751
|
|
|
protected function supportsCommentOnStatement() |
752
|
|
|
{ |
753
|
|
|
return false; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
758
|
|
|
*/ |
759
|
|
|
public function testGetCreateSchemaSQL() |
760
|
|
|
{ |
761
|
|
|
$this->_platform->getCreateSchemaSQL('schema'); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
/** |
765
|
|
|
* @group DBAL-585 |
766
|
|
|
*/ |
767
|
|
|
public function testAlterTableChangeQuotedColumn() |
768
|
|
|
{ |
769
|
|
|
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); |
770
|
|
|
$tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable'); |
771
|
|
|
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
772
|
|
|
'select', new \Doctrine\DBAL\Schema\Column( |
773
|
|
|
'select', \Doctrine\DBAL\Types\Type::getType('string') |
774
|
|
|
), |
775
|
|
|
array('type') |
776
|
|
|
); |
777
|
|
|
|
778
|
|
|
self::assertContains( |
779
|
|
|
$this->_platform->quoteIdentifier('select'), |
780
|
|
|
implode(';', $this->_platform->getAlterTableSQL($tableDiff)) |
781
|
|
|
); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
/** |
785
|
|
|
* @group DBAL-563 |
786
|
|
|
*/ |
787
|
|
|
public function testUsesSequenceEmulatedIdentityColumns() |
788
|
|
|
{ |
789
|
|
|
self::assertFalse($this->_platform->usesSequenceEmulatedIdentityColumns()); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* @group DBAL-563 |
794
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
795
|
|
|
*/ |
796
|
|
|
public function testReturnsIdentitySequenceName() |
797
|
|
|
{ |
798
|
|
|
$this->_platform->getIdentitySequenceName('mytable', 'mycolumn'); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
public function testReturnsBinaryDefaultLength() |
802
|
|
|
{ |
803
|
|
|
self::assertSame($this->getBinaryDefaultLength(), $this->_platform->getBinaryDefaultLength()); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
protected function getBinaryDefaultLength() |
807
|
|
|
{ |
808
|
|
|
return 255; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
public function testReturnsBinaryMaxLength() |
812
|
|
|
{ |
813
|
|
|
self::assertSame($this->getBinaryMaxLength(), $this->_platform->getBinaryMaxLength()); |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
protected function getBinaryMaxLength() |
817
|
|
|
{ |
818
|
|
|
return 4000; |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
/** |
822
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
823
|
|
|
*/ |
824
|
|
|
public function testReturnsBinaryTypeDeclarationSQL() |
825
|
|
|
{ |
826
|
|
|
$this->_platform->getBinaryTypeDeclarationSQL(array()); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* @group DBAL-553 |
831
|
|
|
*/ |
832
|
|
|
public function hasNativeJsonType() |
833
|
|
|
{ |
834
|
|
|
self::assertFalse($this->_platform->hasNativeJsonType()); |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
/** |
838
|
|
|
* @group DBAL-553 |
839
|
|
|
*/ |
840
|
|
|
public function testReturnsJsonTypeDeclarationSQL() |
841
|
|
|
{ |
842
|
|
|
$column = array( |
843
|
|
|
'length' => 666, |
844
|
|
|
'notnull' => true, |
845
|
|
|
'type' => Type::getType('json_array'), |
846
|
|
|
); |
847
|
|
|
|
848
|
|
|
self::assertSame( |
849
|
|
|
$this->_platform->getClobTypeDeclarationSQL($column), |
850
|
|
|
$this->_platform->getJsonTypeDeclarationSQL($column) |
851
|
|
|
); |
852
|
|
|
} |
853
|
|
|
|
854
|
|
|
/** |
855
|
|
|
* @group DBAL-234 |
856
|
|
|
*/ |
857
|
|
|
public function testAlterTableRenameIndex() |
858
|
|
|
{ |
859
|
|
|
$tableDiff = new TableDiff('mytable'); |
860
|
|
|
$tableDiff->fromTable = new Table('mytable'); |
861
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
862
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
863
|
|
|
$tableDiff->renamedIndexes = array( |
864
|
|
|
'idx_foo' => new Index('idx_bar', array('id')) |
865
|
|
|
); |
866
|
|
|
|
867
|
|
|
self::assertSame( |
868
|
|
|
$this->getAlterTableRenameIndexSQL(), |
869
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
870
|
|
|
); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
/** |
874
|
|
|
* @group DBAL-234 |
875
|
|
|
*/ |
876
|
|
|
protected function getAlterTableRenameIndexSQL() |
877
|
|
|
{ |
878
|
|
|
return array( |
879
|
|
|
'DROP INDEX idx_foo', |
880
|
|
|
'CREATE INDEX idx_bar ON mytable (id)', |
881
|
|
|
); |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* @group DBAL-234 |
886
|
|
|
*/ |
887
|
|
|
public function testQuotesAlterTableRenameIndex() |
888
|
|
|
{ |
889
|
|
|
$tableDiff = new TableDiff('table'); |
890
|
|
|
$tableDiff->fromTable = new Table('table'); |
891
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
892
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
893
|
|
|
$tableDiff->renamedIndexes = array( |
894
|
|
|
'create' => new Index('select', array('id')), |
895
|
|
|
'`foo`' => new Index('`bar`', array('id')), |
896
|
|
|
); |
897
|
|
|
|
898
|
|
|
self::assertSame( |
899
|
|
|
$this->getQuotedAlterTableRenameIndexSQL(), |
900
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
901
|
|
|
); |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
/** |
905
|
|
|
* @group DBAL-234 |
906
|
|
|
*/ |
907
|
|
|
protected function getQuotedAlterTableRenameIndexSQL() |
908
|
|
|
{ |
909
|
|
|
return array( |
910
|
|
|
'DROP INDEX "create"', |
911
|
|
|
'CREATE INDEX "select" ON "table" (id)', |
912
|
|
|
'DROP INDEX "foo"', |
913
|
|
|
'CREATE INDEX "bar" ON "table" (id)', |
914
|
|
|
); |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
/** |
918
|
|
|
* @group DBAL-835 |
919
|
|
|
*/ |
920
|
|
|
public function testQuotesAlterTableRenameColumn() |
921
|
|
|
{ |
922
|
|
|
$fromTable = new Table('mytable'); |
923
|
|
|
|
924
|
|
|
$fromTable->addColumn('unquoted1', 'integer', array('comment' => 'Unquoted 1')); |
925
|
|
|
$fromTable->addColumn('unquoted2', 'integer', array('comment' => 'Unquoted 2')); |
926
|
|
|
$fromTable->addColumn('unquoted3', 'integer', array('comment' => 'Unquoted 3')); |
927
|
|
|
|
928
|
|
|
$fromTable->addColumn('create', 'integer', array('comment' => 'Reserved keyword 1')); |
929
|
|
|
$fromTable->addColumn('table', 'integer', array('comment' => 'Reserved keyword 2')); |
930
|
|
|
$fromTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword 3')); |
931
|
|
|
|
932
|
|
|
$fromTable->addColumn('`quoted1`', 'integer', array('comment' => 'Quoted 1')); |
933
|
|
|
$fromTable->addColumn('`quoted2`', 'integer', array('comment' => 'Quoted 2')); |
934
|
|
|
$fromTable->addColumn('`quoted3`', 'integer', array('comment' => 'Quoted 3')); |
935
|
|
|
|
936
|
|
|
$toTable = new Table('mytable'); |
937
|
|
|
|
938
|
|
|
$toTable->addColumn('unquoted', 'integer', array('comment' => 'Unquoted 1')); // unquoted -> unquoted |
939
|
|
|
$toTable->addColumn('where', 'integer', array('comment' => 'Unquoted 2')); // unquoted -> reserved keyword |
940
|
|
|
$toTable->addColumn('`foo`', 'integer', array('comment' => 'Unquoted 3')); // unquoted -> quoted |
941
|
|
|
|
942
|
|
|
$toTable->addColumn('reserved_keyword', 'integer', array('comment' => 'Reserved keyword 1')); // reserved keyword -> unquoted |
943
|
|
|
$toTable->addColumn('from', 'integer', array('comment' => 'Reserved keyword 2')); // reserved keyword -> reserved keyword |
944
|
|
|
$toTable->addColumn('`bar`', 'integer', array('comment' => 'Reserved keyword 3')); // reserved keyword -> quoted |
945
|
|
|
|
946
|
|
|
$toTable->addColumn('quoted', 'integer', array('comment' => 'Quoted 1')); // quoted -> unquoted |
947
|
|
|
$toTable->addColumn('and', 'integer', array('comment' => 'Quoted 2')); // quoted -> reserved keyword |
948
|
|
|
$toTable->addColumn('`baz`', 'integer', array('comment' => 'Quoted 3')); // quoted -> quoted |
949
|
|
|
|
950
|
|
|
$comparator = new Comparator(); |
951
|
|
|
|
952
|
|
|
self::assertEquals( |
953
|
|
|
$this->getQuotedAlterTableRenameColumnSQL(), |
954
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) |
955
|
|
|
); |
956
|
|
|
} |
957
|
|
|
|
958
|
|
|
/** |
959
|
|
|
* Returns SQL statements for {@link testQuotesAlterTableRenameColumn}. |
960
|
|
|
* |
961
|
|
|
* @return array |
962
|
|
|
* |
963
|
|
|
* @group DBAL-835 |
964
|
|
|
*/ |
965
|
|
|
abstract protected function getQuotedAlterTableRenameColumnSQL(); |
966
|
|
|
|
967
|
|
|
/** |
968
|
|
|
* @group DBAL-835 |
969
|
|
|
*/ |
970
|
|
|
public function testQuotesAlterTableChangeColumnLength() |
971
|
|
|
{ |
972
|
|
|
$fromTable = new Table('mytable'); |
973
|
|
|
|
974
|
|
|
$fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10)); |
975
|
|
|
$fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10)); |
976
|
|
|
$fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10)); |
977
|
|
|
|
978
|
|
|
$fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10)); |
979
|
|
|
$fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10)); |
980
|
|
|
$fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10)); |
981
|
|
|
|
982
|
|
|
$toTable = new Table('mytable'); |
983
|
|
|
|
984
|
|
|
$toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255)); |
985
|
|
|
$toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255)); |
986
|
|
|
$toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255)); |
987
|
|
|
|
988
|
|
|
$toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255)); |
989
|
|
|
$toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255)); |
990
|
|
|
$toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255)); |
991
|
|
|
|
992
|
|
|
$comparator = new Comparator(); |
993
|
|
|
|
994
|
|
|
self::assertEquals( |
995
|
|
|
$this->getQuotedAlterTableChangeColumnLengthSQL(), |
996
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) |
997
|
|
|
); |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}. |
1002
|
|
|
* |
1003
|
|
|
* @return array |
1004
|
|
|
* |
1005
|
|
|
* @group DBAL-835 |
1006
|
|
|
*/ |
1007
|
|
|
abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); |
1008
|
|
|
|
1009
|
|
|
/** |
1010
|
|
|
* @group DBAL-807 |
1011
|
|
|
*/ |
1012
|
|
|
public function testAlterTableRenameIndexInSchema() |
1013
|
|
|
{ |
1014
|
|
|
$tableDiff = new TableDiff('myschema.mytable'); |
1015
|
|
|
$tableDiff->fromTable = new Table('myschema.mytable'); |
1016
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
1017
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
1018
|
|
|
$tableDiff->renamedIndexes = array( |
1019
|
|
|
'idx_foo' => new Index('idx_bar', array('id')) |
1020
|
|
|
); |
1021
|
|
|
|
1022
|
|
|
self::assertSame( |
1023
|
|
|
$this->getAlterTableRenameIndexInSchemaSQL(), |
1024
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1025
|
|
|
); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
/** |
1029
|
|
|
* @group DBAL-807 |
1030
|
|
|
*/ |
1031
|
|
|
protected function getAlterTableRenameIndexInSchemaSQL() |
1032
|
|
|
{ |
1033
|
|
|
return array( |
1034
|
|
|
'DROP INDEX idx_foo', |
1035
|
|
|
'CREATE INDEX idx_bar ON myschema.mytable (id)', |
1036
|
|
|
); |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
/** |
1040
|
|
|
* @group DBAL-807 |
1041
|
|
|
*/ |
1042
|
|
|
public function testQuotesAlterTableRenameIndexInSchema() |
1043
|
|
|
{ |
1044
|
|
|
$tableDiff = new TableDiff('`schema`.table'); |
1045
|
|
|
$tableDiff->fromTable = new Table('`schema`.table'); |
1046
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
1047
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
1048
|
|
|
$tableDiff->renamedIndexes = array( |
1049
|
|
|
'create' => new Index('select', array('id')), |
1050
|
|
|
'`foo`' => new Index('`bar`', array('id')), |
1051
|
|
|
); |
1052
|
|
|
|
1053
|
|
|
self::assertSame( |
1054
|
|
|
$this->getQuotedAlterTableRenameIndexInSchemaSQL(), |
1055
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1056
|
|
|
); |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
/** |
1060
|
|
|
* @group DBAL-234 |
1061
|
|
|
*/ |
1062
|
|
|
protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
1063
|
|
|
{ |
1064
|
|
|
return array( |
1065
|
|
|
'DROP INDEX "schema"."create"', |
1066
|
|
|
'CREATE INDEX "select" ON "schema"."table" (id)', |
1067
|
|
|
'DROP INDEX "schema"."foo"', |
1068
|
|
|
'CREATE INDEX "bar" ON "schema"."table" (id)', |
1069
|
|
|
); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* @group DBAL-1237 |
1074
|
|
|
*/ |
1075
|
|
|
public function testQuotesDropForeignKeySQL() |
1076
|
|
|
{ |
1077
|
|
|
if (! $this->_platform->supportsForeignKeyConstraints()) { |
1078
|
|
|
$this->markTestSkipped( |
1079
|
|
|
sprintf('%s does not support foreign key constraints.', get_class($this->_platform)) |
1080
|
|
|
); |
1081
|
|
|
} |
1082
|
|
|
|
1083
|
|
|
$tableName = 'table'; |
1084
|
|
|
$table = new Table($tableName); |
1085
|
|
|
$foreignKeyName = 'select'; |
1086
|
|
|
$foreignKey = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); |
1087
|
|
|
$expectedSql = $this->getQuotesDropForeignKeySQL(); |
1088
|
|
|
|
1089
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName)); |
1090
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table)); |
1091
|
|
|
} |
1092
|
|
|
|
1093
|
|
|
protected function getQuotesDropForeignKeySQL() |
1094
|
|
|
{ |
1095
|
|
|
return 'ALTER TABLE "table" DROP FOREIGN KEY "select"'; |
1096
|
|
|
} |
1097
|
|
|
|
1098
|
|
|
/** |
1099
|
|
|
* @group DBAL-1237 |
1100
|
|
|
*/ |
1101
|
|
|
public function testQuotesDropConstraintSQL() |
1102
|
|
|
{ |
1103
|
|
|
$tableName = 'table'; |
1104
|
|
|
$table = new Table($tableName); |
1105
|
|
|
$constraintName = 'select'; |
1106
|
|
|
$constraint = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); |
1107
|
|
|
$expectedSql = $this->getQuotesDropConstraintSQL(); |
1108
|
|
|
|
1109
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName)); |
1110
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table)); |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
protected function getQuotesDropConstraintSQL() |
1114
|
|
|
{ |
1115
|
|
|
return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
protected function getStringLiteralQuoteCharacter() |
1119
|
|
|
{ |
1120
|
|
|
return "'"; |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
public function testGetStringLiteralQuoteCharacter() |
1124
|
|
|
{ |
1125
|
|
|
self::assertSame($this->getStringLiteralQuoteCharacter(), $this->_platform->getStringLiteralQuoteCharacter()); |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
protected function getQuotedCommentOnColumnSQLWithoutQuoteCharacter() |
1129
|
|
|
{ |
1130
|
|
|
return "COMMENT ON COLUMN mytable.id IS 'This is a comment'"; |
1131
|
|
|
} |
1132
|
|
|
|
1133
|
|
|
public function testGetCommentOnColumnSQLWithoutQuoteCharacter() |
1134
|
|
|
{ |
1135
|
|
|
self::assertEquals( |
1136
|
|
|
$this->getQuotedCommentOnColumnSQLWithoutQuoteCharacter(), |
1137
|
|
|
$this->_platform->getCommentOnColumnSQL('mytable', 'id', 'This is a comment') |
1138
|
|
|
); |
1139
|
|
|
} |
1140
|
|
|
|
1141
|
|
|
protected function getQuotedCommentOnColumnSQLWithQuoteCharacter() |
1142
|
|
|
{ |
1143
|
|
|
return "COMMENT ON COLUMN mytable.id IS 'It''s a quote !'"; |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
public function testGetCommentOnColumnSQLWithQuoteCharacter() |
1147
|
|
|
{ |
1148
|
|
|
$c = $this->getStringLiteralQuoteCharacter(); |
1149
|
|
|
|
1150
|
|
|
self::assertEquals( |
1151
|
|
|
$this->getQuotedCommentOnColumnSQLWithQuoteCharacter(), |
1152
|
|
|
$this->_platform->getCommentOnColumnSQL('mytable', 'id', "It" . $c . "s a quote !") |
1153
|
|
|
); |
1154
|
|
|
} |
1155
|
|
|
|
1156
|
|
|
/** |
1157
|
|
|
* @return array |
1158
|
|
|
* |
1159
|
|
|
* @see testGetCommentOnColumnSQL |
1160
|
|
|
*/ |
1161
|
|
|
abstract protected function getCommentOnColumnSQL(); |
1162
|
|
|
|
1163
|
|
|
/** |
1164
|
|
|
* @group DBAL-1004 |
1165
|
|
|
*/ |
1166
|
|
|
public function testGetCommentOnColumnSQL() |
1167
|
|
|
{ |
1168
|
|
|
self::assertSame( |
1169
|
|
|
$this->getCommentOnColumnSQL(), |
1170
|
|
|
array( |
1171
|
|
|
$this->_platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers |
1172
|
|
|
$this->_platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers |
1173
|
|
|
$this->_platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers |
1174
|
|
|
) |
1175
|
|
|
); |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
/** |
1179
|
|
|
* @group DBAL-1176 |
1180
|
|
|
* |
1181
|
|
|
* @dataProvider getGeneratesInlineColumnCommentSQL |
1182
|
|
|
*/ |
1183
|
|
|
public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) |
1184
|
|
|
{ |
1185
|
|
|
if (! $this->_platform->supportsInlineColumnComments()) { |
1186
|
|
|
$this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->_platform))); |
1187
|
|
|
} |
1188
|
|
|
|
1189
|
|
|
self::assertSame($expectedSql, $this->_platform->getInlineColumnCommentSQL($comment)); |
1190
|
|
|
} |
1191
|
|
|
|
1192
|
|
|
public function getGeneratesInlineColumnCommentSQL() |
1193
|
|
|
{ |
1194
|
|
|
return array( |
1195
|
|
|
'regular comment' => array('Regular comment', $this->getInlineColumnRegularCommentSQL()), |
1196
|
|
|
'comment requiring escaping' => array( |
1197
|
|
|
sprintf( |
1198
|
|
|
'Using inline comment delimiter %s works', |
1199
|
|
|
$this->getInlineColumnCommentDelimiter() |
1200
|
|
|
), |
1201
|
|
|
$this->getInlineColumnCommentRequiringEscapingSQL() |
1202
|
|
|
), |
1203
|
|
|
'empty comment' => array('', $this->getInlineColumnEmptyCommentSQL()), |
1204
|
|
|
); |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
protected function getInlineColumnCommentDelimiter() |
1208
|
|
|
{ |
1209
|
|
|
return "'"; |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
protected function getInlineColumnRegularCommentSQL() |
1213
|
|
|
{ |
1214
|
|
|
return "COMMENT 'Regular comment'"; |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
protected function getInlineColumnCommentRequiringEscapingSQL() |
1218
|
|
|
{ |
1219
|
|
|
return "COMMENT 'Using inline comment delimiter '' works'"; |
1220
|
|
|
} |
1221
|
|
|
|
1222
|
|
|
protected function getInlineColumnEmptyCommentSQL() |
1223
|
|
|
{ |
1224
|
|
|
return "COMMENT ''"; |
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
protected function getQuotedStringLiteralWithoutQuoteCharacter() |
1228
|
|
|
{ |
1229
|
|
|
return "'No quote'"; |
1230
|
|
|
} |
1231
|
|
|
|
1232
|
|
|
protected function getQuotedStringLiteralWithQuoteCharacter() |
1233
|
|
|
{ |
1234
|
|
|
return "'It''s a quote'"; |
1235
|
|
|
} |
1236
|
|
|
|
1237
|
|
|
protected function getQuotedStringLiteralQuoteCharacter() |
1238
|
|
|
{ |
1239
|
|
|
return "''''"; |
1240
|
|
|
} |
1241
|
|
|
|
1242
|
|
|
/** |
1243
|
|
|
* @group DBAL-1176 |
1244
|
|
|
*/ |
1245
|
|
|
public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() |
1246
|
|
|
{ |
1247
|
|
|
if ($this->_platform->supportsInlineColumnComments()) { |
1248
|
|
|
$this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->_platform))); |
1249
|
|
|
} |
1250
|
|
|
|
1251
|
|
|
$this->expectException( |
1252
|
|
|
'Doctrine\DBAL\DBALException', |
1253
|
|
|
"Operation 'Doctrine\\DBAL\\Platforms\\AbstractPlatform::getInlineColumnCommentSQL' is not supported by platform.", |
|
|
|
|
1254
|
|
|
0 |
1255
|
|
|
); |
1256
|
|
|
|
1257
|
|
|
$this->_platform->getInlineColumnCommentSQL('unsupported'); |
1258
|
|
|
} |
1259
|
|
|
|
1260
|
|
|
public function testQuoteStringLiteral() |
1261
|
|
|
{ |
1262
|
|
|
$c = $this->getStringLiteralQuoteCharacter(); |
1263
|
|
|
|
1264
|
|
|
self::assertEquals( |
1265
|
|
|
$this->getQuotedStringLiteralWithoutQuoteCharacter(), |
1266
|
|
|
$this->_platform->quoteStringLiteral('No quote') |
1267
|
|
|
); |
1268
|
|
|
self::assertEquals( |
1269
|
|
|
$this->getQuotedStringLiteralWithQuoteCharacter(), |
1270
|
|
|
$this->_platform->quoteStringLiteral('It' . $c . 's a quote') |
1271
|
|
|
); |
1272
|
|
|
self::assertEquals( |
1273
|
|
|
$this->getQuotedStringLiteralQuoteCharacter(), |
1274
|
|
|
$this->_platform->quoteStringLiteral($c) |
1275
|
|
|
); |
1276
|
|
|
} |
1277
|
|
|
|
1278
|
|
|
/** |
1279
|
|
|
* @group DBAL-423 |
1280
|
|
|
* |
1281
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
1282
|
|
|
*/ |
1283
|
|
|
public function testReturnsGuidTypeDeclarationSQL() |
1284
|
|
|
{ |
1285
|
|
|
$this->_platform->getGuidTypeDeclarationSQL(array()); |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
|
/** |
1289
|
|
|
* @group DBAL-1010 |
1290
|
|
|
*/ |
1291
|
|
|
public function testGeneratesAlterTableRenameColumnSQL() |
1292
|
|
|
{ |
1293
|
|
|
$table = new Table('foo'); |
1294
|
|
|
$table->addColumn( |
1295
|
|
|
'bar', |
1296
|
|
|
'integer', |
1297
|
|
|
array('notnull' => true, 'default' => 666, 'comment' => 'rename test') |
1298
|
|
|
); |
1299
|
|
|
|
1300
|
|
|
$tableDiff = new TableDiff('foo'); |
1301
|
|
|
$tableDiff->fromTable = $table; |
1302
|
|
|
$tableDiff->renamedColumns['bar'] = new Column( |
1303
|
|
|
'baz', |
1304
|
|
|
Type::getType('integer'), |
1305
|
|
|
array('notnull' => true, 'default' => 666, 'comment' => 'rename test') |
1306
|
|
|
); |
1307
|
|
|
|
1308
|
|
|
self::assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff)); |
1309
|
|
|
} |
1310
|
|
|
|
1311
|
|
|
/** |
1312
|
|
|
* @return array |
1313
|
|
|
*/ |
1314
|
|
|
abstract public function getAlterTableRenameColumnSQL(); |
1315
|
|
|
|
1316
|
|
|
/** |
1317
|
|
|
* @group DBAL-1016 |
1318
|
|
|
*/ |
1319
|
|
|
public function testQuotesTableIdentifiersInAlterTableSQL() |
1320
|
|
|
{ |
1321
|
|
|
$table = new Table('"foo"'); |
1322
|
|
|
$table->addColumn('id', 'integer'); |
1323
|
|
|
$table->addColumn('fk', 'integer'); |
1324
|
|
|
$table->addColumn('fk2', 'integer'); |
1325
|
|
|
$table->addColumn('fk3', 'integer'); |
1326
|
|
|
$table->addColumn('bar', 'integer'); |
1327
|
|
|
$table->addColumn('baz', 'integer'); |
1328
|
|
|
$table->addForeignKeyConstraint('fk_table', array('fk'), array('id'), array(), 'fk1'); |
1329
|
|
|
$table->addForeignKeyConstraint('fk_table', array('fk2'), array('id'), array(), 'fk2'); |
1330
|
|
|
|
1331
|
|
|
$tableDiff = new TableDiff('"foo"'); |
1332
|
|
|
$tableDiff->fromTable = $table; |
1333
|
|
|
$tableDiff->newName = 'table'; |
1334
|
|
|
$tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); |
1335
|
|
|
$tableDiff->changedColumns['bar'] = new ColumnDiff( |
1336
|
|
|
'bar', |
1337
|
|
|
new Column('bar', Type::getType('integer'), array('notnull' => false)), |
1338
|
|
|
array('notnull'), |
1339
|
|
|
$table->getColumn('bar') |
1340
|
|
|
); |
1341
|
|
|
$tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); |
1342
|
|
|
$tableDiff->removedColumns['baz'] = new Column('baz', Type::getType('integer')); |
1343
|
|
|
$tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(array('fk3'), 'fk_table', array('id'), 'fk_add'); |
1344
|
|
|
$tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(array('fk2'), 'fk_table2', array('id'), 'fk2'); |
1345
|
|
|
$tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(array('fk'), 'fk_table', array('id'), 'fk1'); |
1346
|
|
|
|
1347
|
|
|
self::assertSame( |
1348
|
|
|
$this->getQuotesTableIdentifiersInAlterTableSQL(), |
1349
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1350
|
|
|
); |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
/** |
1354
|
|
|
* @return array |
1355
|
|
|
*/ |
1356
|
|
|
abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); |
1357
|
|
|
|
1358
|
|
|
/** |
1359
|
|
|
* @group DBAL-1090 |
1360
|
|
|
*/ |
1361
|
|
|
public function testAlterStringToFixedString() |
1362
|
|
|
{ |
1363
|
|
|
|
1364
|
|
|
$table = new Table('mytable'); |
1365
|
|
|
$table->addColumn('name', 'string', array('length' => 2)); |
1366
|
|
|
|
1367
|
|
|
$tableDiff = new TableDiff('mytable'); |
1368
|
|
|
$tableDiff->fromTable = $table; |
1369
|
|
|
|
1370
|
|
|
$tableDiff->changedColumns['name'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
1371
|
|
|
'name', new \Doctrine\DBAL\Schema\Column( |
1372
|
|
|
'name', \Doctrine\DBAL\Types\Type::getType('string'), array('fixed' => true, 'length' => 2) |
1373
|
|
|
), |
1374
|
|
|
array('fixed') |
1375
|
|
|
); |
1376
|
|
|
|
1377
|
|
|
$sql = $this->_platform->getAlterTableSQL($tableDiff); |
1378
|
|
|
|
1379
|
|
|
$expectedSql = $this->getAlterStringToFixedStringSQL(); |
1380
|
|
|
|
1381
|
|
|
self::assertEquals($expectedSql, $sql); |
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
/** |
1385
|
|
|
* @return array |
1386
|
|
|
*/ |
1387
|
|
|
abstract protected function getAlterStringToFixedStringSQL(); |
1388
|
|
|
|
1389
|
|
|
/** |
1390
|
|
|
* @group DBAL-1062 |
1391
|
|
|
*/ |
1392
|
|
|
public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
1393
|
|
|
{ |
1394
|
|
|
$foreignTable = new Table('foreign_table'); |
1395
|
|
|
$foreignTable->addColumn('id', 'integer'); |
1396
|
|
|
$foreignTable->setPrimaryKey(array('id')); |
1397
|
|
|
|
1398
|
|
|
$primaryTable = new Table('mytable'); |
1399
|
|
|
$primaryTable->addColumn('foo', 'integer'); |
1400
|
|
|
$primaryTable->addColumn('bar', 'integer'); |
1401
|
|
|
$primaryTable->addColumn('baz', 'integer'); |
1402
|
|
|
$primaryTable->addIndex(array('foo'), 'idx_foo'); |
1403
|
|
|
$primaryTable->addIndex(array('bar'), 'idx_bar'); |
1404
|
|
|
$primaryTable->addForeignKeyConstraint($foreignTable, array('foo'), array('id'), array(), 'fk_foo'); |
1405
|
|
|
$primaryTable->addForeignKeyConstraint($foreignTable, array('bar'), array('id'), array(), 'fk_bar'); |
1406
|
|
|
|
1407
|
|
|
$tableDiff = new TableDiff('mytable'); |
1408
|
|
|
$tableDiff->fromTable = $primaryTable; |
1409
|
|
|
$tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', array('foo')); |
1410
|
|
|
|
1411
|
|
|
self::assertSame( |
1412
|
|
|
$this->getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(), |
1413
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1414
|
|
|
); |
1415
|
|
|
} |
1416
|
|
|
|
1417
|
|
|
/** |
1418
|
|
|
* @return array |
1419
|
|
|
*/ |
1420
|
|
|
abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(); |
1421
|
|
|
|
1422
|
|
|
/** |
1423
|
|
|
* @group DBAL-1082 |
1424
|
|
|
* |
1425
|
|
|
* @dataProvider getGeneratesDecimalTypeDeclarationSQL |
1426
|
|
|
*/ |
1427
|
|
|
public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) |
1428
|
|
|
{ |
1429
|
|
|
self::assertSame($expectedSql, $this->_platform->getDecimalTypeDeclarationSQL($column)); |
1430
|
|
|
} |
1431
|
|
|
|
1432
|
|
|
/** |
1433
|
|
|
* @return array |
1434
|
|
|
*/ |
1435
|
|
|
public function getGeneratesDecimalTypeDeclarationSQL() |
1436
|
|
|
{ |
1437
|
|
|
return array( |
1438
|
|
|
array(array(), 'NUMERIC(10, 0)'), |
1439
|
|
|
array(array('unsigned' => true), 'NUMERIC(10, 0)'), |
1440
|
|
|
array(array('unsigned' => false), 'NUMERIC(10, 0)'), |
1441
|
|
|
array(array('precision' => 5), 'NUMERIC(5, 0)'), |
1442
|
|
|
array(array('scale' => 5), 'NUMERIC(10, 5)'), |
1443
|
|
|
array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), |
1444
|
|
|
); |
1445
|
|
|
} |
1446
|
|
|
|
1447
|
|
|
/** |
1448
|
|
|
* @group DBAL-1082 |
1449
|
|
|
* |
1450
|
|
|
* @dataProvider getGeneratesFloatDeclarationSQL |
1451
|
|
|
*/ |
1452
|
|
|
public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) |
1453
|
|
|
{ |
1454
|
|
|
self::assertSame($expectedSql, $this->_platform->getFloatDeclarationSQL($column)); |
1455
|
|
|
} |
1456
|
|
|
|
1457
|
|
|
/** |
1458
|
|
|
* @return array |
1459
|
|
|
*/ |
1460
|
|
|
public function getGeneratesFloatDeclarationSQL() |
1461
|
|
|
{ |
1462
|
|
|
return array( |
1463
|
|
|
array(array(), 'DOUBLE PRECISION'), |
1464
|
|
|
array(array('unsigned' => true), 'DOUBLE PRECISION'), |
1465
|
|
|
array(array('unsigned' => false), 'DOUBLE PRECISION'), |
1466
|
|
|
array(array('precision' => 5), 'DOUBLE PRECISION'), |
1467
|
|
|
array(array('scale' => 5), 'DOUBLE PRECISION'), |
1468
|
|
|
array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), |
1469
|
|
|
); |
1470
|
|
|
} |
1471
|
|
|
|
1472
|
|
|
public function testItEscapesStringsForLike() : void |
1473
|
|
|
{ |
1474
|
|
|
self::assertSame( |
1475
|
|
|
'\_25\% off\_ your next purchase \\\\o/', |
1476
|
|
|
$this->_platform->escapeStringForLike('_25% off_ your next purchase \o/', '\\') |
1477
|
|
|
); |
1478
|
|
|
} |
1479
|
|
|
} |
1480
|
|
|
|