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
fcc09f60
Commit
fcc09f60
authored
Dec 18, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #410 from deeky666/fix-connection-insert
Fix Connection::insert() with empty data given
parents
3aae47ae
60606fce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
Connection.php
lib/Doctrine/DBAL/Connection.php
+8
-7
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+21
-1
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
fcc09f60
...
...
@@ -604,15 +604,16 @@ class Connection implements DriverConnection
{
$this
->
connect
();
if
(
!
is_int
(
key
(
$types
)
))
{
$types
=
$this
->
extractTypeValues
(
$data
,
$types
);
if
(
empty
(
$data
))
{
return
$this
->
executeUpdate
(
'INSERT INTO '
.
$tableName
.
' ()'
.
' VALUES ()'
);
}
$query
=
'INSERT INTO '
.
$tableName
.
' ('
.
implode
(
', '
,
array_keys
(
$data
))
.
')'
.
' VALUES ('
.
implode
(
', '
,
array_fill
(
0
,
count
(
$data
),
'?'
))
.
')'
;
return
$this
->
executeUpdate
(
$query
,
array_values
(
$data
),
$types
);
return
$this
->
executeUpdate
(
'INSERT INTO '
.
$tableName
.
' ('
.
implode
(
', '
,
array_keys
(
$data
))
.
')'
.
' VALUES ('
.
implode
(
', '
,
array_fill
(
0
,
count
(
$data
),
'?'
))
.
')'
,
array_values
(
$data
),
is_int
(
key
(
$types
))
?
$types
:
$this
->
extractTypeValues
(
$data
,
$types
)
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
fcc09f60
...
...
@@ -275,4 +275,24 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this
->
assertFalse
(
$conn
->
isTransactionActive
());
}
}
\ No newline at end of file
public
function
testEmptyInsert
()
{
$driverMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver'
);
$driverMock
->
expects
(
$this
->
any
())
->
method
(
'connect'
)
->
will
(
$this
->
returnValue
(
new
DriverConnectionMock
()));
$conn
=
$this
->
getMockBuilder
(
'Doctrine\DBAL\Connection'
)
->
setMethods
(
array
(
'executeUpdate'
))
->
setConstructorArgs
(
array
(
array
(
'platform'
=>
new
Mocks\MockPlatform
()),
$driverMock
))
->
getMock
();
$conn
->
expects
(
$this
->
once
())
->
method
(
'executeUpdate'
)
->
with
(
'INSERT INTO footable () VALUES ()'
);
$conn
->
insert
(
'footable'
,
array
());
}
}
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