diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 81a3564b4..7e8eef21b 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -580,22 +580,6 @@ class DboMysql extends DboSource { return $alter; } -/** - * Inserts multiple values into a table - * - * @param string $table - * @param string $fields - * @param array $values - */ - function insertMulti($table, $fields, $values) { - $table = $this->fullTableName($table); - if (is_array($fields)) { - $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); - } - $values = implode(', ', $values); - $this->query("INSERT INTO {$table} ({$fields}) VALUES {$values}"); - } - /** * Returns an detailed array of sources (tables) in the database. * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 038a11551..8dde0531f 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -291,8 +291,7 @@ class DboSource extends DataSource { * @return mixed Resource or object representing the result set, or false on failure */ public function execute($sql, $options = array(), $params = array()) { - $defaults = array('log' => $this->fullDebug); - $options = array_merge($defaults, $options); + $options = $options + array('log' => $this->fullDebug); $this->error = null; $t = microtime(true); @@ -2686,13 +2685,17 @@ class DboSource extends DataSource { */ public function insertMulti($table, $fields, $values) { $table = $this->fullTableName($table); - if (is_array($fields)) { - $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); - } + $holder = implode(',', array_fill(0, count($fields), '?')); + $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); + $count = count($values); + $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$holder})"; + $statement = $this->_connection->prepare($sql); for ($x = 0; $x < $count; $x++) { - $this->query("INSERT INTO {$table} ({$fields}) VALUES {$values[$x]}"); + $statement->execute($values[$x]); + $statement->closeCursor(); } + return true; } /** diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index c4b693a0c..d6954b97d 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1459,15 +1459,11 @@ class Model extends Object { foreach ((array)$data as $row) { if ((is_string($row) && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) { - $values = array( - $db->value($id, $this->getColumnType($this->primaryKey)), - $db->value($row) - ); + $values = array($id, $row); if ($isUUID && $primaryAdded) { - $values[] = $db->value(String::uuid()); + $values[] = String::uuid(); } - $values = implode(',', $values); - $newValues[] = "({$values})"; + $newValues[] = $values; unset($values); } elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) { $newData[] = $row; @@ -1506,7 +1502,6 @@ class Model extends Object { } if (!empty($newValues)) { - $fields = implode(',', $fields); $db->insertMulti($this->{$join}, $fields, $newValues); } } diff --git a/cake/tests/cases/libs/model/behavior_collection.test.php b/cake/tests/cases/libs/model/behavior_collection.test.php index a40fee525..92c8fff5e 100644 --- a/cake/tests/cases/libs/model/behavior_collection.test.php +++ b/cake/tests/cases/libs/model/behavior_collection.test.php @@ -546,6 +546,7 @@ class BehaviorCollectionTest extends CakeTestCase { */ function testBehaviorToggling() { $Apple = new Apple(); + $expected = $Apple->find('all'); $this->assertIdentical($Apple->Behaviors->enabled(), array()); $Apple->Behaviors->init('Apple', array('Test' => array('key' => 'value'))); diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 37a037a89..7e0484700 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -5076,7 +5076,7 @@ class ModelReadTest extends BaseModelTest { 'typ' => 2 ))); - $this->assertEqual($result, $expected); + $this->assertEqual($expected, $result); } /** @@ -5646,7 +5646,7 @@ class ModelReadTest extends BaseModelTest { 'name' => 'computer' )))))); - $this->assertIdentical($result, $expected); + $this->assertEquals($result, $expected); } /** diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index eeeae5c9d..fee5721b6 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -163,13 +163,13 @@ class CakeTestFixture { * @return boolean on success or if there are no records to insert, or false on failure */ public function insert(&$db) { + $this->truncate($db); if (!isset($this->_insert)) { $values = array(); - if (isset($this->records) && !empty($this->records)) { foreach ($this->records as $record) { $fields = array_keys($record); - $values[] = '(' . implode(', ', array_map(array(&$db, 'value'), array_values($record))) . ')'; + $values[] = array_values($record); } return $db->insertMulti($this->table, $fields, $values); }