web-base/Core/Driver/SQL/Condition/Compare.class.php

35 lines
955 B
PHP
Raw Normal View History

2020-04-02 00:02:51 +02:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\Driver\SQL\Condition;
2020-04-02 00:02:51 +02:00
use Core\Driver\SQL\SQL;
2020-04-02 00:02:51 +02:00
class Compare extends Condition {
2020-04-03 17:39:58 +02:00
private string $operator;
2021-04-08 19:48:04 +02:00
private string $column;
2020-04-03 17:39:58 +02:00
private $value;
2021-04-08 19:48:04 +02:00
public function __construct(string $col, $val, string $operator = '=') {
2020-04-02 00:02:51 +02:00
$this->operator = $operator;
2021-04-08 19:48:04 +02:00
$this->column = $col;
2020-04-02 00:02:51 +02:00
$this->value = $val;
}
2021-04-08 19:48:04 +02:00
public function getColumn(): string { return $this->column; }
2020-04-02 00:02:51 +02:00
public function getValue() { return $this->value; }
2021-04-02 21:58:06 +02:00
public function getOperator(): string { return $this->operator; }
2020-04-02 00:02:51 +02:00
function getExpression(SQL $sql, array &$params): string {
if ($this->value === null) {
if ($this->operator === "=") {
return $sql->columnName($this->column) . " IS NULL";
} else if ($this->operator === "!=") {
return $sql->columnName($this->column) . " IS NOT NULL";
}
}
return $sql->columnName($this->column) . $this->operator . $sql->addValue($this->value, $params);
}
2020-04-03 17:39:58 +02:00
}