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
5df3a642
Commit
5df3a642
authored
Nov 05, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #704 from deeky666/DBAL-1024
[DBAL-1024] Add more foreign key constraint violation error codes
parents
0b3e0043
ab59447d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
16 deletions
+99
-16
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
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+4
-1
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+81
-14
No files found.
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
View file @
5df3a642
...
...
@@ -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 @
5df3a642
...
...
@@ -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 @
5df3a642
...
...
@@ -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 @
5df3a642
...
...
@@ -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'
:
...
...
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
5df3a642
...
...
@@ -151,7 +151,10 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/
public
function
exec
(
$statement
)
{
$this
->
_conn
->
query
(
$statement
);
if
(
false
===
$this
->
_conn
->
query
(
$statement
))
{
throw
new
MysqliException
(
$this
->
_conn
->
error
,
$this
->
_conn
->
sqlstate
,
$this
->
_conn
->
errno
);
}
return
$this
->
_conn
->
affected_rows
;
}
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
5df3a642
...
...
@@ -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