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
f8b46957
Commit
f8b46957
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] Implement error detection on duplicate table for mysql and sqlite
parent
94089fd9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
0 deletions
+22
-0
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+1
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+2
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+4
-0
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+15
-0
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
f8b46957
...
@@ -23,6 +23,7 @@ class DBALException extends \Exception
...
@@ -23,6 +23,7 @@ class DBALException extends \Exception
{
{
const
ERROR_DUPLICATE_KEY
=
1
;
const
ERROR_DUPLICATE_KEY
=
1
;
const
ERROR_UNKNOWN_TABLE
=
2
;
const
ERROR_UNKNOWN_TABLE
=
2
;
const
ERROR_TABLE_ALREADY_EXISTS
=
3
;
/**
/**
* @param string $method
* @param string $method
...
...
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
f8b46957
...
@@ -120,6 +120,8 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -120,6 +120,8 @@ class Driver implements \Doctrine\DBAL\Driver
return
DBALException
::
ERROR_DUPLICATE_KEY
;
return
DBALException
::
ERROR_DUPLICATE_KEY
;
case
'42S02'
:
case
'42S02'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
case
'42S01'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
}
return
0
;
return
0
;
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
f8b46957
...
@@ -126,6 +126,10 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -126,6 +126,10 @@ class Driver implements \Doctrine\DBAL\Driver
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
;
}
}
if
(
strpos
(
$exception
->
getMessage
(),
'already exists'
)
!==
false
)
{
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
}
}
return
0
;
return
0
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
f8b46957
...
@@ -31,5 +31,20 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -31,5 +31,20 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_UNKNOWN_TABLE
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_UNKNOWN_TABLE
);
$this
->
_conn
->
executeQuery
(
$sql
);
$this
->
_conn
->
executeQuery
(
$sql
);
}
}
public
function
testTableAlreadyExists
()
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
"duplicatekey_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
);
foreach
(
$this
->
_conn
->
getDatabasePlatform
()
->
getCreateTableSQL
(
$table
)
AS
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
}
foreach
(
$this
->
_conn
->
getDatabasePlatform
()
->
getCreateTableSQL
(
$table
)
AS
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
}
}
}
}
\ 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