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