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/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ abstract public function getKeywords(): array;
* @param string $prefix
* @return mixed
*/
abstract protected function getAttributeProjection(array $selections, string $prefix = ''): mixed;
abstract protected function getAttributeProjection(array $selections, string $prefix): mixed;

/**
* Get all selected attributes from queries
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Adapter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public function getKeywords(): array
return $this->delegate(__FUNCTION__, \func_get_args());
}

protected function getAttributeProjection(array $selections, string $prefix = ''): mixed
protected function getAttributeProjection(array $selections, string $prefix): mixed
{
return $this->delegate(__FUNCTION__, \func_get_args());
}
Expand Down
27 changes: 10 additions & 17 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,13 @@ public function getDocument(string $collection, string $id, array $queries = [],

$forUpdate = $forUpdate ? 'FOR UPDATE' : '';

$alias = Query::DEFAULT_ALIAS;

$sql = "
SELECT {$this->getAttributeProjection($selections)}
FROM {$this->getSQLTable($name)}
WHERE _uid = :_uid
{$this->getTenantQuery($collection)}
SELECT {$this->getAttributeProjection($selections, $alias)}
FROM {$this->getSQLTable($name)} AS {$this->quote($alias)}
WHERE {$this->quote($alias)}.{$this->quote('_uid')} = :_uid
{$this->getTenantQuery($collection, $alias)}
";

if ($this->getSupportForUpdateLock()) {
Expand Down Expand Up @@ -1680,13 +1682,10 @@ public function getTenantQuery(
* @return mixed
* @throws Exception
*/
protected function getAttributeProjection(array $selections, string $prefix = ''): mixed
protected function getAttributeProjection(array $selections, string $prefix): mixed
{
if (empty($selections) || \in_array('*', $selections)) {
if (!empty($prefix)) {
return "{$this->quote($prefix)}.*";
}
return '*';
return "{$this->quote($prefix)}.*";
}

$internalKeys = [
Expand All @@ -1703,14 +1702,8 @@ protected function getAttributeProjection(array $selections, string $prefix = ''
$selections[] = $this->getInternalKeyForAttribute($internalKey);
}

if (!empty($prefix)) {
foreach ($selections as &$selection) {
$selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}";
}
} else {
foreach ($selections as &$selection) {
$selection = "{$this->quote($this->filter($selection))}";
}
foreach ($selections as &$selection) {
$selection = "{$this->quote($prefix)}.{$this->quote($this->filter($selection))}";
}

return \implode(',', $selections);
Expand Down