Skip to content

Commit

Permalink
Multi-row insert's do not work in Sqlite right now.
Browse files Browse the repository at this point in the history
I've fixed some of the issues but not all of them. There is
still a problem with nulls being inserted in every column.
  • Loading branch information
markstory committed May 26, 2013
1 parent 603de3c commit 69f35d1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/Cake/Database/Dialect/SqliteDialectTrait.php
Expand Up @@ -102,32 +102,33 @@ protected function _insertQueryTranslator($query) {
return $query;
}

$cols = $v->columns();
$newQuery = $query->connection()->newQuery();
$cols = $v->columns();
$values = [];
debug($cols);
foreach ($v->values() as $k => $val) {
$values[] = $val;
$fillLength = count($cols) - count($val);
if ($fillLength > 0) {
$val = array_merge($val, array_fill(0, $fillLength, null));
}
// TODO this doesn't work all columns are inserted as null.
$val = array_map(function($val) {
return $val instanceof ExpressionInterface ? $val : '?';
}, $val);

$select = array_combine($cols, $val);
if ($k === 0) {
array_unshift($values, $newQuery->select(array_combine($cols, $val)));
array_unshift($values, $newQuery->select($select));
continue;
}

$q = $newQuery->connection()->newQuery();
$newQuery->union($q->select(array_combine($cols, $val)), true);
$newQuery->union($q->select($select), true);
}

$v = clone $v;
$v->values($values);
return $query->values($v);
$v->values([$newQuery]);
$query->values($v);
return $query;
}

/**
Expand Down

0 comments on commit 69f35d1

Please sign in to comment.