Skip to content

Commit

Permalink
Fix errors when columns match value lengths.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 26, 2013
1 parent c27267f commit 0711368
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Cake/Database/Dialect/SqliteDialectTrait.php
Expand Up @@ -88,7 +88,7 @@ protected function _transformFunctionExpression(FunctionExpression $expression)
}

/**
* Transforms an insert query that is meant to insert multiple tows at a time,
* Transforms an insert query that is meant to insert multiple rows at a time,
* otherwise it leaves the query untouched.
*
* The way SQLite works with multi insert is by having multiple select statements
Expand All @@ -105,9 +105,13 @@ protected function _insertQueryTranslator($query) {
$cols = $v->columns();
$newQuery = $query->connection()->newQuery();
$values = [];
debug($cols);
foreach ($v->values() as $k => $val) {
$values[] = $val;
$val = array_merge($val, array_fill(0, count($cols) - count($val), null));
$fillLength = count($cols) - count($val);
if ($fillLength > 0) {
$val = array_merge($val, array_fill(0, $fillLength, null));
}
$val = array_map(function($val) {
return $val instanceof ExpressionInterface ? $val : '?';
}, $val);
Expand Down

0 comments on commit 0711368

Please sign in to comment.