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
e85e7130
Commit
e85e7130
authored
Aug 27, 2013
by
dazz
Committed by
Benjamin Eberlei
Nov 13, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-407] Introduce failing test for duplicate key exception code
parent
d79ce18e
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
141 additions
and
8 deletions
+141
-8
.gitignore
.gitignore
+1
-0
Connection.php
lib/Doctrine/DBAL/Connection.php
+5
-5
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+4
-1
Driver.php
lib/Doctrine/DBAL/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php
+8
-0
DB2Driver.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/OCI8/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
+8
-0
Driver.php
lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
+8
-0
Statement.php
lib/Doctrine/DBAL/Statement.php
+6
-1
DBALExceptionTest.php
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
+2
-1
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+27
-0
No files found.
.gitignore
View file @
e85e7130
...
...
@@ -5,3 +5,4 @@ dist/
download/
lib/Doctrine/Common/
vendor/
*.phpunit.xml
lib/Doctrine/DBAL/Connection.php
View file @
e85e7130
...
...
@@ -645,7 +645,7 @@ class Connection implements DriverConnection
try
{
$stmt
=
new
Statement
(
$statement
,
$this
);
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$statement
);
throw
DBALException
::
driverExceptionDuringQuery
(
$
this
->
_driver
,
$
ex
,
$statement
);
}
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
...
...
@@ -698,7 +698,7 @@ class Connection implements DriverConnection
$stmt
=
$this
->
_conn
->
query
(
$query
);
}
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
throw
DBALException
::
driverExceptionDuringQuery
(
$
this
->
_driver
,
$
ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
}
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
...
...
@@ -807,7 +807,7 @@ class Connection implements DriverConnection
break
;
}
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$args
[
0
]);
throw
DBALException
::
driverExceptionDuringQuery
(
$
this
->
_driver
,
$
ex
,
$args
[
0
]);
}
$statement
->
setFetchMode
(
$this
->
defaultFetchMode
);
...
...
@@ -860,7 +860,7 @@ class Connection implements DriverConnection
$result
=
$this
->
_conn
->
exec
(
$query
);
}
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
throw
DBALException
::
driverExceptionDuringQuery
(
$
this
->
_driver
,
$
ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
}
if
(
$logger
)
{
...
...
@@ -891,7 +891,7 @@ class Connection implements DriverConnection
try
{
$result
=
$this
->
_conn
->
exec
(
$statement
);
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$statement
);
throw
DBALException
::
driverExceptionDuringQuery
(
$
this
->
_driver
,
$
ex
,
$statement
);
}
if
(
$logger
)
{
...
...
lib/Doctrine/DBAL/DBALException.php
View file @
e85e7130
...
...
@@ -21,6 +21,8 @@ namespace Doctrine\DBAL;
class
DBALException
extends
\Exception
{
const
ERROR_DUPLICATE_KEY
=
1
;
/**
* @param string $method
*
...
...
@@ -74,13 +76,14 @@ class DBALException extends \Exception
}
/**
* @param \Doctrine\DBAL\Driver $driver
* @param \Exception $driverEx
* @param string $sql
* @param array $params
*
* @return \Doctrine\DBAL\DBALException
*/
public
static
function
driverExceptionDuringQuery
(
\Exception
$driverEx
,
$sql
,
array
$params
=
array
())
public
static
function
driverExceptionDuringQuery
(
Driver
$driver
,
\Exception
$driverEx
,
$sql
,
array
$params
=
array
())
{
$msg
=
"An exception occurred while executing '"
.
$sql
.
"'"
;
if
(
$params
)
{
...
...
lib/Doctrine/DBAL/Driver.php
View file @
e85e7130
...
...
@@ -72,4 +72,12 @@ interface Driver
* @return string The name of the database.
*/
public
function
getDatabase
(
Connection
$conn
);
/**
* @param \Exception $exception
*
* @return int
*/
public
function
convertExceptionCode
(
\Exception
$exception
);
}
lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php
View file @
e85e7130
...
...
@@ -99,4 +99,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
View file @
e85e7130
...
...
@@ -91,4 +91,12 @@ class DB2Driver implements Driver
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
View file @
e85e7130
...
...
@@ -67,4 +67,12 @@ class Driver implements DriverInterface
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/OCI8/Driver.php
View file @
e85e7130
...
...
@@ -113,4 +113,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
$params
[
'user'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php
View file @
e85e7130
...
...
@@ -105,4 +105,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
e85e7130
...
...
@@ -108,4 +108,12 @@ class Driver implements \Doctrine\DBAL\Driver
}
return
$conn
->
query
(
'SELECT DATABASE()'
)
->
fetchColumn
();
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
View file @
e85e7130
...
...
@@ -113,4 +113,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
$params
[
'user'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
View file @
e85e7130
...
...
@@ -99,5 +99,13 @@ class Driver implements \Doctrine\DBAL\Driver
?
$params
[
'dbname'
]
:
$conn
->
query
(
'SELECT CURRENT_DATABASE()'
)
->
fetchColumn
();
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
e85e7130
...
...
@@ -112,4 +112,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
isset
(
$params
[
'path'
])
?
$params
[
'path'
]
:
null
;
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
View file @
e85e7130
...
...
@@ -102,4 +102,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
View file @
e85e7130
...
...
@@ -83,4 +83,12 @@ class Driver implements \Doctrine\DBAL\Driver
$params
=
$conn
->
getParams
();
return
$params
[
'dbname'
];
}
/**
* {@inheritdoc}
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
}
lib/Doctrine/DBAL/Statement.php
View file @
e85e7130
...
...
@@ -164,7 +164,12 @@ class Statement implements \IteratorAggregate, DriverStatement
try
{
$stmt
=
$this
->
stmt
->
execute
(
$params
);
}
catch
(
\Exception
$ex
)
{
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$this
->
sql
,
$this
->
conn
->
resolveParams
(
$this
->
params
,
$this
->
types
));
throw
DBALException
::
driverExceptionDuringQuery
(
$this
->
conn
->
getDriver
(),
$ex
,
$this
->
sql
,
$this
->
conn
->
resolveParams
(
$this
->
params
,
$this
->
types
)
);
}
if
(
$logger
)
{
...
...
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
View file @
e85e7130
...
...
@@ -8,7 +8,8 @@ class DBALExceptionTest extends \Doctrine\Tests\DbalTestCase
{
public
function
testDriverExceptionDuringQueryAcceptsBinaryData
()
{
$e
=
DBALException
::
driverExceptionDuringQuery
(
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$driver
=
$this
->
getMock
(
'\Doctrine\DBAL\Driver'
);
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$this
->
assertContains
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
}
}
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
0 → 100644
View file @
e85e7130
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\DBALException
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
ExceptionTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
testDuplicateKeyException
()
{
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table
=
new
\Doctrine\DBAL\Schema\Table
(
"duplicatekey_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
$table
->
setPrimaryKey
(
array
(
'id'
));
foreach
(
$this
->
_conn
->
getDatabasePlatform
()
->
getCreateTableSQL
(
$table
)
AS
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
}
$this
->
_conn
->
insert
(
"duplicatekey_table"
,
array
(
'id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_DUPLICATE_KEY
);
$this
->
_conn
->
insert
(
"duplicatekey_table"
,
array
(
'id'
=>
1
));
}
}
\ No newline at end of file
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