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
4d29ad40
Commit
4d29ad40
authored
Oct 26, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more foreign key constraint violation error codes
parent
c8640073
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
15 deletions
+95
-15
AbstractMySQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
+1
-0
AbstractOracleDriver.php
lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php
+3
-1
AbstractPostgreSQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
+9
-0
AbstractSQLAnywhereDriver.php
lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
+1
-0
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+81
-14
No files found.
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
View file @
4d29ad40
...
...
@@ -56,6 +56,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
case
'1217'
:
case
'1451'
:
case
'1452'
:
case
'1701'
:
return
new
Exception\ForeignKeyConstraintViolationException
(
$message
,
$exception
);
case
'1062'
:
...
...
lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php
View file @
4d29ad40
...
...
@@ -67,6 +67,8 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
case
'1400'
:
return
new
Exception\NotNullConstraintViolationException
(
$message
,
$exception
);
case
'2266'
:
case
'2291'
:
case
'2292'
:
return
new
Exception\ForeignKeyConstraintViolationException
(
$message
,
$exception
);
}
...
...
@@ -129,7 +131,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
if
(
isset
(
$params
[
'service'
])
&&
$params
[
'service'
]
==
true
)
{
$service
=
'SERVICE_NAME='
.
$serviceName
;
}
if
(
isset
(
$params
[
'instancename'
])
&&
!
empty
(
$params
[
'instancename'
]))
{
$instance
=
'(INSTANCE_NAME = '
.
$params
[
'instancename'
]
.
')'
;
}
...
...
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
View file @
4d29ad40
...
...
@@ -45,6 +45,14 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
public
function
convertException
(
$message
,
DriverException
$exception
)
{
switch
(
$exception
->
getSQLState
())
{
case
'0A000'
:
// Foreign key constraint violations during a TRUNCATE operation
// are considered "feature not supported" in PostgreSQL.
if
(
strpos
(
$exception
->
getMessage
(),
'truncate'
)
!==
false
)
{
return
new
Exception\ForeignKeyConstraintViolationException
(
$message
,
$exception
);
}
break
;
case
'23502'
:
return
new
Exception\NotNullConstraintViolationException
(
$message
,
$exception
);
...
...
@@ -76,6 +84,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
if
(
strpos
(
$exception
->
getMessage
(),
'SQLSTATE[08006]'
)
!==
false
)
{
return
new
Exception\ConnectionException
(
$message
,
$exception
);
}
break
;
}
...
...
lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
View file @
4d29ad40
...
...
@@ -55,6 +55,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
case
'-193'
:
case
'-196'
:
return
new
Exception\UniqueConstraintViolationException
(
$message
,
$exception
);
case
'-194'
:
case
'-198'
:
return
new
Exception\ForeignKeyConstraintViolationException
(
$message
,
$exception
);
case
'-144'
:
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
4d29ad40
...
...
@@ -2,10 +2,11 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Schema\Table
;
class
ExceptionTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
p
ublic
function
setUp
()
p
rotected
function
setUp
()
{
parent
::
setUp
();
...
...
@@ -54,33 +55,74 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
public
function
testForeignKeyContraintViolationException
()
public
function
testForeignKeyContraintViolationException
OnInsert
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
"Only fails on platforms with foreign key constraints."
);
}
$
schema
=
new
\Doctrine\DBAL\Schema\Schema
();
$
this
->
setUpForeignKeyConstraintViolationExceptionTest
();
$table
=
$schema
->
createTable
(
"constraint_error_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
_conn
->
insert
(
"constraint_error_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"owning_table"
,
array
(
'id'
=>
1
,
'constraint_id'
=>
1
));
$owningTable
=
$schema
->
createTable
(
"owning_table"
);
$owningTable
->
addColumn
(
'id'
,
'integer'
,
array
());
$owningTable
->
addColumn
(
'constraint_id'
,
'integer'
,
array
());
$owningTable
->
setPrimaryKey
(
array
(
'id'
));
$owningTable
->
addForeignKeyConstraint
(
$table
,
array
(
'constraint_id'
),
array
(
'id'
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'
);
$this
->
_conn
->
insert
(
'owning_table'
,
array
(
'id'
=>
2
,
'constraint_id'
=>
2
));
foreach
(
$schema
->
toSql
(
$this
->
_conn
->
getDatabasePlatform
())
as
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyContraintViolationExceptionOnUpdate
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
"Only fails on platforms with foreign key constraints."
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
$this
->
_conn
->
insert
(
"constraint_error_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"owning_table"
,
array
(
'id'
=>
1
,
'constraint_id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'
);
$this
->
_conn
->
update
(
'constraint_error_table'
,
array
(
'id'
=>
2
),
array
(
'id'
=>
1
));
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyContraintViolationExceptionOnDelete
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
"Only fails on platforms with foreign key constraints."
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
$this
->
_conn
->
insert
(
"constraint_error_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"owning_table"
,
array
(
'id'
=>
1
,
'constraint_id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'
);
$this
->
_conn
->
delete
(
'constraint_error_table'
,
array
(
'id'
=>
1
));
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyContraintViolationExceptionOnTruncate
()
{
$platform
=
$this
->
_conn
->
getDatabasePlatform
();
if
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
"Only fails on platforms with foreign key constraints."
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
$this
->
_conn
->
insert
(
"constraint_error_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"owning_table"
,
array
(
'id'
=>
1
,
'constraint_id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'
);
$this
->
_conn
->
executeUpdate
(
$platform
->
getTruncateTableSQL
(
'constraint_error_table'
));
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testNotNullConstraintViolationException
()
...
...
@@ -249,5 +291,30 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
array
(
array
(
'host'
=>
'localnope'
)),
);
}
}
private
function
setUpForeignKeyConstraintViolationExceptionTest
()
{
$schemaManager
=
$this
->
_conn
->
getSchemaManager
();
$table
=
new
Table
(
"constraint_error_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
$table
->
setPrimaryKey
(
array
(
'id'
));
$owningTable
=
new
Table
(
"owning_table"
);
$owningTable
->
addColumn
(
'id'
,
'integer'
,
array
());
$owningTable
->
addColumn
(
'constraint_id'
,
'integer'
,
array
());
$owningTable
->
setPrimaryKey
(
array
(
'id'
));
$owningTable
->
addForeignKeyConstraint
(
$table
,
array
(
'constraint_id'
),
array
(
'id'
));
$schemaManager
->
createTable
(
$table
);
$schemaManager
->
createTable
(
$owningTable
);
}
private
function
tearDownForeignKeyConstraintViolationExceptionTest
()
{
$schemaManager
=
$this
->
_conn
->
getSchemaManager
();
$schemaManager
->
dropTable
(
'owning_table'
);
$schemaManager
->
dropTable
(
'constraint_error_table'
);
}
}
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