mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
ref
This commit is contained in:
@@ -96,18 +96,27 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
|
||||
protected const EXISTS_OPERATOR = 'EXISTS';
|
||||
|
||||
/** @var string[] */
|
||||
private array $comparisonOperators = [
|
||||
'!=s',
|
||||
'=s',
|
||||
'!=',
|
||||
'!*',
|
||||
'*',
|
||||
'>=',
|
||||
'<=',
|
||||
'>',
|
||||
'<',
|
||||
'=',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected array $comparisonOperators = [
|
||||
protected array $comparisonOperatorMap = [
|
||||
'!=s' => 'NOT IN',
|
||||
'=s' => 'IN',
|
||||
'!=' => '<>',
|
||||
'!*' => 'NOT LIKE',
|
||||
'*' => 'LIKE',
|
||||
'>=' => '>=',
|
||||
'<=' => '<=',
|
||||
'>' => '>',
|
||||
'<' => '<',
|
||||
'=' => '=',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
@@ -2350,6 +2359,30 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
return implode(" " . $sqlOp . " ", $wherePartList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{string, string, string}
|
||||
*/
|
||||
private function splitWhereLeftItem(string $item): array
|
||||
{
|
||||
if (preg_match('/^[a-z0-9]+$/i', $item)) {
|
||||
return [$item, '=', '='];
|
||||
}
|
||||
|
||||
foreach ($this->comparisonOperators as $operator) {
|
||||
$sqlOperator = $this->comparisonOperatorMap[$operator] ?? $operator;
|
||||
|
||||
if (!str_ends_with($item, $operator)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$expression = trim(substr($item, 0, -strlen($operator)));
|
||||
|
||||
return [$expression, $sqlOperator, $operator];
|
||||
}
|
||||
|
||||
return [$item, '=', '='];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
@@ -2410,21 +2443,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
$isNotValue = true;
|
||||
}
|
||||
|
||||
$operator = '=';
|
||||
$operatorOrm = '=';
|
||||
|
||||
if (!preg_match('/^[a-z0-9]+$/i', $field)) {
|
||||
foreach ($this->comparisonOperators as $op => $opDb) {
|
||||
if (str_ends_with($field, $op)) {
|
||||
$field = trim(substr($field, 0, -strlen($op)));
|
||||
|
||||
$operatorOrm = $op;
|
||||
$operator = $opDb;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
[$field, $operator, $operatorOrm] = $this->splitWhereLeftItem($field);
|
||||
|
||||
$leftPart = null;
|
||||
|
||||
@@ -2946,8 +2965,6 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
return $sql;
|
||||
}
|
||||
|
||||
$operator = '=';
|
||||
|
||||
$isNotValue = false;
|
||||
$isComplex = false;
|
||||
|
||||
@@ -2956,16 +2973,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
$isNotValue = true;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-z0-9]+$/i', $left)) {
|
||||
foreach ($this->comparisonOperators as $op => $opDb) {
|
||||
if (str_ends_with($left, $op)) {
|
||||
$left = trim(substr($left, 0, -strlen($op)));
|
||||
$operator = $opDb;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
[$left, $operator] = $this->splitWhereLeftItem($left);
|
||||
|
||||
if (Util::isComplexExpression($left)) {
|
||||
$isComplex = true;
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
|
||||
namespace Espo\ORM\QueryComposer;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class Functions
|
||||
{
|
||||
public const FUNCTION_LIST = [
|
||||
|
||||
@@ -49,17 +49,12 @@ class PostgresqlQueryComposer extends BaseQueryComposer
|
||||
protected int $aliasMaxLength = 128;
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected array $comparisonOperators = [
|
||||
protected array $comparisonOperatorMap = [
|
||||
'!=s' => 'NOT IN',
|
||||
'=s' => 'IN',
|
||||
'!=' => '<>',
|
||||
'!*' => 'NOT ILIKE',
|
||||
'*' => 'ILIKE',
|
||||
'>=' => '>=',
|
||||
'<=' => '<=',
|
||||
'>' => '>',
|
||||
'<' => '<',
|
||||
'=' => '=',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
|
||||
Reference in New Issue
Block a user