Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
558cbf17
Commit
558cbf17
authored
Dec 12, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #741 from deeky666/DBAL-1051
[DBAL-1051] Quote index name in inline index declaration SQL
parents
80f08a64
356b5291
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
192 additions
and
11 deletions
+192
-11
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+4
-2
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+3
-1
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+2
-1
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+16
-0
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+55
-2
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+16
-0
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+16
-0
DB2PlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
+24
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+16
-0
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+24
-5
SqlitePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
+16
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
558cbf17
...
...
@@ -2308,12 +2308,13 @@ abstract class AbstractPlatform
public
function
getUniqueConstraintDeclarationSQL
(
$name
,
Index
$index
)
{
$columns
=
$index
->
getQuotedColumns
(
$this
);
$name
=
new
Identifier
(
$name
);
if
(
count
(
$columns
)
===
0
)
{
throw
new
\InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
return
'CONSTRAINT '
.
$name
.
' UNIQUE ('
return
'CONSTRAINT '
.
$name
->
getQuotedName
(
$this
)
.
' UNIQUE ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
.
$this
->
getPartialIndexSQL
(
$index
);
}
...
...
@@ -2332,12 +2333,13 @@ abstract class AbstractPlatform
public
function
getIndexDeclarationSQL
(
$name
,
Index
$index
)
{
$columns
=
$index
->
getQuotedColumns
(
$this
);
$name
=
new
Identifier
(
$name
);
if
(
count
(
$columns
)
===
0
)
{
throw
new
\InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
return
$this
->
getCreateIndexSQLFlags
(
$index
)
.
'INDEX '
.
$name
.
' ('
return
$this
->
getCreateIndexSQLFlags
(
$index
)
.
'INDEX '
.
$name
->
getQuotedName
(
$this
)
.
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
.
$this
->
getPartialIndexSQL
(
$index
);
}
...
...
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
558cbf17
...
...
@@ -19,6 +19,7 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Identifier
;
...
...
@@ -438,7 +439,8 @@ class DB2Platform extends AbstractPlatform
*/
public
function
getIndexDeclarationSQL
(
$name
,
Index
$index
)
{
return
$this
->
getUniqueConstraintDeclarationSQL
(
$name
,
$index
);
// Index declaration in statements like CREATE TABLE is not supported.
throw
DBALException
::
notSupported
(
__METHOD__
);
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
558cbf17
...
...
@@ -1358,7 +1358,8 @@ class SQLAnywherePlatform extends AbstractPlatform
$flags
=
''
;
if
(
!
empty
(
$name
))
{
$sql
.=
'CONSTRAINT '
.
$name
.
' '
;
$name
=
new
Identifier
(
$name
);
$sql
.=
'CONSTRAINT '
.
$name
->
getQuotedName
(
$this
)
.
' '
;
}
if
(
$constraint
->
hasFlag
(
'clustered'
))
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
558cbf17
...
...
@@ -641,4 +641,20 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"COMMENT ON COLUMN `select`.`from` IS 'comment'"
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT `select` UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
'INDEX `select` (foo)'
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
558cbf17
...
...
@@ -167,12 +167,17 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$where
=
'test IS NULL AND test2 IS NOT NULL'
;
$indexDef
=
new
\Doctrine\DBAL\Schema\Index
(
'name'
,
array
(
'test'
,
'test2'
),
false
,
false
,
array
(),
array
(
'where'
=>
$where
));
$uniqueIndex
=
new
\Doctrine\DBAL\Schema\Index
(
'name'
,
array
(
'test'
,
'test2'
),
true
,
false
,
array
(),
array
(
'where'
=>
$where
));
$expected
=
' WHERE '
.
$where
;
$actuals
=
array
();
if
(
$this
->
supportsInlineIndexDeclaration
())
{
$actuals
[]
=
$this
->
_platform
->
getIndexDeclarationSQL
(
'name'
,
$indexDef
);
$actuals
[]
=
$this
->
_platform
->
getUniqueConstraintDeclarationSQL
(
'name'
,
$indexDef
);
}
$actuals
[]
=
$this
->
_platform
->
getUniqueConstraintDeclarationSQL
(
'name'
,
$uniqueIndex
);
$actuals
[]
=
$this
->
_platform
->
getCreateIndexSQL
(
$indexDef
,
'table'
);
foreach
(
$actuals
as
$actual
)
{
...
...
@@ -587,6 +592,54 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
$this
->
getQuotedColumnInForeignKeySQL
(),
$sql
);
}
/**
* @group DBAL-1051
*/
public
function
testQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
$index
=
new
Index
(
'select'
,
array
(
'foo'
),
true
);
$this
->
assertSame
(
$this
->
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
(),
$this
->
_platform
->
getUniqueConstraintDeclarationSQL
(
'select'
,
$index
)
);
}
/**
* @return string
*/
abstract
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
();
/**
* @group DBAL-1051
*/
public
function
testQuotesReservedKeywordInIndexDeclarationSQL
()
{
$index
=
new
Index
(
'select'
,
array
(
'foo'
));
if
(
!
$this
->
supportsInlineIndexDeclaration
())
{
$this
->
setExpectedException
(
'Doctrine\DBAL\DBALException'
);
}
$this
->
assertSame
(
$this
->
getQuotesReservedKeywordInIndexDeclarationSQL
(),
$this
->
_platform
->
getIndexDeclarationSQL
(
'select'
,
$index
)
);
}
/**
* @return string
*/
abstract
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
();
/**
* @return boolean
*/
protected
function
supportsInlineIndexDeclaration
()
{
return
true
;
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
558cbf17
...
...
@@ -739,4 +739,20 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
)
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT "select" UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
'INDEX "select" (foo)'
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
558cbf17
...
...
@@ -1186,4 +1186,20 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
array
(
'CaScAdE'
,
'CASCADE'
),
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT [select] UNIQUE (foo) WHERE foo IS NOT NULL'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
'INDEX [select] (foo)'
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
View file @
558cbf17
...
...
@@ -615,4 +615,28 @@ class DB2PlatformTest extends AbstractPlatformTestCase
),
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT "select" UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
''
;
// not supported by this platform
}
/**
* {@inheritdoc}
*/
protected
function
supportsInlineIndexDeclaration
()
{
return
false
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
558cbf17
...
...
@@ -642,4 +642,20 @@ EOD;
$this
->
assertEquals
(
$createTriggerStatement
,
$sql
[
3
]);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT "select" UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
'INDEX "select" (foo)'
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
558cbf17
...
...
@@ -817,11 +817,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
);
}
public
function
testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes
()
{
$this
->
markTestSkipped
(
'Index declaration in statements like CREATE TABLE is not supported.'
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -932,4 +927,28 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
array
(
'CaScAdE'
,
'CASCADE'
),
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT "select" UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
''
;
// not supported by this platform
}
/**
* {@inheritdoc}
*/
protected
function
supportsInlineIndexDeclaration
()
{
return
false
;
}
}
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
View file @
558cbf17
...
...
@@ -608,4 +608,20 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
{
return
'CONSTRAINT "select" UNIQUE (foo)'
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuotesReservedKeywordInIndexDeclarationSQL
()
{
return
'INDEX "select" (foo)'
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment