Commit fcc09f60 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #410 from deeky666/fix-connection-insert

Fix Connection::insert() with empty data given
parents 3aae47ae 60606fce
...@@ -604,15 +604,16 @@ class Connection implements DriverConnection ...@@ -604,15 +604,16 @@ class Connection implements DriverConnection
{ {
$this->connect(); $this->connect();
if ( ! is_int(key($types))) { if (empty($data)) {
$types = $this->extractTypeValues($data, $types); return $this->executeUpdate('INSERT INTO ' . $tableName . ' ()' . ' VALUES ()');
} }
$query = 'INSERT INTO ' . $tableName return $this->executeUpdate(
. ' (' . implode(', ', array_keys($data)) . ')' 'INSERT INTO ' . $tableName . ' (' . implode(', ', array_keys($data)) . ')' .
. ' VALUES (' . implode(', ', array_fill(0, count($data), '?')) . ')'; ' VALUES (' . implode(', ', array_fill(0, count($data), '?')) . ')',
array_values($data),
return $this->executeUpdate($query, array_values($data), $types); is_int(key($types)) ? $types : $this->extractTypeValues($data, $types)
);
} }
/** /**
......
...@@ -275,4 +275,24 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); ...@@ -275,4 +275,24 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this->assertFalse($conn->isTransactionActive()); $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());
}
}
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