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
d47e926e
Commit
d47e926e
authored
Sep 02, 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 non unique field name exception for sqlite
parent
6401e760
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
3 deletions
+29
-3
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+1
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+4
-0
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+24
-3
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
d47e926e
...
...
@@ -27,6 +27,7 @@ class DBALException extends \Exception
const
ERROR_FOREIGN_KEY_CONSTRAINT
=
4
;
const
ERROR_NOT_NULL
=
5
;
const
ERROR_BAD_FIELD_NAME
=
6
;
const
ERROR_NON_UNIQUE_FIELD_NAME
=
7
;
/**
* @param string $method
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
d47e926e
...
...
@@ -139,6 +139,10 @@ class Driver implements \Doctrine\DBAL\Driver
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
;
}
}
return
0
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
d47e926e
...
...
@@ -94,15 +94,36 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
$table
=
$schema
->
createTable
(
"
non_uniqu
e_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'unique'
=>
true
));
$table
=
$schema
->
createTable
(
"
bad_fieldnam
e_table"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
());
foreach
(
$schema
->
toSql
(
$this
->
_conn
->
getDatabasePlatform
())
AS
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
}
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_BAD_FIELD_NAME
);
$this
->
_conn
->
insert
(
"non_unique_table"
,
array
(
'name'
=>
5
));
$this
->
_conn
->
insert
(
"bad_fieldname_table"
,
array
(
'name'
=>
5
));
}
public
function
testNonUniqueFieldNameException
()
{
$schema
=
new
\Doctrine\DBAL\Schema\Schema
();
$table
=
$schema
->
createTable
(
"ambiguous_list_table"
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table2
=
$schema
->
createTable
(
"ambiguous_list_table_2"
);
$table2
->
addColumn
(
'id'
,
'integer'
);
foreach
(
$schema
->
toSql
(
$this
->
_conn
->
getDatabasePlatform
())
AS
$sql
)
{
$this
->
_conn
->
executeQuery
(
$sql
);
}
$sql
=
'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2'
;
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
);
$this
->
_conn
->
executeQuery
(
$sql
);
}
protected
function
onNotSuccessfulTest
(
\Exception
$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