Builds the query.

@return string
512658
protected function build() : string {
    $table = $this->table;
    $mode = $this->mode;
    $columns = $this->columns;
    $where = $this->where;
    $values = $this->values;
    $data = $this->data;

    $query = '';

    switch ($mode) {
      case 'select':
        if (!empty($where)) {
          $query = "SELECT {$columns} FROM `{$table}` WHERE {$where}";
        } else {
          $query = "SELECT {$columns} FROM `{$table}`";
        }
        break;

      case 'insert':
        $query = "INSERT INTO `{$table}` ({$columns}) VALUES ({$values})";
        break;

      case 'update':
        if (!empty($where)) {
          $query = "UPDATE `{$table}` SET {$data} WHERE {$where}";
        } else {
          $query = "UPDATE `{$table}` SET {$data}";
        }
        break;

      case 'delete':
        if (!empty($where)) {
          $query = "DELETE FROM `{$table}` WHERE {$where}";
        } else {
          $query = "DELETE FROM `{$table}`";
        }
        break;
    }

    return $query;
  }
229260
public function getQuery()
    {
        if (is_null($this->query)) {
            $params = $this->getParameters();
            $params = array_map(array($this, 'htmlDecode'), $params);
            $params = array_map(array($this, 'encode'), $params);

            $this->setQuery(http_build_query($params, "", "&"));
        }

        return $this->query;
    }
1134590
protected function buildQuery()
    {
        // 合并数据库配置
        if (!empty($this->connection)) {
            if (is_array($this->connection)) {
                $connection = array_merge(Config::get('database'), $this->connection);
            } else {
                $connection = $this->connection;
            }

        } else {
            $connection = Config::get('database');
        }

        Db::import($connection)->connect();

        /**
         * @var Connect $con
         */
        $con = Db::getQueryObject();

        $queryClass = $con->getConfig('query');

        /**
         * @var Query $query
         */
        $query = Application::get($queryClass);

        // 设置当前数据表和模型名
        if (!empty($this->table)) {
            $query->table($this->table);
        } else {
            $query->table($this->name);
        }

        return $query;
    }
908332
public static function build_query_string()
	{
		$params = array();

		foreach (func_get_args() as $arg)
		{
			$arg = is_array($arg) ? $arg : array($arg => '1');

			$params = array_merge($params, $arg);
		}

		return http_build_query($params);
	}
135697
public function build(): string
    {
        if ($this->truncate === true) {
            return $this->getTruncateSql();
        }
        $sql = [];
        $sql = $this->getDeleteSql($sql);
        $sql = $this->condition->getWhereSql($sql);
        $sql = $this->getOrderBySql($sql);
        $sql = $this->getLimitSql($sql);
        $result = trim(implode(' ', $sql)) . ';';

        return $result;
    }
291158
public function toUrlQuery()
    {
        $queryData = array();
        foreach (self::$properties as $p => $setter) {
            if ($this->$p !== null) {
                $queryData[$p] = $this->$p;
            }
        }
        return http_build_query($queryData);
    }
648502
protected function _buildUpdate()
        {
            $query = [];
            $query[] = "UPDATE {$this->_quoteIdentifier($this->_table_name)} SET";

            $field_list = [];

            foreach ($this->_dirty_fields as $key => $value) {
                if(!Arrays::exists($key, $this->_expr_fields)) {
                    $value = '?';
                }

                $field_list[] = "{$this->_quoteIdentifier($key)} = $value";
            }

            $query[] = join(", ", $field_list);
            $this->_addIdColumnConditions($query);

            return join(" ", $query);
        }
358918
public function getSql()
    {
        if ($this->builtSql === null) {
            $this->builtSql = $this->buildSql();
        }

        return $this->builtSql;
    }
98763
public function getQuery()
    {
        $query = $this->database->getSelectQuery()->from($this->table);

        foreach ($this->join as $join) {
            if (!is_array($join[2])) {
                $join[2] = [$join[2]];
            }

            $where = array_shift($join[2]);
            if (!empty($join[2])) {
                foreach ($join[2] as $i => $value) {
                    $join[2][$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $join[2]);
            }

            $query->join($join[0], $join[1], $where, $join[3]);
        }

        foreach ($this->filter as $i => $filter) {
            //array('post_id=%s AND post_title IN %s', 123, array('asd'));
            $where = array_shift($filter);
            if (!empty($filter)) {
                foreach ($filter as $i => $value) {
                    $filter[$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $filter);
            }

            $query->where($where);
        }

        return $query;
    }
494879
public function getQuery()
	{
		if (!$this->query) {
			$this->query = new Query($this->driver, $this->preprocessor);
		}

		return $this->query;
	}
81685
public function build(&$query)
    {
        $segments = array();

        if (isset($query['oid'])) {
            $segments[] = '@'.$query['oid'];
        }

        if (isset($query['q'])) {
            $segments[] = $query['q'];
        }

        //we don't need the view
        unset($query['view']);
        unset($query['oid']);
        unset($query['q']);

        return $segments;
    }
697313
public function getQuery()
    {
        $sql = $this->setQuery;
        $sql .= $this->getWhere();
        $sql .= $this->getGroupBy();
        $sql .= $this->getOrderBy();
        $sql .= $this->getHaving();
        $sql .= $this->getLimit();

        $this->setQuery = null;
        $this->setWhere = null;
        $this->setHaving = null;
        $this->setOrderBy = null;
        $this->setGroupBy = null;
        $this->setLimit = null;

        return str_replace('  ', ' ', $sql);
    }
27702
public function getQuery()
    {

        $strings = $this->string;
        $query = $this->buildQuery($this->getPattern($this->getChieldPattern()), $strings);

        return $query;
    }
1123903
public function build(): string
    {
        $join = '';
        $filter = '';
        $order = '';
        $limit = '';
        
        // Biuld joins
        if ($this->join) {
            $tmp = [];
            
            foreach ($this->join as $def) {
                $tmp[] = ' ' . $def['by'] . ' JOIN ' . '{db_prefix}' . (isset($def['as']) ? $def['table'] . ' AS ' . $def['as'] : $def['join']) . ' ON (' . $def['cond'] . ')';
            }
        }
        
        $join = isset($tmp) ? implode(' ', $tmp) : '';
        
        // Add counter
        if ($this->counter) {
            
            $tmp = '(@' . $this->counter['name'] . ':=' . '@' . $this->counter['name'] . '+' . $this->counter['step'] . ') AS ' . $this->counter['as'];
            
            array_unshift($this->fields, $tmp);
        }
        
        $fieldlist = $this->buildFieldlist();
        
        // Create filterstatement
        $filter = $this->filter ? 'WHERE ' . $this->filter : '';
        
        // Create group by statement
        $group_by = '';
        
        if ($this->group_by) {
            
            if (is_array($this->group_by)) {
                $this->group_by = implode(', ', $this->group_by);
            }
            
            $group_by = 'GROUP BY ' . $this->group_by;
        }
        
        // Create having statement
        $having = $this->having ? 'HAVING ' . $this->having : '';
        
        // Create order statement
        $order = $this->order ? 'ORDER BY ' . $this->order : '';
        
        // Create limit statement
        if ($this->limit) {
            
            $limit = ' LIMIT ';
            
            if (isset($this->limit['lower'])) {
                $limit .= $this->limit['lower'];
            }
            
            if (isset($this->limit['lower']) && isset($this->limit['upper'])) {
                $limit .= ',' . $this->limit['upper'];
            }
        }
        
        // Get complete tablename with alias while respecting called mathod
        $table = $this->buildTableName();
        
        switch ($this->method) {
            
            case 'UPDATE':
                
                // we have to build our own fieldlist
                $fields = [];
                
                foreach ($this->fields as $field) {
                    $fields[] = $field . '=:' . $field;
                }
                
                $pieces = [
                    $this->method,
                    $table,
                    'SET',
                    implode(',', $fields),
                    $filter
                ];
                
                break;
            
            case 'INSERT':
            case 'REPLACE':
                
                // Build values
                $values = [];
                
                foreach ($this->fields as $field) {
                    $values[] = ':' . $field;
                }
                
                if (empty($values)) {
                    Throw new QueryBuilderException('No values for INSERT or REPLACE found.');
                }
                
                $pieces = [
                    $this->method . ' INTO',
                    $table,
                    empty($fieldlist) || $fieldlist == '*' ? '' : '(' . $fieldlist . ')',
                    'VALUES (' . implode(', ', $values) . ')'
                ];
                
                break;
            
            case 'DELETE':
                
                $pieces = [
                    $this->method,
                    'FROM ' . $table,
                    $filter,
                    $order,
                    $limit
                ];
                
                break;
            
            default:
                
                $pieces = [
                    $this->method,
                    $fieldlist,
                    'FROM ' . $table,
                    $join,
                    $filter,
                    $group_by,
                    $having,
                    $order,
                    $limit
                ];
                
                break;
        }
        
        array_walk_recursive($pieces, function (&$data, $index) {
            $data = trim($data);
        });
        
        // Build sql string from pieces
        $this->sql = trim(implode(' ', $pieces));
        
        // Finally cleanup parameters by removing parameter not needed in query and parse array parameter into sql
        // string.
        foreach ($this->params as $key => $val) {
            
            // Do cleanup
            if (strpos($this->sql, $key) === false) {
                unset($this->params[$key]);
                continue;
            }
            
            // Replace array parameter against sql valid part
            if (is_array($val)) {
                $prepared = $this->prepareArrayQuery($key, $val);
                
                array_push($this->params, $prepared['params']);
                
                $this->sql = str_replace('prep:' . $key, $prepared['sql'], $this->sql);
            }
        }
        
        return $this->sql;
    }
865326
public function toString()
	{
		// Build the actual query
		if (is_object($this->statement))
		{
			$query = $this->interpolate($this->statement->queryString, $this->bindings);
		}
		else
		{
			$query = $this->statement;
		}

		return $query;
	}
942386
public function build(): string
    {
        $sql = [];
        $sql = $this->getUpdateSql($sql);
        $sql = $this->getSetSql($sql);
        $sql = $this->condition->getWhereSql($sql);
        $sql = $this->getOrderBySql($sql);
        $sql = $this->getLimitSql($sql);
        $result = trim(implode(' ', $sql)) . ';';

        return $result;
    }
855190
public function buildQuery() 
    {
        $qb = $this->dataGrid->getQueryBuilder();

        if (!$qb instanceof QueryBuilder){
            throw new \InvalidArgumentException('Value must be instance of Doctrine\ORM\QueryBuilder.');
        }
        
        $options = $this->getOptions();
        
        // Is dependant grid ?
        if ($this->dataGrid->isDependentGrid()) {
            $qb->setParameter('masterGridRowId', $options['masterGridRowId']);
        }
        
        // Orders the records
        if ($options['orderBy']) {
            $qb->addOrderBy($options['orderBy'], $options['sort']);
        }
        
        // Applying search filters
        if ($options['search'] && !empty($options['filters'])) {
            $this->applyFilters($qb, $options['filters']);
        }
        
        // dispatch should onQueryBuilderReady event here
        
        if (!$this->dataGrid->isSortableEnabled() && $options['page'] && $options['records']){
            $qb->setMaxResults($options['records']);
            $qb->setFirstResult(($options['page'] - 1) * $options['records']);
        }

        $this->setQuery($qb->getQuery());
        
        // Getting count
        $paginator = new Paginator($this->getQuery());
        //$paginator->setUseOutputWalkers(false);
        $this->setCount($paginator->count());
        
        return $this;
    }