1 | <?php |
||
2 | |||
3 | namespace Doctrine\Tests\DBAL\Platforms; |
||
4 | |||
5 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
||
6 | use Doctrine\DBAL\Platforms\DB2Platform; |
||
7 | use Doctrine\DBAL\Schema\Column; |
||
8 | use Doctrine\DBAL\Schema\ColumnDiff; |
||
9 | use Doctrine\DBAL\Schema\Index; |
||
10 | use Doctrine\DBAL\Schema\Table; |
||
11 | use Doctrine\DBAL\Schema\TableDiff; |
||
12 | use Doctrine\DBAL\Types\Type; |
||
13 | |||
14 | class DB2PlatformTest extends AbstractPlatformTestCase |
||
15 | { |
||
16 | /** @var DB2Platform */ |
||
17 | protected $platform; |
||
18 | |||
19 | public function createPlatform() |
||
20 | { |
||
21 | return new DB2Platform(); |
||
22 | } |
||
23 | |||
24 | public function getGenerateAlterTableSql() |
||
25 | { |
||
26 | return [ |
||
27 | 'ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)', |
||
28 | 'ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL', |
||
29 | "ALTER TABLE mytable ALTER COLUMN baz SET DEFAULT 'def'", |
||
30 | 'ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT', |
||
31 | 'ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL', |
||
32 | "ALTER TABLE mytable ALTER COLUMN bloo SET DEFAULT '0'", |
||
33 | 'ALTER TABLE mytable ' . |
||
34 | 'ADD COLUMN quota INTEGER DEFAULT NULL ' . |
||
35 | 'DROP COLUMN foo', |
||
36 | "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", |
||
37 | 'RENAME TABLE mytable TO userlist', |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | public function getGenerateForeignKeySql() |
||
42 | { |
||
43 | return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; |
||
44 | } |
||
45 | |||
46 | public function getGenerateIndexSql() |
||
47 | { |
||
48 | return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; |
||
49 | } |
||
50 | |||
51 | public function getGenerateTableSql() |
||
52 | { |
||
53 | return 'CREATE TABLE test (id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; |
||
54 | } |
||
55 | |||
56 | public function getGenerateTableWithMultiColumnUniqueIndexSql() |
||
57 | { |
||
58 | return [ |
||
59 | 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', |
||
60 | 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', |
||
61 | ]; |
||
62 | } |
||
63 | |||
64 | public function getGenerateUniqueIndexSql() |
||
65 | { |
||
66 | return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; |
||
67 | } |
||
68 | |||
69 | protected function getQuotedColumnInForeignKeySQL() |
||
70 | { |
||
71 | return [ |
||
72 | 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', |
||
73 | 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar")', |
||
74 | 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar")', |
||
75 | 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")', |
||
76 | ]; |
||
77 | } |
||
78 | |||
79 | protected function getQuotedColumnInIndexSQL() |
||
80 | { |
||
81 | return [ |
||
82 | 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', |
||
83 | 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', |
||
84 | ]; |
||
85 | } |
||
86 | |||
87 | protected function getQuotedNameInIndexSQL() |
||
88 | { |
||
89 | return [ |
||
90 | 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', |
||
91 | 'CREATE INDEX "key" ON test (column1)', |
||
92 | ]; |
||
93 | } |
||
94 | |||
95 | protected function getQuotedColumnInPrimaryKeySQL() |
||
96 | { |
||
97 | return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; |
||
98 | } |
||
99 | |||
100 | protected function getBitAndComparisonExpressionSql($value1, $value2) |
||
101 | { |
||
102 | return 'BITAND(' . $value1 . ', ' . $value2 . ')'; |
||
103 | } |
||
104 | |||
105 | protected function getBitOrComparisonExpressionSql($value1, $value2) |
||
106 | { |
||
107 | return 'BITOR(' . $value1 . ', ' . $value2 . ')'; |
||
108 | } |
||
109 | |||
110 | public function getCreateTableColumnCommentsSQL() |
||
111 | { |
||
112 | return [ |
||
113 | 'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))', |
||
114 | "COMMENT ON COLUMN test.id IS 'This is a comment'", |
||
115 | ]; |
||
116 | } |
||
117 | |||
118 | public function getAlterTableColumnCommentsSQL() |
||
119 | { |
||
120 | return [ |
||
121 | 'ALTER TABLE mytable ' . |
||
122 | 'ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT', |
||
123 | "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", |
||
124 | "COMMENT ON COLUMN mytable.quota IS 'A comment'", |
||
125 | "COMMENT ON COLUMN mytable.foo IS ''", |
||
126 | "COMMENT ON COLUMN mytable.baz IS 'B comment'", |
||
127 | ]; |
||
128 | } |
||
129 | |||
130 | public function getCreateTableColumnTypeCommentsSQL() |
||
131 | { |
||
132 | return [ |
||
133 | 'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))', |
||
134 | 'COMMENT ON COLUMN test."data" IS \'(DC2Type:array)\'', |
||
135 | ]; |
||
136 | } |
||
137 | |||
138 | public function testHasCorrectPlatformName() |
||
139 | { |
||
140 | self::assertEquals('db2', $this->platform->getName()); |
||
141 | } |
||
142 | |||
143 | public function testGeneratesCreateTableSQLWithCommonIndexes() |
||
144 | { |
||
145 | $table = new Table('test'); |
||
146 | $table->addColumn('id', 'integer'); |
||
147 | $table->addColumn('name', 'string', ['length' => 50]); |
||
148 | $table->setPrimaryKey(['id']); |
||
149 | $table->addIndex(['name']); |
||
150 | $table->addIndex(['id', 'name'], 'composite_idx'); |
||
151 | |||
152 | self::assertEquals( |
||
153 | [ |
||
154 | 'CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))', |
||
155 | 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', |
||
156 | 'CREATE INDEX composite_idx ON test (id, name)', |
||
157 | ], |
||
158 | $this->platform->getCreateTableSQL($table) |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | public function testGeneratesCreateTableSQLWithForeignKeyConstraints() |
||
163 | { |
||
164 | $table = new Table('test'); |
||
165 | $table->addColumn('id', 'integer'); |
||
166 | $table->addColumn('fk_1', 'integer'); |
||
167 | $table->addColumn('fk_2', 'integer'); |
||
168 | $table->setPrimaryKey(['id']); |
||
169 | $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); |
||
170 | $table->addForeignKeyConstraint( |
||
171 | 'foreign_table2', |
||
172 | ['fk_1', 'fk_2'], |
||
173 | ['pk_1', 'pk_2'], |
||
174 | [], |
||
175 | 'named_fk' |
||
176 | ); |
||
177 | |||
178 | self::assertEquals( |
||
179 | [ |
||
180 | 'CREATE TABLE test (id INTEGER NOT NULL, fk_1 INTEGER NOT NULL, fk_2 INTEGER NOT NULL)', |
||
181 | 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2)', |
||
182 | 'ALTER TABLE test ADD CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2)', |
||
183 | ], |
||
184 | $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) |
||
185 | ); |
||
186 | } |
||
187 | |||
188 | public function testGeneratesCreateTableSQLWithCheckConstraints() |
||
189 | { |
||
190 | $table = new Table('test'); |
||
191 | $table->addColumn('id', 'integer'); |
||
192 | $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); |
||
193 | $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); |
||
194 | $table->setPrimaryKey(['id']); |
||
195 | |||
196 | self::assertEquals( |
||
197 | ['CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], |
||
198 | $this->platform->getCreateTableSQL($table) |
||
199 | ); |
||
200 | } |
||
201 | |||
202 | public function testGeneratesColumnTypesDeclarationSQL() |
||
203 | { |
||
204 | $fullColumnDef = [ |
||
205 | 'length' => 10, |
||
206 | 'fixed' => true, |
||
207 | 'unsigned' => true, |
||
208 | 'autoincrement' => true, |
||
209 | ]; |
||
210 | |||
211 | self::assertEquals('VARCHAR(255)', $this->platform->getVarcharTypeDeclarationSQL([])); |
||
212 | self::assertEquals('VARCHAR(10)', $this->platform->getVarcharTypeDeclarationSQL(['length' => 10])); |
||
213 | self::assertEquals('CHAR(254)', $this->platform->getVarcharTypeDeclarationSQL(['fixed' => true])); |
||
214 | self::assertEquals('CHAR(10)', $this->platform->getVarcharTypeDeclarationSQL($fullColumnDef)); |
||
215 | |||
216 | self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([])); |
||
217 | self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); |
||
218 | self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); |
||
219 | self::assertEquals('INTEGER', $this->platform->getIntegerTypeDeclarationSQL([])); |
||
220 | self::assertEquals('INTEGER', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); |
||
221 | self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef)); |
||
222 | self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([])); |
||
223 | self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); |
||
224 | self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef)); |
||
225 | self::assertEquals('BLOB(1M)', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef)); |
||
226 | self::assertEquals('SMALLINT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef)); |
||
227 | self::assertEquals('CLOB(1M)', $this->platform->getClobTypeDeclarationSQL($fullColumnDef)); |
||
228 | self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef)); |
||
229 | self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->platform->getDateTimeTypeDeclarationSQL(['version' => true])); |
||
230 | self::assertEquals('TIMESTAMP(0)', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); |
||
231 | self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); |
||
232 | } |
||
233 | |||
234 | public function testInitializesDoctrineTypeMappings() |
||
235 | { |
||
236 | $this->platform->initializeDoctrineTypeMappings(); |
||
237 | |||
238 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('smallint')); |
||
239 | self::assertSame('smallint', $this->platform->getDoctrineTypeMapping('smallint')); |
||
240 | |||
241 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bigint')); |
||
242 | self::assertSame('bigint', $this->platform->getDoctrineTypeMapping('bigint')); |
||
243 | |||
244 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); |
||
245 | self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); |
||
246 | |||
247 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('time')); |
||
248 | self::assertSame('time', $this->platform->getDoctrineTypeMapping('time')); |
||
249 | |||
250 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('date')); |
||
251 | self::assertSame('date', $this->platform->getDoctrineTypeMapping('date')); |
||
252 | |||
253 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varchar')); |
||
254 | self::assertSame('string', $this->platform->getDoctrineTypeMapping('varchar')); |
||
255 | |||
256 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('character')); |
||
257 | self::assertSame('string', $this->platform->getDoctrineTypeMapping('character')); |
||
258 | |||
259 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('clob')); |
||
260 | self::assertSame('text', $this->platform->getDoctrineTypeMapping('clob')); |
||
261 | |||
262 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('blob')); |
||
263 | self::assertSame('blob', $this->platform->getDoctrineTypeMapping('blob')); |
||
264 | |||
265 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('decimal')); |
||
266 | self::assertSame('decimal', $this->platform->getDoctrineTypeMapping('decimal')); |
||
267 | |||
268 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double')); |
||
269 | self::assertSame('float', $this->platform->getDoctrineTypeMapping('double')); |
||
270 | |||
271 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real')); |
||
272 | self::assertSame('float', $this->platform->getDoctrineTypeMapping('real')); |
||
273 | |||
274 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp')); |
||
275 | self::assertSame('datetime', $this->platform->getDoctrineTypeMapping('timestamp')); |
||
276 | } |
||
277 | |||
278 | public function getIsCommentedDoctrineType() |
||
279 | { |
||
280 | $data = parent::getIsCommentedDoctrineType(); |
||
281 | |||
282 | $data[Type::BOOLEAN] = [Type::getType(Type::BOOLEAN), true]; |
||
283 | |||
284 | return $data; |
||
285 | } |
||
286 | |||
287 | public function testGeneratesDDLSnippets() |
||
288 | { |
||
289 | self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); |
||
290 | self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); |
||
291 | self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); |
||
292 | self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar')); |
||
293 | self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar'), true); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
294 | |||
295 | $viewSql = 'SELECT * FROM footable'; |
||
296 | self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql)); |
||
297 | self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); |
||
298 | } |
||
299 | |||
300 | public function testGeneratesCreateUnnamedPrimaryKeySQL() |
||
301 | { |
||
302 | self::assertEquals( |
||
303 | 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', |
||
304 | $this->platform->getCreatePrimaryKeySQL( |
||
305 | new Index('any_pk_name', ['a', 'b'], true, true), |
||
306 | 'foo' |
||
307 | ) |
||
308 | ); |
||
309 | } |
||
310 | |||
311 | public function testGeneratesSQLSnippets() |
||
312 | { |
||
313 | self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); |
||
314 | self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); |
||
315 | self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL()); |
||
316 | self::assertEquals("'1987/05/02' + 4 DAY", $this->platform->getDateAddDaysExpression("'1987/05/02'", 4)); |
||
317 | self::assertEquals("'1987/05/02' + 12 HOUR", $this->platform->getDateAddHourExpression("'1987/05/02'", 12)); |
||
318 | self::assertEquals("'1987/05/02' + 2 MINUTE", $this->platform->getDateAddMinutesExpression("'1987/05/02'", 2)); |
||
319 | self::assertEquals("'1987/05/02' + 102 MONTH", $this->platform->getDateAddMonthExpression("'1987/05/02'", 102)); |
||
320 | self::assertEquals("'1987/05/02' + 15 MONTH", $this->platform->getDateAddQuartersExpression("'1987/05/02'", 5)); |
||
321 | self::assertEquals("'1987/05/02' + 1 SECOND", $this->platform->getDateAddSecondsExpression("'1987/05/02'", 1)); |
||
322 | self::assertEquals("'1987/05/02' + 21 DAY", $this->platform->getDateAddWeeksExpression("'1987/05/02'", 3)); |
||
323 | self::assertEquals("'1987/05/02' + 10 YEAR", $this->platform->getDateAddYearsExpression("'1987/05/02'", 10)); |
||
324 | self::assertEquals("DAYS('1987/05/02') - DAYS('1987/04/01')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); |
||
325 | self::assertEquals("'1987/05/02' - 4 DAY", $this->platform->getDateSubDaysExpression("'1987/05/02'", 4)); |
||
326 | self::assertEquals("'1987/05/02' - 12 HOUR", $this->platform->getDateSubHourExpression("'1987/05/02'", 12)); |
||
327 | self::assertEquals("'1987/05/02' - 2 MINUTE", $this->platform->getDateSubMinutesExpression("'1987/05/02'", 2)); |
||
328 | self::assertEquals("'1987/05/02' - 102 MONTH", $this->platform->getDateSubMonthExpression("'1987/05/02'", 102)); |
||
329 | self::assertEquals("'1987/05/02' - 15 MONTH", $this->platform->getDateSubQuartersExpression("'1987/05/02'", 5)); |
||
330 | self::assertEquals("'1987/05/02' - 1 SECOND", $this->platform->getDateSubSecondsExpression("'1987/05/02'", 1)); |
||
331 | self::assertEquals("'1987/05/02' - 21 DAY", $this->platform->getDateSubWeeksExpression("'1987/05/02'", 3)); |
||
332 | self::assertEquals("'1987/05/02' - 10 YEAR", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10)); |
||
333 | self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->platform->getForUpdateSQL()); |
||
334 | self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); |
||
335 | self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); |
||
336 | self::assertEquals('LOCATE(substring_column, string_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1)); |
||
337 | self::assertEquals('SUBSTR(column, 5)', $this->platform->getSubstringExpression('column', 5)); |
||
338 | self::assertEquals('SUBSTR(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2)); |
||
339 | } |
||
340 | |||
341 | public function testModifiesLimitQuery() |
||
342 | { |
||
343 | self::assertEquals( |
||
344 | 'SELECT * FROM user', |
||
345 | $this->platform->modifyLimitQuery('SELECT * FROM user', null, null) |
||
346 | ); |
||
347 | |||
348 | self::assertEquals( |
||
349 | 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10', |
||
350 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0) |
||
351 | ); |
||
352 | |||
353 | self::assertEquals( |
||
354 | 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10', |
||
355 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10) |
||
356 | ); |
||
357 | |||
358 | self::assertEquals( |
||
359 | 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 15', |
||
360 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) |
||
361 | ); |
||
362 | self::assertEquals( |
||
363 | 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 5', |
||
364 | $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) |
||
365 | ); |
||
366 | } |
||
367 | |||
368 | public function testPrefersIdentityColumns() |
||
369 | { |
||
370 | self::assertTrue($this->platform->prefersIdentityColumns()); |
||
371 | } |
||
372 | |||
373 | public function testSupportsIdentityColumns() |
||
374 | { |
||
375 | self::assertTrue($this->platform->supportsIdentityColumns()); |
||
376 | } |
||
377 | |||
378 | public function testDoesNotSupportSavePoints() |
||
379 | { |
||
380 | self::assertFalse($this->platform->supportsSavepoints()); |
||
381 | } |
||
382 | |||
383 | public function testDoesNotSupportReleasePoints() |
||
384 | { |
||
385 | self::assertFalse($this->platform->supportsReleaseSavepoints()); |
||
386 | } |
||
387 | |||
388 | public function testDoesNotSupportCreateDropDatabase() |
||
389 | { |
||
390 | self::assertFalse($this->platform->supportsCreateDropDatabase()); |
||
391 | } |
||
392 | |||
393 | public function testReturnsSQLResultCasing() |
||
394 | { |
||
395 | self::assertSame('COL', $this->platform->getSQLResultCasing('cOl')); |
||
396 | } |
||
397 | |||
398 | protected function getBinaryDefaultLength() |
||
399 | { |
||
400 | return 1; |
||
401 | } |
||
402 | |||
403 | protected function getBinaryMaxLength() |
||
404 | { |
||
405 | return 32704; |
||
406 | } |
||
407 | |||
408 | public function testReturnsBinaryTypeDeclarationSQL() |
||
409 | { |
||
410 | self::assertSame('VARCHAR(1) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL([])); |
||
411 | self::assertSame('VARCHAR(255) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); |
||
412 | self::assertSame('VARCHAR(32704) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32704])); |
||
413 | |||
414 | self::assertSame('CHAR(1) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); |
||
415 | self::assertSame('CHAR(254) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * @group legacy |
||
420 | * @expectedDeprecation Binary field length 32705 is greater than supported by the platform (32704). Reduce the field length or use a BLOB field instead. |
||
421 | */ |
||
422 | public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() |
||
423 | { |
||
424 | self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32705])); |
||
425 | self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32705])); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @group DBAL-234 |
||
430 | */ |
||
431 | protected function getAlterTableRenameIndexSQL() |
||
432 | { |
||
433 | return ['RENAME INDEX idx_foo TO idx_bar']; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * @group DBAL-234 |
||
438 | */ |
||
439 | protected function getQuotedAlterTableRenameIndexSQL() |
||
440 | { |
||
441 | return [ |
||
442 | 'RENAME INDEX "create" TO "select"', |
||
443 | 'RENAME INDEX "foo" TO "bar"', |
||
444 | ]; |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * {@inheritdoc} |
||
449 | */ |
||
450 | protected function getQuotedAlterTableRenameColumnSQL() |
||
451 | { |
||
452 | return ['ALTER TABLE mytable ' . |
||
453 | 'RENAME COLUMN unquoted1 TO unquoted ' . |
||
454 | 'RENAME COLUMN unquoted2 TO "where" ' . |
||
455 | 'RENAME COLUMN unquoted3 TO "foo" ' . |
||
456 | 'RENAME COLUMN "create" TO reserved_keyword ' . |
||
457 | 'RENAME COLUMN "table" TO "from" ' . |
||
458 | 'RENAME COLUMN "select" TO "bar" ' . |
||
459 | 'RENAME COLUMN quoted1 TO quoted ' . |
||
460 | 'RENAME COLUMN quoted2 TO "and" ' . |
||
461 | 'RENAME COLUMN quoted3 TO "baz"', |
||
462 | ]; |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * {@inheritdoc} |
||
467 | */ |
||
468 | protected function getQuotedAlterTableChangeColumnLengthSQL() |
||
469 | { |
||
470 | $this->markTestIncomplete('Not implemented yet'); |
||
471 | } |
||
472 | |||
473 | /** |
||
474 | * @group DBAL-807 |
||
475 | */ |
||
476 | protected function getAlterTableRenameIndexInSchemaSQL() |
||
477 | { |
||
478 | return ['RENAME INDEX myschema.idx_foo TO idx_bar']; |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * @group DBAL-807 |
||
483 | */ |
||
484 | protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
||
485 | { |
||
486 | return [ |
||
487 | 'RENAME INDEX "schema"."create" TO "select"', |
||
488 | 'RENAME INDEX "schema"."foo" TO "bar"', |
||
489 | ]; |
||
490 | } |
||
491 | |||
492 | /** |
||
493 | * @group DBAL-423 |
||
494 | */ |
||
495 | public function testReturnsGuidTypeDeclarationSQL() |
||
496 | { |
||
497 | self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * {@inheritdoc} |
||
502 | */ |
||
503 | public function getAlterTableRenameColumnSQL() |
||
504 | { |
||
505 | return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; |
||
506 | } |
||
507 | |||
508 | /** |
||
509 | * {@inheritdoc} |
||
510 | */ |
||
511 | protected function getQuotesTableIdentifiersInAlterTableSQL() |
||
512 | { |
||
513 | return [ |
||
514 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', |
||
515 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', |
||
516 | 'ALTER TABLE "foo" ' . |
||
517 | 'ADD COLUMN bloo INTEGER NOT NULL WITH DEFAULT ' . |
||
518 | 'DROP COLUMN baz ' . |
||
519 | 'ALTER COLUMN bar DROP NOT NULL ' . |
||
520 | 'RENAME COLUMN id TO war', |
||
521 | 'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE "foo"\')', |
||
522 | 'RENAME TABLE "foo" TO "table"', |
||
523 | 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', |
||
524 | 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', |
||
525 | ]; |
||
526 | } |
||
527 | |||
528 | /** |
||
529 | * {@inheritdoc} |
||
530 | */ |
||
531 | protected function getCommentOnColumnSQL() |
||
532 | { |
||
533 | return [ |
||
534 | 'COMMENT ON COLUMN foo.bar IS \'comment\'', |
||
535 | 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', |
||
536 | 'COMMENT ON COLUMN "select"."from" IS \'comment\'', |
||
537 | ]; |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * @group DBAL-944 |
||
542 | * @dataProvider getGeneratesAlterColumnSQL |
||
543 | */ |
||
544 | public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $expectedSQLClause = null) |
||
545 | { |
||
546 | $tableDiff = new TableDiff('foo'); |
||
547 | $tableDiff->fromTable = new Table('foo'); |
||
548 | $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, [$changedProperty]); |
||
549 | |||
550 | $expectedSQL = []; |
||
551 | |||
552 | if ($expectedSQLClause !== null) { |
||
553 | $expectedSQL[] = 'ALTER TABLE foo ALTER COLUMN bar ' . $expectedSQLClause; |
||
554 | } |
||
555 | |||
556 | $expectedSQL[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE foo')"; |
||
557 | |||
558 | self::assertSame($expectedSQL, $this->platform->getAlterTableSQL($tableDiff)); |
||
559 | } |
||
560 | |||
561 | /** |
||
562 | * @return mixed[] |
||
563 | */ |
||
564 | public function getGeneratesAlterColumnSQL() |
||
565 | { |
||
566 | return [ |
||
567 | [ |
||
568 | 'columnDefinition', |
||
569 | new Column('bar', Type::getType('decimal'), ['columnDefinition' => 'MONEY NOT NULL']), |
||
570 | 'MONEY NOT NULL', |
||
571 | ], |
||
572 | [ |
||
573 | 'type', |
||
574 | new Column('bar', Type::getType('integer')), |
||
575 | 'SET DATA TYPE INTEGER', |
||
576 | ], |
||
577 | [ |
||
578 | 'length', |
||
579 | new Column('bar', Type::getType('string'), ['length' => 100]), |
||
580 | 'SET DATA TYPE VARCHAR(100)', |
||
581 | ], |
||
582 | [ |
||
583 | 'precision', |
||
584 | new Column('bar', Type::getType('decimal'), ['precision' => 10, 'scale' => 2]), |
||
585 | 'SET DATA TYPE NUMERIC(10, 2)', |
||
586 | ], |
||
587 | [ |
||
588 | 'scale', |
||
589 | new Column('bar', Type::getType('decimal'), ['precision' => 5, 'scale' => 4]), |
||
590 | 'SET DATA TYPE NUMERIC(5, 4)', |
||
591 | ], |
||
592 | [ |
||
593 | 'fixed', |
||
594 | new Column('bar', Type::getType('string'), ['length' => 20, 'fixed' => true]), |
||
595 | 'SET DATA TYPE CHAR(20)', |
||
596 | ], |
||
597 | [ |
||
598 | 'notnull', |
||
599 | new Column('bar', Type::getType('string'), ['notnull' => true]), |
||
600 | 'SET NOT NULL', |
||
601 | ], |
||
602 | [ |
||
603 | 'notnull', |
||
604 | new Column('bar', Type::getType('string'), ['notnull' => false]), |
||
605 | 'DROP NOT NULL', |
||
606 | ], |
||
607 | [ |
||
608 | 'default', |
||
609 | new Column('bar', Type::getType('string'), ['default' => 'foo']), |
||
610 | "SET DEFAULT 'foo'", |
||
611 | ], |
||
612 | [ |
||
613 | 'default', |
||
614 | new Column('bar', Type::getType('integer'), ['autoincrement' => true, 'default' => 666]), |
||
615 | null, |
||
616 | ], |
||
617 | [ |
||
618 | 'default', |
||
619 | new Column('bar', Type::getType('string')), |
||
620 | 'DROP DEFAULT', |
||
621 | ], |
||
622 | ]; |
||
623 | } |
||
624 | |||
625 | /** |
||
626 | * {@inheritdoc} |
||
627 | */ |
||
628 | protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
||
629 | { |
||
630 | return 'CONSTRAINT "select" UNIQUE (foo)'; |
||
631 | } |
||
632 | |||
633 | /** |
||
634 | * {@inheritdoc} |
||
635 | */ |
||
636 | protected function getQuotesReservedKeywordInIndexDeclarationSQL() |
||
637 | { |
||
638 | return ''; // not supported by this platform |
||
639 | } |
||
640 | |||
641 | /** |
||
642 | * {@inheritdoc} |
||
643 | */ |
||
644 | protected function getQuotesReservedKeywordInTruncateTableSQL() |
||
645 | { |
||
646 | return 'TRUNCATE "select" IMMEDIATE'; |
||
647 | } |
||
648 | |||
649 | /** |
||
650 | * {@inheritdoc} |
||
651 | */ |
||
652 | protected function supportsInlineIndexDeclaration() |
||
653 | { |
||
654 | return false; |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * {@inheritdoc} |
||
659 | */ |
||
660 | protected function supportsCommentOnStatement() |
||
661 | { |
||
662 | return true; |
||
663 | } |
||
664 | |||
665 | /** |
||
666 | * {@inheritdoc} |
||
667 | */ |
||
668 | protected function getAlterStringToFixedStringSQL() |
||
669 | { |
||
670 | return [ |
||
671 | 'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)', |
||
672 | 'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE mytable\')', |
||
673 | ]; |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * {@inheritdoc} |
||
678 | */ |
||
679 | protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
||
680 | { |
||
681 | return ['RENAME INDEX idx_foo TO idx_foo_renamed']; |
||
682 | } |
||
683 | |||
684 | /** |
||
685 | * @group DBAL-2436 |
||
686 | */ |
||
687 | public function testQuotesTableNameInListTableColumnsSQL() |
||
688 | { |
||
689 | self::assertStringContainsStringIgnoringCase( |
||
690 | "'Foo''Bar\\'", |
||
691 | $this->platform->getListTableColumnsSQL("Foo'Bar\\") |
||
692 | ); |
||
693 | } |
||
694 | |||
695 | /** |
||
696 | * @group DBAL-2436 |
||
697 | */ |
||
698 | public function testQuotesTableNameInListTableIndexesSQL() |
||
699 | { |
||
700 | self::assertStringContainsStringIgnoringCase( |
||
701 | "'Foo''Bar\\'", |
||
702 | $this->platform->getListTableIndexesSQL("Foo'Bar\\") |
||
703 | ); |
||
704 | } |
||
705 | |||
706 | /** |
||
707 | * @group DBAL-2436 |
||
708 | */ |
||
709 | public function testQuotesTableNameInListTableForeignKeysSQL() |
||
710 | { |
||
711 | self::assertStringContainsStringIgnoringCase( |
||
712 | "'Foo''Bar\\'", |
||
713 | $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") |
||
714 | ); |
||
715 | } |
||
716 | } |
||
717 |