Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,23 @@ protected function buildCriteria(array $statements, bool $bindValues = true): ar
// Get the criteria only query from the nestedCriteria object
$queryObject = $nestedCriteria->getQuery('criteriaOnly', true);

// Skip if the closure didn't add any criteria (empty closure)
$sql = $queryObject->getSql();
if (trim($sql) === '')
{
// Remove the joiner (AND/OR) that was already pushed before the closure check
if ($joiner !== '')
{
array_pop($criteria);
}
continue;
}

// Merge the bindings we get from nestedCriteria object
$bindings[] = $queryObject->getBindings();

// Append the sql we get from the nestedCriteria object
$criteria[] = "({$queryObject->getSql()})";
$criteria[] = "({$sql})";

continue;
}
Expand Down Expand Up @@ -358,7 +370,7 @@ protected function buildAliasedTableName(string $table, array $statements): stri
{
$this->aliasPrefix = $statements['aliases'][$table] ?? null;
if ($this->aliasPrefix !== null) {
return sprintf('%s AS %s', $this->wrapSanitizer($table), $this->wrapSanitizer(strtolower($this->aliasPrefix)));
return sprintf('%s AS %s', $this->wrapSanitizer($table), $this->wrapSanitizer($this->aliasPrefix));
}

return sprintf('%s', $this->wrapSanitizer($table));
Expand All @@ -375,7 +387,8 @@ protected function buildAliasedTableName(string $table, array $statements): stri
*/
public function criteriaOnly(array $statements, $bindValues = true): array
{
$sql = $bindings = [];
$sql = '';
$bindings = [];
if (isset($statements['criteria']) === false) {
return compact('sql', 'bindings');
}
Expand Down Expand Up @@ -443,7 +456,7 @@ private function doInsert(array $statements, array $data, $type): array
$keys[] = $key;
if ($value instanceof Raw) {
$values[] = (string)$value;
$bindings[] = $value->getBindings();
$bindings = array_merge($bindings, (array)$value->getBindings()); // ✅ FIXED
} else {
$values[] = '?';
$bindings[] = $value;
Expand Down Expand Up @@ -493,7 +506,7 @@ private function getUpdateStatement(array $data): array

if ($value instanceof Raw) {
$statements[] = $statement . $value;
$bindings += $value->getBindings();
$bindings = array_merge($bindings, (array)$value->getBindings()); // fixed
} else {
$statements[] = $statement . '?';
$bindings[] = $value;
Expand Down Expand Up @@ -807,4 +820,4 @@ public function wrapSanitizer($value)
// Join these back with "." and return
return implode('.', $valueArr);
}
}
}
4 changes: 2 additions & 2 deletions src/Pecee/Pixie/QueryBuilder/Adapters/Sqlserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function select(array $statements): array
$prefix = $statements['aliases'][$table] ?? null;

if ($prefix !== null) {
$t = sprintf('%s AS %s', $table, strtolower($prefix));
$t = sprintf('%s AS %s', $table, $prefix);
} else {
$t = sprintf('%s', $table);
}
Expand Down Expand Up @@ -179,4 +179,4 @@ public function wrapSanitizer($value)
// Join these back with "." and return
return implode('.', $valueArr);
}
}
}
4 changes: 2 additions & 2 deletions src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public function alias(string $alias, ?string $table = null): self
$table = $this->tablePrefix . $table;
}

$this->statements['aliases'][$table] = \strtolower($alias);
$this->statements['aliases'][$table] = $alias;

return $this;
}
Expand Down Expand Up @@ -1883,4 +1883,4 @@ public function close(): void
$this->connection = null;
}

}
}