Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Condition/InConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function buildCompositeInCondition(?string $operator, $columns, $value
$quotedColumns = [];

foreach ($columns as $i => $column) {
$quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column;
$quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->getDb()->quoteColumnName($column) : $column;
}

$vss = [];
Expand Down
49 changes: 27 additions & 22 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class QueryBuilder extends BaseQueryBuilder
/**
* @var array mapping from abstract column types (keys) to physical column types (values).
*/
public array $typeMap = [
protected array $typeMap = [
Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_UPK => 'integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_BIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
Expand Down Expand Up @@ -491,43 +491,43 @@ public function build(Query $query, array $params = []): array
{
$query = $query->prepare($this);

$params = empty($params) ? $query->params : array_merge($params, $query->params);
$params = empty($params) ? $query->getParams() : array_merge($params, $query->getParams());

$clauses = [
$this->buildSelect($query->select, $params, $query->distinct, $query->selectOption),
$this->buildFrom($query->from, $params),
$this->buildJoin($query->join, $params),
$this->buildWhere($query->where, $params),
$this->buildGroupBy($query->groupBy),
$this->buildHaving($query->having, $params),
$this->buildSelect($query->getSelect(), $params, $query->getDistinct(), $query->getSelectOption()),
$this->buildFrom($query->getFrom(), $params),
$this->buildJoin($query->getJoin(), $params),
$this->buildWhere($query->getWhere(), $params),
$this->buildGroupBy($query->getGroupBy()),
$this->buildHaving($query->getHaving(), $params),
];

$sql = implode($this->separator, array_filter($clauses));
$sql = $this->buildOrderByAndLimit($sql, $query->orderBy, $query->limit, $query->offset);
$sql = $this->buildOrderByAndLimit($sql, $query->getOrderBy(), $query->getLimit(), $query->getOffset());

if (!empty($query->orderBy)) {
foreach ($query->orderBy as $expression) {
if (!empty($query->getOrderBy())) {
foreach ($query->getOrderBy() as $expression) {
if ($expression instanceof ExpressionInterface) {
$this->buildExpression($expression, $params);
}
}
}

if (!empty($query->groupBy)) {
foreach ($query->groupBy as $expression) {
if (!empty($query->getGroupBy())) {
foreach ($query->getGroupBy() as $expression) {
if ($expression instanceof ExpressionInterface) {
$this->buildExpression($expression, $params);
}
}
}

$union = $this->buildUnion($query->union, $params);
$union = $this->buildUnion($query->getUnion(), $params);

if ($union !== '') {
$sql = "$sql{$this->separator}$union";
}

$with = $this->buildWithQueries($query->withQueries, $params);
$with = $this->buildWithQueries($query->getWithQueries(), $params);

if ($with !== '') {
$sql = "$with{$this->separator}$sql";
Expand All @@ -547,13 +547,13 @@ public function createIndex(string $name, string $table, $columns, bool $unique
'/(`.*`) ON ({{(%?)([\w\-]+)}\}\.{{((%?)[\w\-]+)\\}\\})|(`.*`) ON ({{(%?)([\w\-]+)\.([\w\-]+)\\}\\})/',
static function ($matches) {
if (!empty($matches[1])) {
return $matches[4].".".$matches[1]
. ' ON {{' .$matches[3].$matches[5] . '}}';
return $matches[4] . "." . $matches[1]
. ' ON {{' . $matches[3] . $matches[5] . '}}';
}

if (!empty($matches[7])) {
return $matches[10]. '.' .$matches[7]
. ' ON {{' .$matches[9].$matches[11] . '}}';
return $matches[10] . '.' . $matches[7]
. ' ON {{' . $matches[9] . $matches[11] . '}}';
}
},
$sql
Expand Down Expand Up @@ -597,7 +597,12 @@ public function upsert(string $table, $insertColumns, $updateColumns, array &$pa
/** @var Constraint[] $constraints */
$constraints = [];

[$uniqueNames, $insertNames, $updateNames] = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
[$uniqueNames, $insertNames, $updateNames] = $this->prepareUpsertColumns(
$table,
$insertColumns,
$updateColumns,
$constraints
);

if (empty($uniqueNames)) {
return $this->insert($table, $insertColumns, $params);
Expand Down Expand Up @@ -638,8 +643,8 @@ public function upsert(string $table, $insertColumns, $updateColumns, array &$pa
}

$updateSql = 'WITH "EXCLUDED" (' . implode(', ', $insertNames)
. ') AS (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' ')) . ') '
. $this->update($table, $updateColumns, $updateCondition, $params);
. ') AS (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' '))
. ') ' . $this->update($table, $updateColumns, $updateCondition, $params);

return "$updateSql; $insertSql;";
}
Expand Down