Skip to content

Commit

Permalink
Fix insertion errors from the previous change.
Browse files Browse the repository at this point in the history
Strip out common identifier quoting characters so that the default row
has the same keys as the data being inserted.
  • Loading branch information
markstory committed May 13, 2016
1 parent dc5cc8b commit cafb4ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Database/Expression/ValuesExpression.php
Expand Up @@ -151,7 +151,13 @@ public function sql(ValueBinder $generator)
}

$i = 0;
$defaults = array_fill_keys($this->_columns, null);
$columns = [];

// Remove identifier quoting so column names match keys.
foreach ($this->_columns as $col) {
$columns[] = trim($col, '`[]"');
}
$defaults = array_fill_keys($columns, null);
$placeholders = [];

foreach ($this->_values as $row) {
Expand All @@ -173,7 +179,6 @@ public function sql(ValueBinder $generator)
if ($this->query()) {
return ' ' . $this->query()->sql($generator);
}

return sprintf(' VALUES (%s)', implode('), (', $placeholders));
}

Expand Down
7 changes: 5 additions & 2 deletions src/Database/Query.php
Expand Up @@ -1320,8 +1320,11 @@ public function insert(array $columns, array $types = [])
$this->_dirty();
$this->_type = 'insert';
$this->_parts['insert'][1] = $columns;
$this->_parts['values'] = new ValuesExpression($columns, $this->typeMap()->types($types));

if (!$this->_parts['values']) {
$this->_parts['values'] = new ValuesExpression($columns, $this->typeMap()->types($types));
} else {
$this->_parts['values']->columns($columns);
}
return $this;
}

Expand Down

0 comments on commit cafb4ad

Please sign in to comment.