Removed timezone + API improvements
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
use Driver\SQL\Column\Column;
|
||||
|
||||
class CondIn extends Condition {
|
||||
|
||||
private string $column;
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class Regex extends Condition {
|
||||
abstract class CondKeyword extends Condition {
|
||||
|
||||
private $leftExpression;
|
||||
private $rightExpression;
|
||||
private string $keyword;
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
public function __construct($keyword, $leftExpression, $rightExpression) {
|
||||
$this->leftExpression = $leftExpression;
|
||||
$this->rightExpression = $rightExpression;
|
||||
$this->keyword = $keyword;
|
||||
}
|
||||
|
||||
public function getLeftExp() { return $this->leftExpression; }
|
||||
public function getRightExp() { return $this->rightExpression; }
|
||||
public function getKeyword() { return $this->keyword; }
|
||||
}
|
||||
10
core/Driver/SQL/Condition/CondLike.class.php
Normal file
10
core/Driver/SQL/Condition/CondLike.class.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class CondLike extends CondKeyword {
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
parent::__construct("LIKE", $leftExpression, $rightExpression);
|
||||
}
|
||||
}
|
||||
11
core/Driver/SQL/Condition/CondRegex.class.php
Normal file
11
core/Driver/SQL/Condition/CondRegex.class.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class CondRegex extends CondKeyword {
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
parent::__construct("REGEXP", $leftExpression, $rightExpression);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use \Driver\SQL\Column\DateTimeColumn;
|
||||
use Driver\SQL\Column\BoolColumn;
|
||||
use Driver\SQL\Column\JsonColumn;
|
||||
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Expression\Add;
|
||||
use Driver\SQL\Strategy\Strategy;
|
||||
use \Driver\SQL\Strategy\UpdateStrategy;
|
||||
@@ -304,16 +304,4 @@ class MySQL extends SQL {
|
||||
public function getStatus() {
|
||||
return mysqli_stat($this->connection);
|
||||
}
|
||||
|
||||
protected function buildCondition($condition, &$params) {
|
||||
if($condition instanceof Regex) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
$right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params);
|
||||
return $left . " REGEXP " . $right;
|
||||
} else {
|
||||
return parent::buildCondition($condition, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use \Driver\SQL\Column\DateTimeColumn;
|
||||
use Driver\SQL\Column\BoolColumn;
|
||||
use Driver\SQL\Column\JsonColumn;
|
||||
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Expression\Add;
|
||||
use Driver\SQL\Strategy\Strategy;
|
||||
use Driver\SQL\Strategy\UpdateStrategy;
|
||||
@@ -304,7 +304,7 @@ class PostgreSQL extends SQL {
|
||||
}
|
||||
|
||||
protected function buildCondition($condition, &$params) {
|
||||
if($condition instanceof Regex) {
|
||||
if($condition instanceof CondRegex) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
|
||||
@@ -6,8 +6,9 @@ use Driver\SQL\Column\Column;
|
||||
use Driver\SQL\Condition\Compare;
|
||||
use Driver\SQL\Condition\CondBool;
|
||||
use Driver\SQL\Condition\CondIn;
|
||||
use Driver\SQL\Condition\CondKeyword;
|
||||
use Driver\SQL\Condition\CondOr;
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Constraint\Constraint;
|
||||
use \Driver\SQL\Constraint\Unique;
|
||||
use \Driver\SQL\Constraint\PrimaryKey;
|
||||
@@ -343,6 +344,13 @@ abstract class SQL {
|
||||
|
||||
$values = implode(",", $values);
|
||||
return $this->columnName($condition->getColumn()) . " IN ($values)";
|
||||
} else if($condition instanceof CondKeyword) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$keyword = $condition->getKeyword();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
$right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params);
|
||||
return "$left $keyword $right ";
|
||||
} else {
|
||||
$this->lastError = "Unsupported condition type: " . get_class($condition);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user