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
1d9dec7b
Commit
1d9dec7b
authored
Sep 30, 2013
by
dazz
Committed by
Benjamin Eberlei
Nov 13, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-407] Implement and detect SqLite connection exceptions
parent
3e580007
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
0 deletions
+52
-0
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+2
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+8
-0
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+42
-0
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
1d9dec7b
...
@@ -30,6 +30,8 @@ class DBALException extends \Exception
...
@@ -30,6 +30,8 @@ class DBALException extends \Exception
const
ERROR_NON_UNIQUE_FIELD_NAME
=
7
;
const
ERROR_NON_UNIQUE_FIELD_NAME
=
7
;
const
ERROR_NOT_UNIQUE
=
8
;
const
ERROR_NOT_UNIQUE
=
8
;
const
ERROR_SYNTAX
=
9
;
const
ERROR_SYNTAX
=
9
;
const
ERROR_UNABLE_TO_OPEN
=
10
;
const
ERROR_WRITE_READONLY
=
11
;
/**
/**
* @param string $method
* @param string $method
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
1d9dec7b
...
@@ -152,6 +152,14 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -152,6 +152,14 @@ class Driver implements \Doctrine\DBAL\Driver
if
(
strpos
(
$exception
->
getMessage
(),
'syntax error'
)
!==
false
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'syntax error'
)
!==
false
)
{
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
)
{
return
DBALException
::
ERROR_WRITE_READONLY
;
}
}
}
return
0
;
return
0
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
1d9dec7b
...
@@ -164,5 +164,47 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -164,5 +164,47 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
var_dump
(
$e
);
var_dump
(
$e
);
}
}
/**
* @dataProvider getSqLiteOpenConnection
*/
public
function
testConnectionExceptionSqLite
(
$mode
,
$exceptionCode
)
{
if
(
$this
->
_conn
->
getDatabasePlatform
()
->
getName
()
!=
'sqlite'
)
{
$this
->
markTestSkipped
(
"Only fails this way on sqlite"
);
}
$filename
=
sprintf
(
'%s/%s'
,
sys_get_temp_dir
(),
'doctrine_failed_connection.db'
);
if
(
file_exists
(
$filename
))
{
unlink
(
$filename
);
}
touch
(
$filename
);
chmod
(
$filename
,
$mode
);
$params
=
array
(
'driver'
=>
'pdo_sqlite'
,
'path'
=>
$filename
,
);
$conn
=
\Doctrine\DBAL\DriverManager
::
getConnection
(
$params
);
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
$table
=
$schema
->
createTable
(
"no_connection"
);
$table
->
addColumn
(
'id'
,
'integer'
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
$exceptionCode
);
foreach
(
$schema
->
toSql
(
$conn
->
getDatabasePlatform
())
AS
$sql
)
{
$conn
->
executeQuery
(
$sql
);
}
}
public
function
getSqLiteOpenConnection
(){
return
array
(
array
(
0000
,
DBALException
::
ERROR_UNABLE_TO_OPEN
),
array
(
0444
,
DBALException
::
ERROR_WRITE_READONLY
),
);
}
}
}
\ 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