Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing how insertMulti handles boolean values.

Binding values individually allows boolean to work correctly.
  • Loading branch information...
commit 0b0d180aada47e03e90985ef6d9156f0398c47ee 1 parent 1487357
@markstory markstory authored
View
30 lib/Cake/Model/Datasource/DboSource.php
@@ -2734,9 +2734,11 @@ public function boolean($data, $quote = false) {
/**
* Inserts multiple values into a table
*
- * @param string $table
- * @param string $fields
- * @param array $values
+ * @param string $table The table being inserted into.
+ * @param array $fields The array of field/column names being inserted.
+ * @param array $values The array of values to insert. The values should
+ * be an array of rows. Each row should have values keyed by the column name.
+ * Each row must have the values in the same order as $fields.
* @return boolean
*/
public function insertMulti($table, $fields, $values) {
@@ -2744,12 +2746,32 @@ public function insertMulti($table, $fields, $values) {
$holder = implode(',', array_fill(0, count($fields), '?'));
$fields = implode(', ', array_map(array(&$this, 'name'), $fields));
+ $pdoMap = array(
+ 'integer' => PDO::PARAM_INT,
+ 'float' => PDO::PARAM_STR,
+ 'boolean' => PDO::PARAM_BOOL,
+ 'string' => PDO::PARAM_STR,
+ 'text' => PDO::PARAM_STR
+ );
+ $columnMap = array();
+
$count = count($values);
$sql = "INSERT INTO {$table} ({$fields}) VALUES ({$holder})";
$statement = $this->_connection->prepare($sql);
$this->begin();
+
+ foreach ($values[0] as $key => $val) {
+ $type = $this->introspectType($val);
+ $columnMap[$key] = $pdoMap[$type];
+ }
+
for ($x = 0; $x < $count; $x++) {
- $statement->execute($values[$x]);
+ $i = 1;
+ foreach ($values[$x] as $key => $val) {
+ $statement->bindValue($i, $val, $columnMap[$key]);
+ $i += 1;
+ }
+ $statement->execute();
$statement->closeCursor();
}
return $this->commit();
View
2  lib/Cake/Test/Fixture/CounterCachePostFixture.php
@@ -34,7 +34,7 @@ class CounterCachePostFixture extends CakeTestFixture {
);
public $records = array(
- array('id' => 1, 'title' => 'Rock and Roll', 'user_id' => 66, 'published' => 0),
+ array('id' => 1, 'title' => 'Rock and Roll', 'user_id' => 66, 'published' => false),
array('id' => 2, 'title' => 'Music', 'user_id' => 66, 'published' => true),
array('id' => 3, 'title' => 'Food', 'user_id' => 301, 'published' => true),
);
Please sign in to comment.
Something went wrong with that request. Please try again.