Builds WHERE part of a query.

@param AnDomainQuery $query Query object
@param array         $where Where conditions

@return string
7777
protected function _buildWhere($query, $where)
    {
        $clause = '';

        if (isset($where['condition'])) {
            $clause .= ' '.$where['condition'];
        }

        //converts subclause to string only if there's at least one where statement in it
        if (isset($where['clause'])) {
            if (empty($where['clause'])) {
                return '';
            }

            $clause .= ' (';
            foreach ($where['clause'] as $subwhere) {
                $clause .= $this->_buildWhere($query, $subwhere);
            }
            $clause .= ' )';

            return $clause;
        }

        list($columns, $property) = array_values(AnDomainQueryHelper::parseColumn($query, $where['property']));

        $value = isset($where['value']) ?  $where['value'] : null;
        $where['property'] = pick($columns, $where['property']);

        if ($property && !$value instanceof AnDomainQuery) {
            $constraint = $where['constraint'];

            if (is_object($value) || is_array($columns)) {
                if ($value instanceof AnObjectSet || is_array($value)) {
                    $values = $value;
                    $keys = array();
                    $clauses = array();
                    foreach ($values as $value) {
                        $columns = $property->serialize($value);
                        foreach ($columns as $column => $value) {
                            $keys[$column][] = $value;
                        }
                    }

                    foreach ($keys as $key => $values) {
                        $clauses[] = $this->_buildWhere($query, array('property' => $key, 'constraint' => $constraint, 'value' => $values));
                    }

                    $clause .= ' ('.implode(' AND ', $clauses).')';

                    return $clause;
                } else {
                    $columns = $property->serialize($value);

                    $clauses = array();
                    foreach ($columns as $column => $value) {
                        $clauses[] = $this->_buildWhere($query, array('property' => $column, 'constraint' => $constraint, 'value' => $value));
                    }

                    $clause .= ' ('.implode(' AND ', $clauses).')';

                    return $clause;
                }
            }
        }

        $clause  .= ' '.$where['property'];

        if (isset($where['constraint'])) {
            $value = $this->_store->quoteValue($where['value']);

            if ($value === 'NULL') {
                //force correct constraint
                if (strpos($where['constraint'], 'IS') === false) {
                    if (strpos($where['constraint'], '<>') !== false) {
                        $where['constraint'] = ' IS NOT ';
                    } elseif (strpos($where['constraint'], '=') !== false) {
                        $where['constraint'] = ' IS ';
                    }
                }
            }

            if (in_array($where['constraint'], array('IN', 'NOT IN'))) {
                $value = ' ( '.$value.' ) ';
            }

            $clause .= ' '.$where['constraint'].' '.$value;
        }

        return $clause;
    }
56481
protected function whereCountQuery( QueryBuilder $query, $operator = '>=', $count = 1, $boolean = 'and' )
	{
		if ( is_numeric( $count ) )
		{
			$count = new Expression( $count );
		}

		$this->query->addBinding( $query->getBindings(), 'where' );

		return $this->where( new Expression( '(' . $query->toSql() . ')' ), $operator, $count, $boolean );
	}
1092597
protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
    {
        $initialQueryChunks = explode('where ', $query->toSql());

        if (count($initialQueryChunks) == 1) {
            throw new InvalidArgumentException(
                'The query builder instance must have a where clause to build a condition string from'
            );
        }

        $queryChunks = explode('?', $initialQueryChunks[1]);
        $chunkCount  = count($queryChunks);
        $bindings    = $query->getBindings();
        $whereString = '';

        for ($i = 0; $i < $chunkCount; $i++) {

            $whereString .= $queryChunks[ $i ];

            if (isset($bindings[ $i ])) {

                if (gettype($bindings[ $i ]) === 'string') {
                    $whereString .= '"' . $bindings[ $i ] . '"';
                }
            }
        }

        return $whereString;
    }
1016789
public function buildSelectString($whereCondition = null)
    {
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        $get = $this->getSelectFields();
        $query = "select $get from " . $this->getViewName() . ' where 1 ';

        if ($whereCondition) {
            reset($whereCondition);
            foreach ($whereCondition as $name => $value) {
                $query .= ' and ' . $name . ' = ' . $database->quote($value);
            }
        }

        return $query;
    }
816555
public function buildQuery(string $table, array $where): SqlParams
    {
        $whereClause = $this->buildWhereClause($where);
        $sql = "DELETE FROM {$table}" . $whereClause->getSql();
        return new SqlParams($sql, $whereClause->getParams());
    }
1345404
protected function whereJsonLength(Builder $query, $where)
    {
        return $this->compileJsonLength(
            $where['column'], $where['operator'], $this->parameter($where['value'])
        );
    }
100828
public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
    {
        if (self::isFilterRegex($data[0])) {
            $this->buildRegexSQL($data[0], array('value'), $joins, $where);
        } elseif (self::isFilterSQL($data[0])) {
            $this->buildFilterSQL($data[0], array('value'), $joins, $where);
        } else {
            $parsed = array();

            // For the filter provided, loop over each piece
            foreach ($data as $string) {
                $type = self::parseFilter($string);

                if ($type == self::ERROR) {
                    return false;
                }

                if (!is_array($parsed[$type])) {
                    $parsed[$type] = array();
                }

                $parsed[$type][] = $string;
            }

            foreach ($parsed as $value) {
                $this->buildRangeFilterSQL($value, $joins, $where, $andOperation);
            }
        }

        return true;
    }
1347458
public function buildWhereFragment(SQLConditionalExpression $query, array &$parameters)
    {
        // Get parameterised elements
        $where = $query->getWhereParameterised($whereParameters);
        if (empty($where)) {
            return '';
        }

        // Join conditions
        $connective = $query->getConnective();
        $parameters = array_merge($parameters, $whereParameters);
        $nl = $this->getSeparator();
        return "{$nl}WHERE (" . implode("){$nl}{$connective} (", $where) . ")";
    }
1024001
public function where($where, &$params)
    {
        if (!is_array($where)) {
            throw new \Exception("Invalid where clause specified, must be an array");
        }

        $params = Helper::toArray($params);

        $query = "";

        $andFlag = false;

        foreach ($where as $field => $value) {

            # Add the and flag if this isn't the first field
            if ($andFlag) {
                $query .= "AND ";
            } else {
                $andFlag = true;
            }

            # Add the field name to the query
            $query .= $this->quoteField($field);

            # Convert arrays to use the in helper
            if (is_array($value)) {
                $helperMap = [
                    "<"     =>  "lessThan",
                    "<="    =>  "lessThanOrEqualTo",
                    ">"     =>  "greaterThan",
                    ">="    =>  "greaterThanOrEqualTo",
                    "="     =>  "equals",
                    "<>"    =>  "notEqualTo",
                ];
                $clause = (string) reset($value);
                if (count($value) === 2 && isset($helperMap[$clause])) {
                    $method = $helperMap[$clause];
                    $val = next($value);
                    trigger_error("Using arrays for complex where clauses is deprecated in favour of the helper methods, eg Sql::" . $method . "(" . $val . ")", E_USER_DEPRECATED);
                    $value = static::$method($val);
                } else {
                    $value = static::in($value);
                }
            }

            # Any parameters not using a helper should use the standard equals helper
            if (!is_object($value)) {
                $value = static::equals($value);
            }

            $query .= " " . $value->getClause() . " ";
            foreach ($value->getValues() as $val) {
                $params[] = $val;
            }
        }

        return $query;
    }
881019
protected function whereNotInSub(Builder $query, $where)
    {
        return $this->wrap($where['column']).' not in ('.$this->compileSelect($where['query']).')';
    }
647871
protected function compileWheres(Builder $query)
    {
        $sql = array();

        if (is_null($query->wheres)) return '';

        foreach ($query->wheres as $where) {
            $method = "where{$where['type']}";

            $sql[] = $where['boolean'].' '.$this->$method($query, $where);
        }

        if (count($sql) > 0) {
            $sql = implode(' ', $sql);

            return 'where '.preg_replace('/and |or /', '', $sql, 1);
        }

        return '';
    }
403559
protected function whereNotIn(Builder $query, $where)
    {
        if (empty($where['values'])) {
            return '1 = 1';
        }

        $values = $this->parameterize($where['values']);

        return $this->wrap($where['column']).' not in ('.$values.')';
    }
293047
protected function compileUpdateWheres(Builder $query)
    {
        $baseWheres = $this->compileWheres($query);

        if (!isset($query->joins)) {
            return $baseWheres;
        }

        // Once we compile the join constraints, we will either use them as the where
        // clause or append them to the existing base where clauses. If we need to
        // strip the leading boolean we will do so when using as the only where.
        $joinWheres = $this->compileUpdateJoinWheres($query);

        if (trim($baseWheres) === '') {
            return 'where ' . $this->removeLeadingBoolean($joinWheres);
        }

        return $baseWheres . ' ' . $joinWheres;
    }
814862
protected function where(array $where): string
	{
		if(is_array($where['column']))
		{
			$column = '(' . $this->columns($where['column'], false) . ')';

			$value = is_array($where['value']) ? '(' . $this->params($where['value']) . ')' : $this->param($where['value']);

			return $column . ' ' . $where['operator'] . ' ' . $value;
		}

		return $this->column($where['column']) . ' ' . $where['operator'] . ' ' . $this->param($where['value']);
	}
240873
protected function formatWhere(array $where) : string {
    $where_clause = '';

    foreach ($where as $column => $value) {
      $logical_operator = null;

      if (is_numeric($column) && is_array($value)) {
        $where_clause .= "`{$value[0]}` {$value[1]} :where_{$value[0]}";
      } else if (is_numeric($column) && is_string($value)) {
        $logical_operator = $value;
      } else {
        $where_clause .= "`{$column}` = :where_{$column}";
      }

      $next_value = next($where);
      $next_key = key($where);

      if ( $next_value !== false && !is_null($next_key) && (!is_numeric($next_key) || !is_string($next_value)) )  {
        $logical_operator = $logical_operator ?? '&&';

        $where_clause .= " {$logical_operator} ";
      }
    }

    return $where_clause;
  }
159809
private function getSearchQueryWhere($query, $where)
	{
		foreach ($where as $key => $value) {
			$query->where($value[0], $value[1], $value[2]);
		}

		return $query;
	}
89149
protected function applyWhere(Builder $query, array $where)
    {
        foreach ($where as $key => $value) {
            if (is_null($value)) {
                $query = $query->whereNull($key);
            } else {
                if (is_array($value)) {
                    $query = $query->where($key, $value[0], $value[1]);
                } else {
                    $query = $query->where($key, '=', $value);
                }
            }
        }

        return $query;
    }