public function toSql(BaseDriver $driver, ArgumentArray $args)
{
$sql = 'INSERT';
if (!empty($this->options)) {
$sql .= $this->buildOptionClause();
}
$sql .= ' INTO ' . $driver->quoteTable($this->intoTable);
// append partition clause if needed.
$sql .= $this->buildPartitionClause($driver, $args);
$valuesClauses = array();
$varCnt = 1;
// build columns
$columns = $this->getColumnNames($driver);
foreach ($this->values as $values) {
$deflatedValues = array();
foreach ($values as $key => $value) {
$deflatedValues[] = $driver->deflate($value, $args);
}
$valuesClauses[] = '(' . join(',', $deflatedValues) . ')';
}
$sql .= ' (' . join(',', $columns) . ')' . ' VALUES ' . join(', ', $valuesClauses);
// Check if RETURNING is supported
if ($this->returning && $driver instanceof PgSQLDriver) {
$sql .= ' RETURNING ' . join(',', $driver->quoteColumns($this->returning));
}
return $sql;
}