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
0f05b757
Commit
0f05b757
authored
May 01, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #303 from BenMorel/jsonfix
Fixed a PHP warning in DBALException::driverExceptionDuringQuery()
parents
4b1ad761
26b47470
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+23
-1
DBALExceptionTest.php
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
+14
-0
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
0f05b757
...
...
@@ -40,13 +40,35 @@ class DBALException extends \Exception
{
$msg
=
"An exception occurred while executing '"
.
$sql
.
"'"
;
if
(
$params
)
{
$msg
.=
" with params "
.
json_encode
(
$params
);
$msg
.=
" with params "
.
self
::
formatParameters
(
$params
);
}
$msg
.=
":
\n\n
"
.
$driverEx
->
getMessage
();
return
new
self
(
$msg
,
0
,
$driverEx
);
}
/**
* Returns a human-readable representation of an array of parameters.
* This properly handles binary data by returning a hex representation.
*
* @param array $params
*
* @return string
*/
private
static
function
formatParameters
(
array
$params
)
{
return
'['
.
implode
(
', '
,
array_map
(
function
(
$param
)
{
$json
=
@
json_encode
(
$param
);
if
(
!
is_string
(
$json
)
||
$json
==
'null'
&&
is_string
(
$param
))
{
// JSON encoding failed, this is not a UTF-8 string.
return
'"\x'
.
implode
(
'\x'
,
str_split
(
bin2hex
(
$param
),
2
))
.
'"'
;
}
return
$json
;
},
$params
))
.
']'
;
}
public
static
function
invalidWrapperClass
(
$wrapperClass
)
{
return
new
self
(
"The given 'wrapperClass' "
.
$wrapperClass
.
" has to be a "
.
...
...
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
0 → 100644
View file @
0f05b757
<?php
namespace
Doctrine\Tests\DBAL
;
use
Doctrine\DBAL\DBALException
;
class
DBALExceptionTest
extends
\Doctrine\Tests\DbalTestCase
{
public
function
testDriverExceptionDuringQueryAcceptsBinaryData
()
{
$e
=
DBALException
::
driverExceptionDuringQuery
(
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$this
->
assertContains
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
}
}
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