Builds condition string

@param string       $field
@param string|array $bind
@param string       $operator

@return string
8087
protected function buildConditionString($field, $bind, $operator)
    {
        if (is_array($bind)) {
            foreach ($bind as &$val) {
                $val = $this->buildConditionString($field, $val, $operator);
                unset($val);
            }

            $logical = $operator === '!=' ? ' and ' : ' or ';

            return '(' . implode($logical, $bind) . ')';
        }

        if ($bind === null) {
            return $field . ' ' . ($operator == '!=' ? 'IS NOT NULL' : 'IS NULL');
        }

        if ($operator === 'regexp') {
            return sprintf('%s regexp %s', $field, $bind);
        }

        return $field . ' ' . $operator . ' ' . $bind;
    }
197807
public function update($table, $fieldValues, $conditions, $bind = [])
    {
        if (!$fieldValues) {
            throw new InvalidArgumentException(['Unable to update :table table without data', 'table' => $table]);
        }

        if (is_string($conditions)) {
            $conditions = [$conditions];
        }

        $wheres = [];

        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
            } else {
                $wheres[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $setFields = [];
        foreach ($fieldValues as $k => $v) {
            if (is_int($k)) {
                $setFields[] = $v;
            } elseif ($v instanceof AssignmentInterface) {
                $v->setFieldName($k);
                $setFields[] = $v->getSql();
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $bind = array_merge($bind, $v->getBind());
            } else {
                $setFields[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $sql = 'UPDATE ' . $this->_escapeIdentifier($table) . ' SET ' . implode(',', $setFields) . ' WHERE ' . implode(' AND ', $wheres);

        return $this->_execute('update', $sql, $bind);
    }
548122
public function buildAndCondition($operator, $operands)
    {
        $operator = $this->normalizeConditionKeyword($operator);
        $parts = [];
        foreach ($operands as $operand) {
            $parts[] = $this->buildCondition($operand);
        }

        return [$operator => $parts];
    }
362713
protected function select(array $fields, array $criteria = array(), array $operators = array(), array $conditions = array())
    {
        $sql = "";
        $stringConditions = array();
        
        if ((!empty($criteria) && !empty($operators)) && !empty($conditions)) {
            if ((count($criteria) == count($operators) && (count($criteria) - 1) == count($conditions)) 
                && ((count($operators) -1) != count($conditions) && count($criteria) > 1)) {
                throw new \Exception("The number of Criteria, Operators and Conditions are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            $stringConditions[] = "$criteriaFields[0] $operators[0] ?";
            
            for ($i = 1; $i < count($criteriaFields); $i++) {
                $j = $i - 1;
                $stringConditions[] = "$conditions[$j] $criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' ', $stringConditions);
        } elseif ((!empty($criteria) && !empty($operators)) && count($criteria) > 1) {
            if (count($criteria) != count($operators)) {
                throw new \Exception("The number of Criteria and Operators are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            for ($i = 0; $i < count($criteriaFields); $i++) {
                $stringConditions[] = "$criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($criteria)) {
            foreach ($criteria as $field => $value) {
                $stringConditions[] = "$field = ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($fields)) {
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table";
        }
        
        $pdos = $this->_pdo->prepare($sql);
        $pdos->execute(array_values($criteria));
        
        return $pdos->fetchAll();
    }
214309
private function generateJoinCondition($field)
    {
        if (!array_key_exists($field, $this->joinConditions)) {
            return '';
        }

        // ON {joinConditino}
        $format = ' WITH %s';

        return sprintf($format, $this->joinConditions[$field]);
    }
1143869
protected function buildCondition($event) {
        $conditions = array();
        foreach ($event->getKeyCodes() as $code) {
            $conditions[$code] = 'Event.KeyCode == ' . $code;
        }

        $result = '';
        if (!empty($conditions)) {
            $result = implode(' || ', $conditions);
        }
        return $result;
    }
705011
private String buildCondition(LogicalOperator logicalOperator, Condition... conditions) {
		if (ArrayUtil.isEmpty(conditions)) {
			return StrUtil.EMPTY;
		}
		if (null == logicalOperator) {
			logicalOperator = LogicalOperator.AND;
		}

		final StringBuilder conditionStrBuilder = new StringBuilder();
		boolean isFirst = true;
		for (Condition condition : conditions) {
			// 添加逻辑运算符
			if (isFirst) {
				isFirst = false;
			} else {
				// " AND " 或者 " OR "
				conditionStrBuilder.append(StrUtil.SPACE).append(logicalOperator).append(StrUtil.SPACE);
			}

			// 构建条件部分："name = ?"、"name IN (?,?,?)"、"name BETWEEN ？AND ？"、"name LIKE ?"
			conditionStrBuilder.append(condition.toString(this.paramValues));
		}

		return conditionStrBuilder.toString();
	}
172767
private function prepareOperator(?string $operator, $value): string
    {
        $operator = strtoupper($operator);

        if (!$operator) {
            $operator = is_array($value) ? 'IN' : '=';
        }

        if ($operator === 'IN' and !is_array($value)) {
            $operator = '=';
        }

        if ($operator !== 'IN' and is_array($value)) {
            throw new SqlException('Value could not be an array in condition for operator `' . $operator . '`.');
        }

        return $operator;
    }
1266896
public function setCondition($field_name, $value, $operation = '=')
    {
        $this->condition[$field_name] = [
            'value' => $value,
            'operation' => $operation
        ];

        return $this;
    }
1362674
public function where($column, $operator = '=', $value = false, $condition = 'AND')
    {
        $where = array();

        // Raw Query
        if ($column instanceof Raw) {
            $where['raw'] = true;
            $where['query'] = $column->getString();
            $where['condition'] = $condition;
            $where['operator'] = $operator;

            $this->queryCompiler->getQuery()->where($where);

            return $this;
        }

        $where['column'] = $column;
        $where['operator'] = $operator;
        $where['value'] = $this->quote($value);
        $where['condition'] = $condition;

        $this->queryCompiler->getQuery()->where($where);

        return $this;
    }
437050
public function getCondition(string $field, array $fieldConf): string
    {
        $type = strtolower($fieldConf['type']);
        $unsigned = $fieldConf['unsigned'];

        $integerCast = $this->getIntegerCast($unsigned);

        $condition = "(CASE $field WHEN NULL THEN NULL ELSE :$field END)";

        $typeToCast = [
            'date' => 'DATE',
            'datetime' => 'DATE',
            'time' => 'TIME',
            'smallint' => $integerCast,
            'integer' => $integerCast,
            'bigint' => $integerCast,
            'float' => 'DECIMAL',
            'decimal' => 'DECIMAL',
        ];

        // No cast required
        if (!array_key_exists($type, $typeToCast)) {
            return $condition;
        }

        return "CAST($condition AS {$typeToCast[$type]})";
    }
144131
public function condition($field, $value = NULL, $expressionOperator = NULL)
    {

        if (!isset($expressionOperator)) {
            if (is_array($value)) {
                $expressionOperator = 'IN';
            }
            else {
                $expressionOperator = '=';
            }
        }
        $this->conditions[] = array(
            'field' => $field,
            'value' => $value,
            'operator' => $expressionOperator,
        );
        return $this;
    }
907424
public function where($field, $condition = false, $operator = '=')
    {
        if (func_num_args() >= 2) {
            $this->where->addCondition($field, $condition, $operator);
        } else {
            $this->where->addCondition($field);
        }

        return $this;
    }
140689
static public function buildExpression($property, $operator, $parameter = null)
    {
        FilterOperator::isValid($operator, true);

        $expr = new Expr();
        switch (intval($operator)) {
            case FilterOperator::NOT_EQUAL:
                return $expr->neq($property, $parameter);
            case FilterOperator::LOWER_THAN:
                return $expr->lt($property, $parameter);
            case FilterOperator::LOWER_THAN_OR_EQUAL:
                return $expr->lte($property, $parameter);
            case FilterOperator::GREATER_THAN:
                return $expr->gt($property, $parameter);
            case FilterOperator::GREATER_THAN_OR_EQUAL:
                return $expr->gte($property, $parameter);
            case FilterOperator::IN:
                return $expr->in($property, $parameter);
            case FilterOperator::NOT_IN:
                return $expr->notIn($property, $parameter);
            case FilterOperator::MEMBER:
                return $expr->isMemberOf($parameter, $property);
            case FilterOperator::NOT_MEMBER:
                return $expr->not($expr->isMemberOf($parameter, $property));
            case FilterOperator::LIKE:
                return $expr->like($property, $parameter);
            case FilterOperator::NOT_LIKE:
                return $expr->notLike($property, $parameter);
            case FilterOperator::START_WITH:
                return $expr->like($property, $parameter);
            case FilterOperator::NOT_START_WITH:
                return $expr->notLike($property, $parameter);
            case FilterOperator::END_WITH:
                return $expr->like($property, $parameter);
            case FilterOperator::NOT_END_WITH:
                return $expr->notLike($property, $parameter);
            case FilterOperator::IS_NULL:
                return $expr->isNull($property);
            case FilterOperator::IS_NOT_NULL:
                return $expr->isNotNull($property);
            default:
                return $expr->eq($property, $parameter);
        }
    }
993472
public function where($val1, $val2 = null, string $operator = null, bool $bind = null, string $join = null){
		$operator = $operator !== null ? strtoupper(trim($operator)) : '=';
		$bind     = $bind ?? true;

		$join = strtoupper(trim($join));
		$join = in_array($join, $this->joinArgs, true) ? $join : 'AND';

		if(in_array($operator, $this->operators, true)){
			$where = [
				is_array($val1)
					? strtoupper($val1[1]).'('.$this->dialect->quote($val1[0]).')'
					: $this->dialect->quote($val1)
			];

			if(in_array($operator, ['IN', 'NOT IN', 'ANY', 'SOME',], true)){

				if(is_array($val2)){

					if($bind){
						$where[] = $operator.'('.implode(',', array_fill(0, count($val2), '?')).')';
						$this->bindValues = array_merge($this->bindValues, $val2);
					}
					else{
						$where[] = $operator.'('.implode(',', array_map([$this->db, 'escape'], $val2)).')'; // @todo: quote
					}

				}
				else if($val2 instanceof Statement){
					$where[] = $operator.'('.$val2->sql().')';
					$this->bindValues = array_merge($this->bindValues, $val2->bindValues());
				}

			}
//			else if(in_array($operator, ['BETWEEN', 'NOT BETWEEN'], true)){
				// @todo
//			}
			else{
				$where[] = $operator;

				if($val2 instanceof Statement){
					$where[] = '('.$val2->sql().')';
					$this->bindValues = array_merge($this->bindValues, $val2->bindValues());
				}
				elseif(is_null($val2)){
					$where[] = 'NULL';
				}
				elseif(is_bool($val2)){
					$where[] = $val2 ? 'TRUE' : 'FALSE';
				}
				elseif(in_array(strtolower($val2), ['null', 'false', 'true', 'unknown'], true)){
					$where[] = strtoupper($val2);
				}
				else {

					if($bind){
						$where[] = '?';
						$this->bindValues[] = $val2;
					}
					else{
						if(!empty($val2)){
							$where[] = $val2;
						}
					}

				}

			}

			$this->where[] = [
				'join' => $join,
				'stmt' => implode(' ', $where),
			];

		}

		return $this;
	}
1284054
public function orWhereRaw($field, $operator = null, $value = null)
    {
        return $this->where($field, $operator, $value, 'or', true);
    }
372492
public function computeCondition(string $field, string $operator, $value, string $table = null, bool $skipTablePrefix = false)
    {
        $operator = trim(strtolower($operator));
        $values = [];
        $pattern = '?';
        $addQuotes = false;

        if ($table) {
            Controller::loadDataContainer($table);

            $dca = &$GLOBALS['TL_DCA'][$table]['fields'][$field];

            if (isset($dca['sql']) && false !== stripos($dca['sql'], 'blob')) {
                $addQuotes = true;
            }
        }

        switch ($operator) {
            case static::OPERATOR_UNLIKE:
                if (\is_array($value)) {
                    foreach ($value as $val) {
                        $values[] = Controller::replaceInsertTags('%'.($addQuotes ? '"'.$val.'"' : $val).'%', false);
                    }

                    break;
                }
                $values[] = Controller::replaceInsertTags('%'.($addQuotes ? '"'.$value.'"' : $value).'%', false);

                break;

            case static::OPERATOR_EQUAL:
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_UNEQUAL:
            case '<>':
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_LOWER:
                $pattern = 'CAST(? AS DECIMAL)';
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_GREATER:
                $pattern = 'CAST(? AS DECIMAL)';
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_LOWER_EQUAL:
                $pattern = 'CAST(? AS DECIMAL)';
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_GREATER_EQUAL:
                $pattern = 'CAST(? AS DECIMAL)';
                $values[] = Controller::replaceInsertTags(\is_array($value) ? implode(' ', $value) : $value, false);

                break;

            case static::OPERATOR_IN:
                $value = array_filter(explode(',', Controller::replaceInsertTags($value, false)));

                // skip if empty to avoid sql error
                if (empty($value)) {
                    break;
                }

                $pattern = '('.implode(
                        ',',
                        array_map(
                            function ($val) {
                                return '"'.addslashes(trim($val)).'"';
                            },
                            $value
                        )
                    ).')';

                break;

            case static::OPERATOR_NOT_IN:
                $value = array_filter(explode(',', Controller::replaceInsertTags($value, false)));

                // skip if empty to avoid sql error
                if (empty($value)) {
                    break;
                }

                $pattern = '('.implode(
                        ',',
                        array_map(
                            function ($val) {
                                return '"'.addslashes(trim($val)).'"';
                            },
                            $value
                        )
                    ).')';

                break;

            case static::OPERATOR_IS_NULL:
            case static::OPERATOR_IS_NOT_NULL:
            case static::OPERATOR_IS_EMPTY:
            case static::OPERATOR_IS_NOT_EMPTY:
                $pattern = '';

                break;

            default:
                if (\is_array($value)) {
                    foreach ($value as $val) {
                        $values[] = Controller::replaceInsertTags('%'.($addQuotes ? '"'.$val.'"' : $val).'%', false);
                    }

                    break;
                }
                $values[] = Controller::replaceInsertTags('%'.($addQuotes ? '"'.$value.'"' : $value).'%', false);

                break;
        }

        $operator = $this->transformVerboseOperator($operator);

        $explodedField = explode('.', $field);

        // remove table if already added to field name
        if (\count($explodedField) > 1) {
            $field = end($explodedField);
        }

        return [(!$skipTablePrefix && $table ? $table.'.' : '')."$field $operator $pattern", $values];
    }