Skip to content

Commit

Permalink
save no cond as null
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Feb 23, 2024
1 parent 714e435 commit b5eeca9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/Persistence/Sql/Oracle/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function render(): array
#[\Override]
protected function _subrenderCondition(array $row): string
{
if (count($row) === 2) {
[$field, $value] = $row;
$cond = '=';
} elseif (count($row) >= 3) {
if (count($row) === 3) {
[$field, $cond, $value] = $row;
if ($cond === null) {
$cond = '=';
}
}

if (count($row) >= 2 && $field instanceof Field
if (count($row) === 3 && $field instanceof Field
&& in_array($field->type, ['text', 'blob'], true)) {
if ($field->type === 'text') {
$field = $this->expr('LOWER([])', [$field]);
Expand Down
30 changes: 14 additions & 16 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num
} else {
if ($numArgs === 2) {
$value = $cond;
unset($cond);
$cond = null;
} elseif ($cond === null) {
throw new \InvalidArgumentException();
}

if (is_object($value) && !$value instanceof Expressionable) {
Expand All @@ -461,11 +463,7 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num
->addMoreInfo('value', $value);
}

if ($numArgs === 2) {
$this->args[$kind][] = [$field, $value];
} else {
$this->args[$kind][] = [$field, $cond, $value];
}
$this->args[$kind][] = [$field, $cond, $value];
}

return $this;
Expand Down Expand Up @@ -527,12 +525,10 @@ protected function _renderConditionInOperator(bool $negated, string $sqlLeft, ar
*/
protected function _subrenderCondition(array $row): string
{
if (count($row) === 3) {
[$field, $cond, $value] = $row;
} elseif (count($row) === 2) {
[$field, $cond] = $row;
} elseif (count($row) === 1) {
if (count($row) === 1) {
[$field] = $row;
} elseif (count($row) === 3) {
[$field, $cond, $value] = $row;
} else {
throw new \InvalidArgumentException();
}
Expand All @@ -544,10 +540,8 @@ protected function _subrenderCondition(array $row): string
return $field;
}

// if no condition defined - use default
if (count($row) === 2) {
$value = $cond;

// if no condition defined - set default condition
if ($cond === null) {
if ($value instanceof Expressionable) {
$value = $value->getDsqlExpression($this);
}
Expand All @@ -571,7 +565,7 @@ protected function _subrenderCondition(array $row): string
}

// special conditions (IS | IS NOT) if value is null
if ($value === null) { // @phpstan-ignore-line see https://github.com/phpstan/phpstan/issues/4173
if ($value === null) {
if ($cond === '=') {
return $field . ' is null';
} elseif ($cond === '!=') {
Expand Down Expand Up @@ -1145,6 +1139,10 @@ public function caseExpr($operand = null)
*/
public function caseWhen($when, $then)
{
if (is_array($when) && count($when) === 2) {
$when = [$when[0], null, $when[1]];
}

$this->args['case_when'][] = [$when, $then];

return $this;
Expand Down

0 comments on commit b5eeca9

Please sign in to comment.