Slice where conditions at the given offset and add them to the query as a nested condition.

@param  \Globalis\PuppetSkilled\Database\Query\Builder  $query
@param  array  $whereSlice
@return void
356144
protected function groupWhereSliceForScope(QueryBuilder $query, $whereSlice)
    {
        $whereBooleans = array_pluck($whereSlice, 'boolean');

        // Here we'll check if the given subset of where clauses contains any "or"
        // booleans and in this case create a nested where expression. That way
        // we don't add any unnecessary nesting thus keeping the query clean.
        if (in_array('or', $whereBooleans)) {
            $query->wheres[] = $this->createNestedWhere($whereSlice, $whereBooleans[0]);
        } else {
            $query->wheres = array_merge($query->wheres, $whereSlice);
        }
    }
161385
public function query(DataStructure\Query\Query $queries)
    {
        $logicFunc = 'andWhere';
        if ($queries instanceof DataStructure\OrQuery) {
            $logicFunc = 'orWhere';
        }

        foreach ($queries as $query) {

            if ($this->isExcludedProperty($query->getProperty())) {
                continue;
            }

            $value = $this->unlockSpecialProperty($query->getProperty(), $query->getValue());

            if ($query instanceof Expression\Equal) {

                $this->criteria->{$logicFunc}(Criteria::expr()->eq($query->getProperty(), $value));

            } elseif ($query instanceof Expression\NotEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->neq($query->getProperty(), $value));

            } elseif ($query instanceof Expression\GreaterThan) {

                $this->criteria->{$logicFunc}(Criteria::expr()->gt($query->getProperty(), $value));

            } elseif ($query instanceof Expression\GreaterThanEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->gte($query->getProperty(), $value));

            } elseif ($query instanceof Expression\LesserThan) {

                $this->criteria->{$logicFunc}(Criteria::expr()->lt($query->getProperty(), $value));

            } elseif ($query instanceof Expression\LesserThanEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->lte($query->getProperty(), $value));

            } elseif ($query instanceof Expression\In) {

                $this->criteria->{$logicFunc}(Criteria::expr()->in($query->getProperty(), $value));

            } elseif ($query instanceof Expression\NotIn) {

                $this->criteria->{$logicFunc}(Criteria::expr()->notIn($query->getProperty(), $query->getValue()));

            }

        }
    }
212049
protected function query($query, $where = null, $size = null, $offset = null)
    {
        $params = [];

        if (is_array($where)) {
            $conditions = [];
            foreach($where as $column => $value) {
                $placeholder = '?';
                $value = '' . $value;

                $conditions[] = $column . ' = ' . $placeholder;
                $params[] = $value;
            }
            if (count($conditions)) {
                $query .= ' WHERE ' . implode(' AND ', $conditions);
            }
        }

        if (!is_null($size)) {
            $query = $this->getPersistence()->getPlatForm()->limitStatement($query, $size, $offset);
        }

        return $this->getPersistence()->query($query, $params);
    }
1026263
protected function whereJsonBoolean(Builder $query, $where)
    {
        $column = $this->wrapJsonBooleanSelector($where['column']);

        $value = $this->wrapJsonBooleanValue(
            $this->parameter($where['value'])
        );

        return $column.' '.$where['operator'].' '.$value;
    }
339932
public function where($where,$parse=null){
        if(!is_null($parse) && is_string($where)) {
            if(!is_array($parse)) {
                $parse = func_get_args();
                array_shift($parse);
            }
            $parse = array_map(array($this->db,'escapeString'),$parse);
            $where =   vsprintf($where,$parse);
        }elseif(is_object($where)){
            $where  =   get_object_vars($where);
        }
        if(is_string($where) && '' != $where){
            $map    =   array();
            $map['_string']   =   $where;
            $where  =   $map;
        }        
        if(isset($this->options['where'])){
            $this->options['where'] =   array_merge($this->options['where'],$where);
        }else{
            $this->options['where'] =   $where;
        }
        
        return $this;
    }
1173087
private void setWhere(Where where) throws SqlParseException {
        if (where != null) {
            QueryBuilder whereQuery = QueryMaker.explan(where,this.select.isQuery);
            request.setQuery(whereQuery);
        }
    }
1058953
public function compileWheres(Query $query)
	{
		$wheres = $query->wheres;

		$sql = [];

		foreach ($wheres as $where)
		{
			if ($where instanceof Expression)
			{
				switch ($where->type)
				{
					case 'raw':

						$sql[] = $this->compileRawWhere($where);

						break;

					case 'disjunct':
						
						$sql[] = $this->compileBasicWhere($where);

						break;

					case 'builder':

						$query = Query::$self->newQuery();

						call_user_func($where->clause, $query);

						$sql[] = '(' . substr($this->compileWheres($query), 6) . ')';

						break;
					
					default:
						# code...
						break;
				}
			}
			elseif (($operator = $where) instanceof Operator)
			{
				$sql[] = $operator->getType();
			}
		}

		return 'WHERE ' . implode(' ', $sql);
	}
1303004
protected function addConditions($query, $conditions)
    {
        foreach ($conditions as $key => $value) {
            if ($value instanceof Closure) {
                $query->where(function ($query) use ($value) {
                    $value($query);
                });
            } else {
                $this->addWhere($query, $key, $value);
            }
        }

        return $query;
    }
699689
public function compile_where( &$query )
	{
		$build = '';

		foreach( $query->wheres as $where ) 
		{
			// to make nested wheres possible you can pass an closure 
			// wich will create a new query where you can add your nested wheres
			if ( !isset( $where[2] ) && is_closure( $where[1] ) )
			{
				$sub_query = new Query;

				call_user_func( $where[1], $sub_query );

				// The parameters get added by the call of compile where
				$build .= ' '.$where[0].' ( '.substr( $this->compile_where( $sub_query ), 7 ).' )';

				continue;
			}

			// when we have an array as where values we have 
			// to parameterize them
			if ( is_array( $where[3] ) ) 
			{
				$where[3] = '('.$this->parameterize( $where[3] ).')';
			}
			else
			{
				$where[3] = $this->param( $where[3] );
			}

			// we always need to escepe where 1 wich referrs to the key
			$where[1] = $this->escape( $where[1] );

			// implode the beauty
			$build .= ' '.implode( ' ', $where );
		}

		return $build;
	}
1172785
public static function query($query)
    {
        //
        static::applySchema();

        //
        $table = self::getTable();
        $whereArray = [];

        //
        if (isset($query['where'])) {
            $whereArray[] = '('.$query['where'].')';
            unset($query['where']);
        }

        //
        foreach ($query as $field => $value) {
            if (in_array($field, ['order', 'limit'])) {
                continue;
            }
            $whereArray[] = "{$field} = '{$value}'";
        }

        //
        $where = count($whereArray) > 0 ? 'WHERE '.implode(' AND ', $whereArray) : '';
        $order = isset($query['order']) ? 'ORDER BY '.$query['order'] : '';
        $limit = isset($query['limit']) ? 'LIMIT '.$query['limit'] : '';
        $sql = "SELECT * FROM {$table} {$where} {$order} {$limit}";
        $results = static::getDatabase()->getResults($sql);

        //
        foreach ($results as &$record) {
            $record = static::create($record);
        }

        return $results;
    }
983998
public function whereRaw($where, $bind = [], $logic = 'AND')
    {
        if ($bind) {
            $this->bindParams($where, $bind);
        }

        $this->options['where'][$logic][] = $this->raw($where);

        return $this;
    }
1122035
private function build_conditions( $where, $columns, $glue = 'AND' ) {
		list ( $_where, $_where_format ) = $this->filter( $where, $columns );
		$conditions = $values = [];
		$index      = 0;
		foreach ( $_where as $field => $value ) {
			$field  = trim( $field );
			$format = $_where_format[ $index ++ ];
			if ( is_null( $value ) ) {
				$conditions[] = "$field IS NULL";
				continue;
			}

			if ( in_array( strtoupper( $field ), [
				'EXISTS',
				'NOT EXISTS',
			] ) ) {
				! is_array( $value ) and $value = [ $value ];
				foreach ( $value as $sub_query ) {
					$conditions[] = "$field ($sub_query)";
				}
				continue;
			}

			$op = '=';
			if ( is_array( $value ) ) {
				if ( count( $value ) > 1 ) {
					$op  = trim( $value[0] );
					$val = $value[1];
					if ( in_array( strtoupper( $op ), [
						'OR',
						'AND',
					] ) ) {
						array_shift( $value );
						$_conditions = [];
						foreach ( $value as $v ) {
							if ( ! is_array( $v ) ) {
								$_conditions[] = "1=0";
								continue;
							}
							list( $c, $v ) = $this->build_conditions( $v, $columns );
							$values        = array_merge( $values, $v );
							$_conditions[] = "({$c})";
						}
						$conditions[] = implode( " {$op} ", $_conditions );

						continue;
					}
					if ( is_array( $val ) ) {
						if ( empty( $val ) ) {
							$conditions[] = "1=0";
						} else {
							foreach ( $val as $v ) {
								$values[] = $v;
							}
							$conditions[] = "$field $op (" . str_repeat( $format . ',', count( $val ) - 1 ) . $format . ')';
						}
						continue;
					}
					if ( count( $value ) > 2 ) {
						$val          = $this->get_field_name( $val, $columns );
						$conditions[] = "$field $op $val";
						continue;
					}
				} else {
					$value        = reset( $value );
					$conditions[] = "$field ($value)";
					continue;
				}
			} else {
				$val = $value;
			}

			$conditions[] = "$field $op $format";
			$values[]     = $val;
		}
		$conditions = implode( " {$glue} ", $conditions );

		return [ $conditions, $values ];
	}
650735
public function where($query)
    {
        $clauses = $this->_where($query);

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

        if (!empty($clause)) {
            $clause = 'WHERE '.$clause;
        }

        return $clause;
    }
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.')';
    }
1258707
protected function nestWheresForScope( QueryBuilder $query, $originalWhereCount )
	{
		// Here, we totally remove all of the where clauses since we are going to
		// rebuild them as nested queries by slicing the groups of wheres into
		// their own sections. This is to prevent any confusing logic order.
		$allWheres = $query->wheres;

		$query->wheres = [];

		$this->addNestedWhereSlice( $query, $allWheres, 0, $originalWhereCount );

		$this->addNestedWhereSlice( $query, $allWheres, $originalWhereCount );
	}
823444
protected function _where($query)
    {
        $link = null;
        $type_check = true;

        if ($query instanceof AnConfig) {
            $type_check = false;
            $query = $query->query;
        }

        $description = $query->getRepository()->getDescription();
        $clauses = array();
        if ($description->getInheritanceColumn() && $type_check) {
            $resource = $description->getInheritanceColumn()->resource->getAlias();
            //the table type column name
            $type_column_name = $resource.'.'.$description->getInheritanceColumn()->name;

            $scopes = AnConfig::unbox($query->instance_of);
            if (empty($scopes)) {
                $scopes = array($description);
            } else {
                if (!is_array($scopes)) {
                    $scopes = array($scopes);
                }
            }

            foreach ($scopes as $index => $scope) {
                $inheritance_type = $this->_inheritanceTree($scope);
                if (!empty($inheritance_type) && $inheritance_type != '%') {
                    $operator = substr($inheritance_type, -1) == '%' ? 'LIKE' : '=';
                    $scopes[$index] = $type_column_name.' '.$operator.' \''.$inheritance_type.'\'';
                } else {
                    unset($scopes[$index]);
                }
            }
            if (!empty($scopes)) {
                $clauses[] = '('.implode(' OR ', $scopes).')';
            }
        }

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

        foreach ($query->link as $link) {
            $clauses = array_merge($clauses, $this->_where($link));
        }

        return $clauses;
    }
399146
public static function q_check(string $table, string $where = ''): bool
    {
        return (bool)self::getInstance()->sql_query('SELECT NULL FROM `' . $table . '`' . ($where ? ' WHERE ' . $where : '') . ' LIMIT 1')->rowCount();
    }