Commit 01760a4a authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-661' into 2.4

parents 4ce45f76 940ff55e
......@@ -548,15 +548,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)
);
}
/**
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Events;
use Doctrine\Tests\Mocks\DriverConnectionMock;
class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
......@@ -174,4 +175,24 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this->_conn->getConfiguration()->setSQLLogger($logger);
$this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger());
}
}
\ 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());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment