Skip to content

Commit

Permalink
quote identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Green committed Aug 26, 2015
1 parent 3bc69d6 commit 7664bc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/DbSync/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ protected function doMultiInsert($table, $data, $type = self::INSERT)
$qs .= ('(' . rtrim($subq, ',') . ')' . (++$i !== $count ? ',' : ''));
}

$cols = array_map(array($this, 'quoteIdentifier'), $cols);

return $this->query($type . ' INTO ' . $table . ' (' . implode(',', $cols) . ') VALUES ' . $qs, $bind);
}

Expand Down Expand Up @@ -297,18 +299,29 @@ public function multiInsertOnDuplicateKeyUpdate($table, $data)
$qs = trim($qs, ',') . '),';
}

$cols = array_map(array($this, 'quoteIdentifier'), $cols);

$colsValues = array_map(function ($col) {
return $col . ' = VALUES(' . $col . ')';
}, $cols);

// Build the statement
$sql = 'INSERT INTO ' . $table . '
(' . implode(', ', $cols) . ') VALUES ' . trim($qs, ',') . '
(' . implode(', ', $cols) . ') VALUES ' . trim($qs, ',') . '
ON DUPLICATE KEY UPDATE ' . implode(', ', $colsValues);

return $this->query($sql, $bind);
}

/**
* @param $column
* @return string
*/
private function quoteIdentifier($column)
{
return '`' . $column . '`';
}

public static function make(array $config)
{

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'host' => 'localhost',
'driver' => 'mysql',
'username' => 'root',
'password' => '',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
Expand Down

0 comments on commit 7664bc9

Please sign in to comment.