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
7710d546
Commit
7710d546
authored
Oct 29, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix foreign key referential action SQL on SQL Server and SQL Anywhere
parent
57a2b0c3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
10 deletions
+119
-10
SQLAnywherePlatform.php
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
+5
-10
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+13
-0
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+25
-0
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+27
-0
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+49
-0
No files found.
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
View file @
7710d546
...
...
@@ -645,17 +645,12 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public
function
getForeignKeyReferentialActionSQL
(
$action
)
{
$action
=
strtoupper
(
$action
);
switch
(
$action
)
{
case
'CASCADE'
:
case
'SET NULL'
:
case
'SET DEFAULT'
:
case
'RESTRICT'
:
return
$action
;
default
:
throw
new
\InvalidArgumentException
(
'Invalid foreign key action: '
.
$action
);
// NO ACTION is not supported, therefore falling back to RESTRICT.
if
(
strtoupper
(
$action
)
===
'NO ACTION'
)
{
return
'RESTRICT'
;
}
return
parent
::
getForeignKeyReferentialActionSQL
(
$action
);
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
7710d546
...
...
@@ -1393,6 +1393,19 @@ class SQLServerPlatform extends AbstractPlatform
return
'ROLLBACK TRANSACTION '
.
$savepoint
;
}
/**
* {@inheritdoc}
*/
public
function
getForeignKeyReferentialActionSQL
(
$action
)
{
// RESTRICT is not supported, therefore falling back to NO ACTION.
if
(
strtoupper
(
$action
)
===
'RESTRICT'
)
{
return
'NO ACTION'
;
}
return
parent
::
getForeignKeyReferentialActionSQL
(
$action
);
}
/**
* {@inheritDoc}
*/
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
7710d546
...
...
@@ -58,6 +58,31 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
str_repeat
(
$c
,
4
),
$this
->
_platform
->
quoteSingleIdentifier
(
$c
));
}
/**
* @group DBAL-1029
*
* @dataProvider getReturnsForeignKeyReferentialActionSQL
*/
public
function
testReturnsForeignKeyReferentialActionSQL
(
$action
,
$expectedSQL
)
{
$this
->
assertSame
(
$expectedSQL
,
$this
->
_platform
->
getForeignKeyReferentialActionSQL
(
$action
));
}
/**
* @return array
*/
public
function
getReturnsForeignKeyReferentialActionSQL
()
{
return
array
(
array
(
'CASCADE'
,
'CASCADE'
),
array
(
'SET NULL'
,
'SET NULL'
),
array
(
'NO ACTION'
,
'NO ACTION'
),
array
(
'RESTRICT'
,
'RESTRICT'
),
array
(
'SET DEFAULT'
,
'SET DEFAULT'
),
array
(
'CaScAdE'
,
'CASCADE'
),
);
}
public
function
testGetInvalidtForeignKeyReferentialActionSQL
()
{
$this
->
setExpectedException
(
'InvalidArgumentException'
);
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
7710d546
...
...
@@ -1159,4 +1159,31 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
"COMMENT ON COLUMN foo.bar IS 'comment'"
,
"COMMENT ON COLUMN [Foo].[BAR] IS 'comment'"
,
"COMMENT ON COLUMN [select].[from] IS 'comment'"
,
);
}
/**
* {@inheritdoc}
*/
public
function
getReturnsForeignKeyReferentialActionSQL
()
{
return
array
(
array
(
'CASCADE'
,
'CASCADE'
),
array
(
'SET NULL'
,
'SET NULL'
),
array
(
'NO ACTION'
,
'NO ACTION'
),
array
(
'RESTRICT'
,
'NO ACTION'
),
array
(
'SET DEFAULT'
,
'SET DEFAULT'
),
array
(
'CaScAdE'
,
'CASCADE'
),
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
7710d546
...
...
@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Platforms\SQLAnywherePlatform
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
...
...
@@ -889,4 +890,52 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
getCommentOnColumnSQL
()
{
return
array
(
'COMMENT ON COLUMN foo.bar IS \'comment\''
,
'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\''
,
'COMMENT ON COLUMN "select"."from" IS \'comment\''
,
);
}
/**
* @group DBAL-1004
*/
public
function
testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers
()
{
$table1
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
))));
$table2
=
new
Table
(
'"foo"'
,
array
(
new
Column
(
'"bar"'
,
Type
::
getType
(
'integer'
),
array
(
'comment'
=>
'baz'
))));
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$table1
,
$table2
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\TableDiff'
,
$tableDiff
);
$this
->
assertSame
(
array
(
'COMMENT ON COLUMN "foo"."bar" IS \'baz\''
,
),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
)
);
}
/**
* {@inheritdoc}
*/
public
function
getReturnsForeignKeyReferentialActionSQL
()
{
return
array
(
array
(
'CASCADE'
,
'CASCADE'
),
array
(
'SET NULL'
,
'SET NULL'
),
array
(
'NO ACTION'
,
'RESTRICT'
),
array
(
'RESTRICT'
,
'RESTRICT'
),
array
(
'SET DEFAULT'
,
'SET DEFAULT'
),
array
(
'CaScAdE'
,
'CASCADE'
),
);
}
}
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