Skip to content

Commit fe0e605

Browse files
committed
refactor(database): simplify RawSql condition handling
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 565c123 commit fe0e605

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎system/Database/BaseBuilder.php‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,12 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
11001100
$condition = $k . $op . $v;
11011101

11021102
if ($v instanceof RawSql) {
1103-
$condition = $v->with($condition);
1103+
$this->{$qbKey}[] = [
1104+
'condition' => $v->with($this->getWhereHavingPrefix($qbKey, $type) . $condition),
1105+
'escape' => $escape,
1106+
];
1107+
1108+
continue;
11041109
}
11051110

11061111
$this->addWhereHavingCondition($qbKey, [
@@ -1113,21 +1118,19 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
11131118
}
11141119

11151120
/**
1121+
* @param 'QBHaving'|'QBWhere' $clause
11161122
* @param array<string, mixed> $condition
11171123
*/
11181124
private function addWhereHavingCondition(string $clause, array $condition, string $type): void
11191125
{
1120-
$prefix = $this->getWhereHavingPrefix($clause, $type);
1121-
1122-
if ($condition['condition'] instanceof RawSql) {
1123-
$condition['condition'] = $condition['condition']->with($prefix . $condition['condition']);
1124-
} else {
1125-
$condition['condition'] = $prefix . $condition['condition'];
1126-
}
1126+
$condition['condition'] = $this->getWhereHavingPrefix($clause, $type) . $condition['condition'];
11271127

11281128
$this->{$clause}[] = $condition;
11291129
}
11301130

1131+
/**
1132+
* @param 'QBHaving'|'QBWhere' $clause
1133+
*/
11311134
private function getWhereHavingPrefix(string $clause, string $type): string
11321135
{
11331136
return $this->{$clause} === [] ? $this->groupGetType('') : $this->groupGetType($type);

0 commit comments

Comments
 (0)