Generate a "select" query

@param boolean $all [optional]
@return string
9782
public function getSelectSQL($all = false)
        {
            if (!$this->query->getTable() instanceof Table) {
                throw new Exception('Trying to generate sql when no table is being used.');
            }
            $sql = $this->generateSelectSQL();
            $sql .= $this->generateJoinSQL();
            if (!$all) {
                $sql .= $this->generateWhereSQL();
            }

            return $sql;
        }
1310713
public function queryAll($params = array())
    {
        $this->mergeParams($params);
        $this->beginQuery();
        $rst = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
        $this->statement->closeCursor();
        return $rst;
    }
9447
public function selectQuery($fields = null)
    {
        /**/$this->app->pr->start('selectQuery/getActualF');

        $actual_fields = $fields ?: $this->getActualFields();

        if ($this->fast && $this->_selectQuery) {
            return $this->_selectQuery();
        }

        $this->_selectQuery = $select = $this->_dsql()->del('fields');

        /**/$this->app->pr->next('selectQuery/addSystemFields');
        // add system fields into select
        foreach ($this->elements as $el) {
            if ($el instanceof Field) {
                if ($el->system() && !in_array($el->short_name, $actual_fields)) {
                    $actual_fields[] = $el->short_name;
                }
            }
        }
        /**/$this->app->pr->next('selectQuery/updateQuery');

        // add actual fields
        foreach ($actual_fields as $field) {
            /** @type Field $field */
            $field = $this->hasElement($field);
            if (!$field) {
                continue;
            }

            $field->updateSelectQuery($select);
        }
        /**/$this->app->pr->stop();

        return $select;
    }
934988
protected function getCountQuery(): Select
    {
        if ($this->countQuery instanceof Select) {
            return $this->countQuery;
        }

        if ($this->searchTerm !== null && $this->searchFields === null) {
            $fields = $this->getFields();
            $searchFields = [];
            foreach ($fields as $field) {
                $searchFields[] = $field['name'];
            }
        } else {
            $searchFields = null;
        }

        $query = clone $this;
        $query->resetFields();
        $query->resetLimit();
        $query->resetOrderBy();
        $query->field('COUNT(*)', 'total');

        if ($this->resetGroupBy) {
            $query->resetGroupBy();
        }

        if ($searchFields !== null) {
            $query->setSearchFields($searchFields);
        }

        return $query;
    }
660928
public function select(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [], Bool $multiple = false)
    {
        $this->isTableOrQueryData($options);

        $this->setOptionAttribute($options);

        $this->isExcludeAttribute($options);

        $this->isIncludeAttribute($options);

        $this->isOrderAttribute($options);

        $this->setSelectedAttribute($selected, $options);

        $this->setMultipleAttribute($multiple, $_attributes);

        $this->setNameAttributeWithReference($name, $_attributes);

        if( ! empty($_attributes['name']) )
        {
            $this->_postback($_attributes['name'], $selected);

            # 5.8.2.8[added]
            $this->getVMethodMessages();

            # 5.4.2[added]
            $this->_validate($_attributes['name'], $_attributes['name']);
            
            # 5.4.2[added]|5.4.5|5.4.6[edited]
            $selected = $this->_getrow('select', $selected, $_attributes);
        }

        $this->commonMethodsForInputElements('select');

        $this->getPermAttribute($perm);

        $this->createSelectElement($options, $selected, $_attributes, $return);

        $this->createBootstrapFormInputElementByType('select', $return, $_attributes, $return);

        $this->_unsetselect();

        $this->outputElement .= $this->_perm($perm, $return);

        return $this;
    }
1346448
public function select($columns = '*'): SelectQuery
    {
        return $this->database->select(func_num_args() ? func_get_args() : '*')->from($this->name);
    }
816172
protected function subselect_query($name)
    {
        if (isset($this->subselect_query[$name]))
        {
            $sql = $this->subselect_query[$name];
        }
        else
        {
            $sql = preg_replace_callback('/\{(.+)\}/Uu', array($this, 'subselect_callback'), $this->subselect[$name]);
            $this->subselect_query[$name] = $sql;
        }
        return "({$sql}) AS `{$name}`";
    }
330671
public function toJson($all = false)
    {
        return $all ? json_encode($this->getAllData()) : json_encode($this->toArray());
    }
531894
private function getSelectQuery()
    {
        return 'SELECT '.(empty($this->parts['select']) ? '*' : implode(', ', $this->parts['select'])).
               ' FROM '.$this->getFromClause().
               (($this->parts['where'] !== null) ? ' WHERE '.$this->parts['where'] : null).
               (!empty($this->parts['group_by']) ? ' GROUP BY '.implode(', ', $this->parts['group_by']) : null).
               (($this->parts['having'] !== null) ? ' HAVING '.$this->parts['having'] : null).
               (!empty($this->parts['order_by']) ? ' ORDER BY '.implode(', ', $this->parts['order_by']) : null).
               (($this->parts['limit'] !== null) ? ' LIMIT '.$this->parts['limit'] : null).
               (($this->parts['offset'] !== null) ? ' OFFSET '.$this->parts['offset'] : null);
    }
1261391
public function update($all = false)
	{
		$db =  \App::get('db');

		$query = "UPDATE `#__trac_project` SET ";

		$classvars = get_class_vars(__CLASS__);

		$first = true;

		foreach ($classvars as $property => $value)
		{
			if (($property{0} == '_') || in_array($property, $this->_list_keys))
			{
				continue;
			}

			if (!$all && !in_array($property, $this->_updatedkeys))
			{
				continue;
			}

			if (!$first)
			{
				$query .= ',';
			}
			else
			{
				$first = false;
			}

			$value = $this->__get($property);

			if ($value === null)
			{
				$query .= "`$property`=NULL";
			}
			else
			{
				$query .= "`$property`=" . $db->quote($value);
			}
		}

		$query .= " WHERE `id`=" . $db->quote($this->__get('id')) . ";";

		if ($first == true)
		{
			$query = '';
		}

		if (!empty($query))
		{
			$db->setQuery($query);

			$result = $db->query();

			if ($result === false)
			{
				return false;
			}

			$affected = $db->getAffectedRows();

			if ($affected < 1)
			{
				$this->create();

				$db->setQuery($query);

				$result = $db->query();

				if ($result === false)
				{
					return false;
				}

				$affected = $db->getAffectedRows();

				if ($affected < 1)
				{
					return false;
				}
			}
		}

		return true;
	}
496933
public function query($criteria,$all=false)
	{
		$this->joinAll=$criteria->together===true;

		if($criteria->alias!='')
		{
			$this->_joinTree->tableAlias=$criteria->alias;
			$this->_joinTree->rawTableAlias=$this->_builder->getSchema()->quoteTableName($criteria->alias);
		}

		$this->_joinTree->find($criteria);
		$this->_joinTree->afterFind();

		if($all)
		{
			$result = array_values($this->_joinTree->records);
			if ($criteria->index!==null)
			{
				$index=$criteria->index;
				$array=array();
				foreach($result as $object)
					$array[$object->$index]=$object;
				$result=$array;
			}
		}
		elseif(count($this->_joinTree->records))
			$result = reset($this->_joinTree->records);
		else
			$result = null;

		$this->destroyJoinTree();
		return $result;
	}
297430
public function all(array $with = [], $all = false)
    {
        $query = $this->with($with);

        if (!$all) {
            $query->published();
        }

        // Query ORDER BY
        $query->order();

        // Get
        return $query->get();
    }
1097567
public function getQuery() {
        $query = 'SELECT '.implode(', ', $this->fields)
                .' FROM '.implode(', ', $this->from);
        if (count($this->conditions) > 0) {
            $query = $query.' WHERE '.implode(' AND ', $this->conditions);
        }
        $query = rtrim($query).';';

        return $query;
    }
566543
private function getQuerySelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT q.*, qt.*')
            ->from('ngbm_collection_query', 'q')
            ->innerJoin(
                'q',
                'ngbm_collection_query_translation',
                'qt',
                $query->expr()->andX(
                    $query->expr()->eq('qt.query_id', 'q.id'),
                    $query->expr()->eq('qt.status', 'q.status')
                )
            );

        return $query;
    }
1309938
public function all()
	{
		//build the select query
		$sql = $this->buildSelect();

		//set the value of the query string
		$this->query_string = $sql;

		//set the query excecution start time
		$query_start_time = microtime(true);

		//execute the sql query
		$result = $this->connector->execute($sql);

		//set the query excecution end time
		$query_stop_time = microtime(true);

		//get the query_excecution
		$query_excec_time = $query_stop_time - $query_start_time;


		//put this in try...catch block for better error handling
		try{

			//check if the query return an error and throw exception
			if ( $result === false ) 
			{
				//get the erro message
				$error = $this->connector->lastError();

				//throw exception
				throw new MySQLException(get_class(new MySQLException) . ' ' .$this->connector->lastError() . '<span class="query-string"> (' . $sql . ') </span>');

			}
			
		}

		//diplay error message
		catch(MySQLException $MySQLExceptionObject){

			//display error message
			$MySQLExceptionObject->errorShow();

		}


		//define container rows() array
		$result_array = array();

		//loop through resultset setting the values of arrays and objects
		while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

			$result_array[] = $row;

		}

		//get the response object instance
		$this->responseObject
			->setQueryString($this->query_string)
			->setQueryTime($query_excec_time)
			->setFieldCount($result->field_count)
			->setNumRows($result->num_rows)
			->setQueryFields($result->fetch_fields())
			->setResultArray($result_array);

		//return the full response object
		return $this->responseObject;
	}
554275
function select( $table, $options = array() ) {

        $options = array_merge( array(

            'expr' => null,
            'where' => array(),
            'orderBy' => array(),
            'limitCount' => null,
            'limitOffset' => null,
            'params' => array()

        ), $options );

        $query = "SELECT ";

        if ( empty( $options[ 'expr' ] ) ) {

            $query .= "*";

        } else if ( is_array( $options[ 'expr' ] ) ) {

            $query .= implode( ", ", $options[ 'expr' ] );

        } else {

            $query .= $options[ 'expr' ];

        }

        $table = $this->rewriteTable( $table );
        $query .= " FROM " . $this->quoteIdentifier( $table );

        $query .= $this->getSuffix( $options[ 'where' ], $options[ 'orderBy' ], $options[ 'limitCount' ], $options[ 'limitOffset' ] );

        $this->onQuery( $query, $options[ 'params' ] );

        $statement = $this->prepare( $query );
        $statement->setFetchMode( \PDO::FETCH_ASSOC );
        $statement->execute( $options[ 'params' ] );

        return $statement;

    }
432845
public function getQuery($toArray = false)
    {
        $result = $toArray ? $this->_query : http_build_query($this->_query, '', '&');
        return $result;
    }