Skip to content

Commit f884da1

Browse files
norbedg
authored andcommitted
SqlBuilder::getSelectQueryHash(): Fixed "Cannot unpack array with string keys" (#133)
Variadic unpacking do not support associative arrays. Next think is that the keys at joinCondition part of parameters array are required to get correct hash...
1 parent e3de4e7 commit f884da1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Database/Table/SqlBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ public function getSelectQueryHash($columns = NULL)
158158
} else {
159159
$parts[] = "{$this->delimitedTable}.*";
160160
}
161-
return $this->getConditionHash(json_encode($parts), array_merge(
161+
return $this->getConditionHash(json_encode($parts), [
162162
$this->parameters['select'],
163-
$this->parameters['joinCondition'] ? array_merge(...$this->parameters['joinCondition']) : [],
163+
$this->parameters['joinCondition'],
164164
$this->parameters['where'],
165165
$this->parameters['group'],
166166
$this->parameters['having'],
167167
$this->parameters['order']
168-
));
168+
]);
169169
}
170170

171171

@@ -771,13 +771,15 @@ protected function addConditionComposition(array $columns, array $parameters, ar
771771

772772
private function getConditionHash($condition, $parameters)
773773
{
774-
foreach ($parameters as & $parameter) {
774+
foreach ($parameters as $key => & $parameter) {
775775
if ($parameter instanceof Selection) {
776776
$parameter = $this->getConditionHash($parameter->getSql(), $parameter->getSqlBuilder()->getParameters());
777777
} elseif ($parameter instanceof SqlLiteral) {
778778
$parameter = $this->getConditionHash($parameter->__toString(), $parameter->getParameters());
779779
} elseif (is_object($parameter) && method_exists($parameter, '__toString')) {
780780
$parameter = $parameter->__toString();
781+
} elseif (is_array($parameter) || $parameter instanceof \ArrayAccess) {
782+
$parameter = $this->getConditionHash($key, $parameter);
781783
}
782784
}
783785
return md5($condition . json_encode($parameters));

0 commit comments

Comments
 (0)