public SelectQuery build()
180169
@Override
  public SelectQueryBase build()
  {
    TableKraken table = _tableManager.getTable(_tableName);
    
    if (table == null) {
      table = _tableManager.loadTable(_tableName);
    }
    
    return build(table);
  }
466649
protected function buildQueryString() {

		$w = [];
		$s = [];

		$qc = $this->quoteChar;

		// start SQL statement

		$this->sql = 'SELECT ';

		// add columns

		if(!$this->columns || !count($this->columns)) {
			$this->sql .= '*';
		}
		else {
			
			$this->sql .= $qc . str_replace('.', $qc . '.' . $qc, implode($qc . ',' . $qc, $this->columns)) . $qc;
				
		}

		// add table

		$this->sql .= ' FROM ' . $qc . preg_replace('/\s+/', $qc . ' ' . $qc, $this->table) . $qc;

		// add alias

		if($this->alias) {
			$this->sql .= ' ' . $qc . $this->alias . $qc;
		}

		// add INNER JOINs

		foreach($this->innerJoins as $join) {
			$this->sql .= sprintf(' INNER JOIN %1$s%2$s%1$s ON %3$s', $qc, preg_replace('/\s+/', $qc . ' ' . $qc, trim($join->table)), $join->on);
		}

		// build WHERE clause

		foreach($this->whereClauses as $where) {

			// complete condition when no operator set

			if(!$where->operator) {
				$w[] = $where->conditionOrColumn;
			}

			// otherwise parse operator

			else {
				if($where->operator === 'IN') {
					$w[] = sprintf(
						'%1$s%2$s%1$s IN (%3$s)',
						$qc,
						str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn),
						implode(', ', array_fill(0, count($where->value), '?'))
					);
				}
				else {
					$w[] = sprintf(
						'%1$s%2$s%1$s %3$s ?',
						$qc,
						str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn),
						$where->operator
					);
				}
			}
		}

		// build SORT clause

		foreach($this->columnSorts as $sort) {
			$s[] = $sort->column . ($sort->asc ? '' : ' DESC');
		}

		if(count($w)) {
			$this->sql .= ' WHERE (' . implode(') AND (', $w) .')';
		}
		if(count($s)) {
			$this->sql .= ' ORDER BY ' . implode(', ', $s);
		}

	}
618059
public function buildSelect($columns, &$params, $distinct = false, $selectOption = null, $query)
    {
        $select = $distinct ? 'SELECT DISTINCT' : 'SELECT';

        if ($selectOption !== null) {
            $select .= ' ' . $selectOption;
        }

        if (empty($columns)) {
            return $select . ' *';
        }

        $columns = is_array($columns) ? $columns : [$columns];

        foreach ($columns as $i => $column) {
            if ($column instanceof Expression) {
                if (is_int($i)) {
                    $columns[$i] = $column->expression;
                }
                else {
                    $columns[$i] = $column->expression . ' AS ' . $this->db->quoteColumnName($i);
                }

                $params = array_merge($params, $column->params);
            }
            elseif ($column instanceof Query) {
                list($sql, $params) = $this->build($column, $params);

                $columns[$i] = "($sql) AS " . $this->db->quoteColumnName($i);
            }
            elseif (is_string($i)) {
                if (strpos($column, '(') === false) {
                    $column = $this->db->quoteColumnName($column);
                }

                $columns[$i] = "$column AS " . $this->db->quoteColumnName($i);
            }
            elseif (strpos($column, '(') === false) {
                if (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $column, $matches)) {
                    $columns[$i] = $this->db->quoteColumnName($matches[1]) . ' AS ' . $this->db->quoteColumnName($matches[2]);
                }
                else {
                    $columns[$i] = $this->db->quoteColumnName($column);
                }
            }
        }

        return $select . ' ' . implode(', ', $columns);
    }
518022
public function &buildColumnList()
    {

        $str = "";
        $ct = 0;

        // Build Select Column List
        foreach ($this->columns as $k => $col) {
            if ($col->in_select) {
                if ($ct > 0) {
                    $str .= ",";
                }

                $str .= " ";

                if ($col->table_name) {
                    $str .= $col->table_name . ".";
                }

                $str .= $col->column_name;

                if (($col->query_name)) {
                    $str .= " " . $col->query_name;
                }

                $ct++;
            }
        }
        //die;
        return $str;
    }
793436
public function build()
    {
        $sql = [
            $this->select->build(),
            $this->from->build(),
            $this->where->build(),
            $this->groupBy->build(),
            $this->having->build(),
            $this->orderBy->build(),
            $this->limit->build(),
            $this->union->build(),
        ];

        $this->values = array_merge(
            $this->where->getValues(),
            $this->having->getValues(),
            $this->union->getValues());

        $sql = implode(' ', array_filter($sql));

        // when there is no select statement then the query
        // is probably just a where subquery, thus does
        // not need to be prefixed with WHERE
        if ('WHERE ' === substr($sql, 0, 6)) {
            return substr($sql, 6);
        }

        return $sql;
    }
232505
StructuredQuery.Builder buildQuery() {
    StructuredQuery.Builder structuredQuery = StructuredQuery.newBuilder();
    structuredQuery.addFrom(
        StructuredQuery.CollectionSelector.newBuilder().setCollectionId(path.getId()));

    if (options.fieldFilters.size() == 1) {
      Filter filter = options.fieldFilters.get(0).toProto();
      if (filter.hasFieldFilter()) {
        structuredQuery.getWhereBuilder().setFieldFilter(filter.getFieldFilter());
      } else {
        Preconditions.checkState(
            filter.hasUnaryFilter(), "Expected a UnaryFilter or a FieldFilter.");
        structuredQuery.getWhereBuilder().setUnaryFilter(filter.getUnaryFilter());
      }
    } else if (options.fieldFilters.size() > 1) {
      Filter.Builder filter = Filter.newBuilder();
      StructuredQuery.CompositeFilter.Builder compositeFilter =
          StructuredQuery.CompositeFilter.newBuilder();
      compositeFilter.setOp(CompositeFilter.Operator.AND);
      for (FieldFilter fieldFilter : options.fieldFilters) {
        compositeFilter.addFilters(fieldFilter.toProto());
      }
      filter.setCompositeFilter(compositeFilter.build());
      structuredQuery.setWhere(filter.build());
    }

    if (!options.fieldOrders.isEmpty()) {
      for (FieldOrder order : options.fieldOrders) {
        structuredQuery.addOrderBy(order.toProto());
      }
    }

    if (!options.fieldProjections.isEmpty()) {
      structuredQuery.getSelectBuilder().addAllFields(options.fieldProjections);
    }

    if (options.limit != -1) {
      structuredQuery.setLimit(Int32Value.newBuilder().setValue(options.limit));
    }

    if (options.offset != -1) {
      structuredQuery.setOffset(options.offset);
    }

    if (options.startCursor != null) {
      structuredQuery.setStartAt(options.startCursor);
    }

    if (options.endCursor != null) {
      structuredQuery.setEndAt(options.endCursor);
    }

    return structuredQuery;
  }
1015162
public String build() {
        for (Map.Entry<String, String> p : parameters.entrySet()) {
            builder.addQueryParameter(p.getKey(), p.getValue());
        }
        return builder.build().toString();
    }
324306
private function _buildQueryParams() {
		$query = [];

		$this->_where = is_array($this->_where) ? $this->_where : [];
		foreach ($this->_where as $key => $val) {
			$query[$key] = is_numeric($val) ? (int) $val : $val;
		}

		if(count($this->_select)) {
			$query[$this->selectFieldsKey] = implode(',', $this->_select);
		}
		if($this->_limit !== null) {
			$query[$this->limitKey] = $this->_limit;
		}
		if($this->_offset !== null) {
			$query[$this->offsetKey] = $this->_offset;
		}

		return $query;
	}
1093274
protected function buildSelectQuery(SQLSelect $query, array &$parameters)
    {
        $sql  = $this->buildSelectFragment($query, $parameters);
        $sql .= $this->buildFromFragment($query, $parameters);
        $sql .= $this->buildWhereFragment($query, $parameters);
        $sql .= $this->buildGroupByFragment($query, $parameters);
        $sql .= $this->buildHavingFragment($query, $parameters);
        $sql .= $this->buildOrderByFragment($query, $parameters);
        $sql .= $this->buildLimitFragment($query, $parameters);
        return $sql;
    }
290325
@Override
    public Search build() {
        return new Search(filter.stream().map(ConditionBuilder::build).collect(toList()),
                          query.stream().map(ConditionBuilder::build).collect(toList()),
                          sort.stream().map(SortFieldBuilder::build).collect(toList()),
                          paging == null ? null : IndexPagingState.fromByteBuffer(ByteBufferUtils.byteBuffer(paging)),
                          refresh);
    }
357104
public function union(SelectQuery $query): self
    {
        $this->union[] = ['', $query->build(false)];

        return $this;
    }
728593
public Query<T> build() {
    QueryBean<T> queryBean = new QueryBean<T>();
    queryBean.setStatement(genStatement());
    queryBean.setParams(getParams());
    if (null != limit) {
      queryBean.setLimit(new PageLimit(limit.getPageIndex(), limit.getPageSize()));
    }
    queryBean.setCountStatement(genCountStatement());
    queryBean.setCacheable(cacheable);
    queryBean.setLang(getLang());
    return queryBean;
  }
1047378
public static function select()
    {
        try {
            self::init();
            $columns = func_get_args();
            $query = 'SELECT ' . implode(', ', $columns) . ' FROM ' . self::$modelTable;
            return new QueryBuilder(self::$connect, $query);

        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }
150480
function buildQuery(query, builder = new Builder()) {
    for (let i = 0; i < query.length; i++) {
        const method = query[i]

        if (Array.isArray(method)) {
            builder.and(buildQuery(method, new NonCapture()))
            continue
        }

        if (!method instanceof Method) {
            // At this point, there should only be methods left, since all parameters are already taken care of.
            // If that's not the case, something didn't work out.
            throw new SyntaxException(`Unexpected statement: ${method}`)
        }

        const parameters = []
        // If there are parameters, walk through them and apply them if they don't start a new method.
        while (query[i + 1] && !(query[i + 1] instanceof Method)) {
            parameters.push(query[i + 1])

            // Since the parameters will be appended to the method object, they are already parsed and can be
            // removed from further parsing. Don't use unset to keep keys incrementing.
            query.splice(i + 1, 1)
        }

        try {
            // Now, append that method to the builder object.
            method.setParameters(parameters).callMethodOn(builder)
        } catch (e) {
            const lastIndex = parameters.length - 1
            if (Array.isArray(parameters[lastIndex])) {
                if (lastIndex !== 0) {
                    method.setParameters(parameters.slice(0, lastIndex))
                }
                method.callMethodOn(builder)
                builder.and(buildQuery(parameters[lastIndex], new NonCapture()))
            } else {
                throw new SyntaxException(`Invalid parameter given for ${method.origin}`)
            }
        }
    }

    return builder
}
671914
private void validateSelectQuery(final String selectQuery) {
        final SimpleDBParser parser = new SimpleDBParser(selectQuery);
        try {
            parser.selectQuery();
        } catch (Exception e) {
            throw new InvalidSimpleDBQueryException("The following query is an invalid SimpleDB query: " + selectQuery,
                    e);
        }
    }
169883
private void buildSelect(final StringBuilder selectBuilder, final List<Projection> projections) {
        selectBuilder.append("SELECT ");
        if (null == projections || projections.isEmpty()) {
            selectBuilder.append(" * ");

            return;
        }

        selectBuilder.append(projections.stream().map(Projection::getKey).collect(Collectors.joining(", ")));
    }
488888
String buildSelect(String htmlAttributes, SelectOptions options) {

        return buildSelect(htmlAttributes, options.getOptions(), options.getValues(), options.getSelectedIndex());
    }