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
89592347
Commit
89592347
authored
Nov 13, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup Sqlite support, testcase and fix a bug.
parent
92073ad3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
78 deletions
+87
-78
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+13
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+50
-47
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+24
-31
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
89592347
...
@@ -105,6 +105,19 @@ class DBALException extends \Exception
...
@@ -105,6 +105,19 @@ class DBALException extends \Exception
return
new
self
(
$msg
,
$driver
->
convertExceptionCode
(
$driverEx
),
$driverEx
);
return
new
self
(
$msg
,
$driver
->
convertExceptionCode
(
$driverEx
),
$driverEx
);
}
}
/**
* @param \Doctrine\DBAL\Driver $driver
* @param \Exception $driverEx
*
* @return \Doctrine\DBAL\DBALException
*/
public
static
function
driverException
(
Driver
$driver
,
\Exception
$driverEx
)
{
$msg
=
"An exception occured in driver: "
.
$driverEx
->
getMessage
();
return
new
self
(
$msg
,
$driver
->
convertExceptionCode
(
$driverEx
),
$driverEx
);
}
/**
/**
* Returns a human-readable representation of an array of parameters.
* Returns a human-readable representation of an array of parameters.
* This properly handles binary data by returning a hex representation.
* This properly handles binary data by returning a hex representation.
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
89592347
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
*/
*/
namespace
Doctrine\DBAL\Driver\PDOSqlite
;
namespace
Doctrine\DBAL\Driver\PDOSqlite
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\DBALException
;
use
PDOException
;
/**
/**
* The PDO Sqlite driver.
* The PDO Sqlite driver.
...
@@ -47,12 +49,16 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -47,12 +49,16 @@ class Driver implements \Doctrine\DBAL\Driver
unset
(
$driverOptions
[
'userDefinedFunctions'
]);
unset
(
$driverOptions
[
'userDefinedFunctions'
]);
}
}
try
{
$pdo
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$pdo
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$this
->
_constructPdoDsn
(
$params
),
$username
,
$username
,
$password
,
$password
,
$driverOptions
$driverOptions
);
);
}
catch
(
PDOException
$ex
)
{
throw
DBALException
::
driverException
(
$this
,
$ex
);
}
foreach
(
$this
->
_userDefinedFunctions
as
$fn
=>
$data
)
{
foreach
(
$this
->
_userDefinedFunctions
as
$fn
=>
$data
)
{
$pdo
->
sqliteCreateFunction
(
$fn
,
$data
[
'callback'
],
$data
[
'numArgs'
]);
$pdo
->
sqliteCreateFunction
(
$fn
,
$data
[
'callback'
],
$data
[
'numArgs'
]);
...
@@ -119,8 +125,6 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -119,8 +125,6 @@ class Driver implements \Doctrine\DBAL\Driver
*/
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
public
function
convertExceptionCode
(
\Exception
$exception
)
{
{
switch
(
$exception
->
getCode
())
{
case
23000
:
if
(
strpos
(
$exception
->
getMessage
(),
'must be unique'
)
!==
false
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'must be unique'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
}
...
@@ -132,7 +136,7 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -132,7 +136,7 @@ class Driver implements \Doctrine\DBAL\Driver
if
(
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
)
{
return
DBALException
::
ERROR_NOT_UNIQUE
;
return
DBALException
::
ERROR_NOT_UNIQUE
;
}
}
case
'HY000'
:
if
(
strpos
(
$exception
->
getMessage
(),
'no such table:'
)
!==
false
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'no such table:'
)
!==
false
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
}
...
@@ -153,13 +157,12 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -153,13 +157,12 @@ class Driver implements \Doctrine\DBAL\Driver
return
DBALException
::
ERROR_SYNTAX
;
return
DBALException
::
ERROR_SYNTAX
;
}
}
if
(
strpos
(
$exception
->
getMessage
(),
'unable to open database file'
)
!==
false
)
{
return
DBALException
::
ERROR_UNABLE_TO_OPEN
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'attempt to write a readonly database'
)
!==
false
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'attempt to write a readonly database'
)
!==
false
)
{
return
DBALException
::
ERROR_WRITE_READONLY
;
return
DBALException
::
ERROR_WRITE_READONLY
;
}
}
if
(
strpos
(
$exception
->
getMessage
(),
'unable to open database file'
)
!==
false
)
{
return
DBALException
::
ERROR_UNABLE_TO_OPEN
;
}
}
return
0
;
return
0
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
89592347
...
@@ -190,7 +190,8 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -190,7 +190,8 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
}
}
public
function
getSqLiteOpenConnection
(){
public
function
getSqLiteOpenConnection
()
{
return
array
(
return
array
(
array
(
0000
,
DBALException
::
ERROR_UNABLE_TO_OPEN
),
array
(
0000
,
DBALException
::
ERROR_UNABLE_TO_OPEN
),
array
(
0444
,
DBALException
::
ERROR_WRITE_READONLY
),
array
(
0444
,
DBALException
::
ERROR_WRITE_READONLY
),
...
@@ -216,6 +217,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -216,6 +217,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
$exceptionCode
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
$exceptionCode
);
foreach
(
$schema
->
toSql
(
$conn
->
getDatabasePlatform
())
AS
$sql
)
{
foreach
(
$schema
->
toSql
(
$conn
->
getDatabasePlatform
())
AS
$sql
)
{
$conn
->
executeQuery
(
$sql
);
$conn
->
executeQuery
(
$sql
);
}
}
...
@@ -229,14 +231,5 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -229,14 +231,5 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
array
(
array
(
'host'
=>
'localnope'
),
DBALException
::
ERROR_ACCESS_DENIED
),
array
(
array
(
'host'
=>
'localnope'
),
DBALException
::
ERROR_ACCESS_DENIED
),
);
);
}
}
protected
function
onNotSuccessfulTest
(
\Exception
$e
)
{
parent
::
onNotSuccessfulTest
(
$e
);
if
(
"PHPUnit_Framework_SkippedTestError"
==
get_class
(
$e
))
{
return
;
}
var_dump
(
$e
);
}
}
}
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