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
Hide 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
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.
* This properly handles binary data by returning a hex representation.
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
89592347
...
...
@@ -18,7 +18,9 @@
*/
namespace
Doctrine\DBAL\Driver\PDOSqlite
;
use
Doctrine\DBAL\DBALException
;
use
PDOException
;
/**
* The PDO Sqlite driver.
...
...
@@ -47,12 +49,16 @@ class Driver implements \Doctrine\DBAL\Driver
unset
(
$driverOptions
[
'userDefinedFunctions'
]);
}
$pdo
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
try
{
$pdo
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
}
catch
(
PDOException
$ex
)
{
throw
DBALException
::
driverException
(
$this
,
$ex
);
}
foreach
(
$this
->
_userDefinedFunctions
as
$fn
=>
$data
)
{
$pdo
->
sqliteCreateFunction
(
$fn
,
$data
[
'callback'
],
$data
[
'numArgs'
]);
...
...
@@ -119,47 +125,44 @@ class Driver implements \Doctrine\DBAL\Driver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
23000
:
if
(
strpos
(
$exception
->
getMessage
(),
'must be unique'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'may not be NULL'
)
!==
false
)
{
return
DBALException
::
ERROR_NOT_NULL
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
)
{
return
DBALException
::
ERROR_NOT_UNIQUE
;
}
case
'HY000'
:
if
(
strpos
(
$exception
->
getMessage
(),
'no such table:'
)
!==
false
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'already exists'
)
!==
false
)
{
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'has no column named'
)
!==
false
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'ambiguous column name'
)
!==
false
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'syntax error'
)
!==
false
)
{
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
)
{
return
DBALException
::
ERROR_WRITE_READONLY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'must be unique'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'may not be NULL'
)
!==
false
)
{
return
DBALException
::
ERROR_NOT_NULL
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
)
{
return
DBALException
::
ERROR_NOT_UNIQUE
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'no such table:'
)
!==
false
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'already exists'
)
!==
false
)
{
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'has no column named'
)
!==
false
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'ambiguous column name'
)
!==
false
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'syntax error'
)
!==
false
)
{
return
DBALException
::
ERROR_SYNTAX
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'attempt to write a readonly database'
)
!==
false
)
{
return
DBALException
::
ERROR_WRITE_READONLY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'unable to open database file'
)
!==
false
)
{
return
DBALException
::
ERROR_UNABLE_TO_OPEN
;
}
return
0
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
89592347
...
...
@@ -51,7 +51,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
$table
=
$schema
->
createTable
(
"constraint_error_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
$table
->
setPrimaryKey
(
array
(
'id'
));
...
...
@@ -72,7 +72,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
);
$this
->
_conn
->
delete
(
'constraint_error_table'
,
array
(
'id'
=>
1
));
}
public
function
testNotNullException
()
{
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
...
...
@@ -168,16 +168,16 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$filename
=
sprintf
(
'%s/%s'
,
sys_get_temp_dir
(),
'doctrine_failed_connection.db'
);
if
(
file_exists
(
$filename
))
{
unlink
(
$filename
);
}
unlink
(
$filename
);
}
touch
(
$filename
);
chmod
(
$filename
,
$mode
);
$params
=
array
(
'driver'
=>
'pdo_sqlite'
,
'path'
=>
$filename
,
);
'driver'
=>
'pdo_sqlite'
,
'path'
=>
$filename
,
);
$conn
=
\Doctrine\DBAL\DriverManager
::
getConnection
(
$params
);
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
...
...
@@ -186,15 +186,16 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
$exceptionCode
);
foreach
(
$schema
->
toSql
(
$conn
->
getDatabasePlatform
())
AS
$sql
)
{
$conn
->
executeQuery
(
$sql
);
}
$conn
->
executeQuery
(
$sql
);
}
}
public
function
getSqLiteOpenConnection
(){
return
array
(
array
(
0000
,
DBALException
::
ERROR_UNABLE_TO_OPEN
),
array
(
0444
,
DBALException
::
ERROR_WRITE_READONLY
),
);
public
function
getSqLiteOpenConnection
()
{
return
array
(
array
(
0000
,
DBALException
::
ERROR_UNABLE_TO_OPEN
),
array
(
0444
,
DBALException
::
ERROR_WRITE_READONLY
),
);
}
/**
...
...
@@ -216,27 +217,19 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table
->
addColumn
(
'id'
,
'integer'
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
$exceptionCode
);
foreach
(
$schema
->
toSql
(
$conn
->
getDatabasePlatform
())
AS
$sql
)
{
$conn
->
executeQuery
(
$sql
);
}
$conn
->
executeQuery
(
$sql
);
}
}
public
function
getConnectionParams
()
{
return
array
(
array
(
array
(
'user'
=>
'not_existing'
),
DBALException
::
ERROR_ACCESS_DENIED
),
array
(
array
(
'password'
=>
'really_not'
),
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
);
return
array
(
array
(
array
(
'user'
=>
'not_existing'
),
DBALException
::
ERROR_ACCESS_DENIED
),
array
(
array
(
'password'
=>
'really_not'
),
DBALException
::
ERROR_ACCESS_DENIED
),
array
(
array
(
'host'
=>
'localnope'
),
DBALException
::
ERROR_ACCESS_DENIED
),
);
}
}
\ 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