Build basis of common activity SQL query.

@since 2.0.0
@access public
324986
public function ActivityQuery($Join = TRUE) {
      $this->SQL
         ->Select('a.*')
         ->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
         ->Select('t.Name', '', 'ActivityType')
         ->From('Activity a')
         ->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
      
      if ($Join) {
         $this->SQL
            ->Select('au.Name', '', 'ActivityName')
            ->Select('au.Gender', '', 'ActivityGender')
            ->Select('au.Photo', '', 'ActivityPhoto')
            ->Select('au.Email', '', 'ActivityEmail')
            ->Select('ru.Name', '', 'RegardingName')
            ->Select('ru.Gender', '', 'RegardingGender')
            ->Select('ru.Email', '', 'RegardingEmail')
            ->Select('ru.Photo', '', 'RegardingPhoto')
            ->Join('User au', 'a.ActivityUserID = au.UserID')
            ->Join('User ru', 'a.RegardingUserID = ru.UserID', 'left');
      }
         
      $this->FireEvent('AfterActivityQuery');
   }
704008
protected function _buildSelect()
        {
            // If the query is raw, just set the $this->_values to be
            // the raw query parameters and return the raw query
            if ($this->_is_raw_query) {
                $this->_values = $this->_raw_parameters;
                return $this->_raw_query;
            }

            // Build and return the full SELECT statement by concatenating
            // the results of calling each separate builder method.
            return $this->_joinIfNotEmpty(
                " ",
                array(
                    $this->_buildSelectStart(),
                    $this->_buildJoin(),
                    $this->_buildWhere(),
                    $this->_buildGroupBy(),
                    $this->_buildHaving(),
                    $this->_buildOrderBy(),
                    $this->_buildLimit(),
                    $this->_buildOffset(),
                )
            );
        }
6296
private function buildDebugSql()
    {
        $bindParams = $this->bindParams;
        foreach ($bindParams as $key => $val) {
            $bindParams[$key] = str_replace('\\\\', '\\', addslashes($val));
        }
        return vsprintf(str_replace('%s', "'%s'", $this->currentSql), $bindParams);
    }
697141
protected function buildQuery()
    {
        /** @var Search $search */
        $search = $this->repository->createSearch();
        $search->setSize($this->limit);
        $search->addSort(new Sort('left', Sort::ORDER_ASC));
        $search->addQuery(new TermQuery('active', true), 'must');
        if (!$this->loadHiddenCategories) {
            $search->addQuery(new TermQuery('is_hidden', 0), 'must');
        }

        return $search;
    }
539743
private function buildQueries()
    {
        $queries = array();

        $outerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.outerglue', ' | ');
        $innerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.innerglue', ': ');

        foreach ($this->logger->getQueries() as $q) {
            $parts = explode($outerGlue, $q, 4);

            $times = explode($innerGlue, $parts[0]);
            $con = explode($innerGlue, $parts[2]);
            $memories = explode($innerGlue, $parts[1]);

            $sql = trim($parts[3]);
            $con = trim($con[1]);
            $time = trim($times[1]);
            $memory = trim($memories[1]);

            $queries[] = array('connection' => $con, 'sql' => $sql, 'time' => $time, 'memory' => $memory);
        }

        return $queries;
    }
1065533
protected function generateJoinSQL()
        {
            $sql = ' FROM ' . $this->getTable()->getSelectFromSql();
            foreach ($this->query->getJoins() as $join) {
                $sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
                $sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());

                if ($join->hasAdditionalCriteria()) {
                    $sql_parts = [];

                    foreach ($join->getAdditionalCriteria() as $criteria) {
                        $criteria->setQuery($this->query);
                        $sql_parts[] = $criteria->getSql();
                        foreach ($criteria->getValues() as $value) {
                            $this->query->addValue($value);
                        }
                    }

                    $sql .= ' AND ' . join(' AND ', $sql_parts);
                }

                $sql .= ')';
            }

            return $sql;
        }
1028809
private function compileQuery()
    {
        if ($this->queryConfiguration->isGlobalSearch()) {
            $this->compileGlobalQuery();
        } elseif ($this->queryConfiguration->isColumnSearch()) {
            $this->compileColumnQuery();
        }
    }
1160460
public function initActiveQuery()
    {
        $this->activeQuery = Tree::find();

        if ($this->treePid) {
            $this->activeQuery->andWhere(['pid' => $this->treePid]);
        }

        if ($this->level) {
            $this->activeQuery->andWhere(['level' => $this->level]);
        }

        if ($this->active) {
            $this->activeQuery->andWhere(['active' => $this->active]);
        }

        if ($this->site_codes) {
            $cmsSites = CmsSite::find()->where(['code' => $this->site_codes])->all();
            if ($cmsSites) {
                $ids = ArrayHelper::map($cmsSites, 'id', 'id');
                $this->activeQuery->andWhere(['cms_site_id' => $ids]);
            }
        }

        if ($this->enabledCurrentSite == Cms::BOOL_Y && \Yii::$app->cms->site) {
            $this->activeQuery->andWhere(['cms_site_id' => \Yii::$app->cms->site->id]);
        }

        if ($this->orderBy) {
            $this->activeQuery->orderBy([$this->orderBy => (int)$this->order]);
        }

        if ($this->tree_type_ids) {
            $this->activeQuery->andWhere(['tree_type_id' => $this->tree_type_ids]);
        }


        if ($this->with) {
            $this->activeQuery->with($this->with);
        }

        if ($this->activeQueryCallback && is_callable($this->activeQueryCallback)) {
            $callback = $this->activeQueryCallback;
            $callback($this->activeQuery);
        }

        return $this;
    }
1019987
public function sql()
    {
        if ($this->active()) {
            if ($this->hasFilters()) {
                $sql = $this->byFilters();
                if ($this->isNegating()) {
                    return $this->operator().' '.$sql;
                }
                return $sql;
            }

            if ($this->hasCondition()) {
                $sql = $this->byCondition();
                if ($this->isNegating()) {
                    return $this->operator().' ('.$sql.')';
                }
                return $sql;
            }

            if ($this->hasFields()) {
                return $this->byPredicate();
            }
        }

        return '';
    }
645476
public function buildQuery()
    {
        $model = $this->model;
        $query = $model::query();

        // perform joins
        if (is_array($this->join)) {
            foreach ($this->join as $condition) {
                list($joinModel, $column, $foreignKey) = $condition;
                $query->join($joinModel, $column, $foreignKey);
            }
        }

        // sanitze and set the filter
        $filter = $this->parseFilterInput($this->filter);
        $query->where($filter);

        // performs a search using LIKE queries
        // WARNING use sparingly, these queries are expensive
        if (!empty($this->search) && is_string($this->search) && property_exists($model, 'searchableProperties')) {
            $w = [];
            $search = addslashes($this->search);
            foreach ($model::$searchableProperties as $name) {
                $w[] = "`$name` LIKE '%$search%'";
            }

            if (count($w) > 0) {
                $query->where('('.implode(' OR ', $w).')');
            }
        }

        // eager loading
        foreach ($this->expand as $k) {
            $property = $model::getProperty($k);
            if ($property && isset($property['relation'])) {
                if (isset($property['id_property'])) {
                    $query->with($property['id_property']);
                } else {
                    $query->with($k);
                }
            }
        }

        if (isset($this->sort)) {
            $query->sort($this->sort);
        }

        // calculate limit and offset
        $start = ($this->page - 1) * $this->perPage;
        $query->start($start)->limit($this->perPage);

        return $query;
    }
1122376
public function get_query()
	{
		// Get the columns
		$columns = $this->select(false);

		// Start building the query
		$select = $columns;
		if ($this->use_subquery())
		{
			$select = array();
			foreach ($columns as $c)
			{
				$select[] = $c[0];
			}
		}
		$query = call_fuel_func_array('DB::select', $select);

		// Set the defined connection on the query
		$query->set_connection($this->connection);

		// Set from table
		$query->from(array($this->_table(), $this->alias));

		// Build the query further
		$tmp = $this->build_query($query, $columns);

		return $tmp['query'];
	}
107683
function it_holds_the_sql_fragments()
    {
        $this->appendSql('SELECT * FROM Phn');
        $this->appendSql(' ');
        $this->appendSql('WHERE true;');

        $this->getSql()->shouldBe('SELECT * FROM Phn WHERE true;');
    }
1164412
public function buildSql()
    {
        $sqlDbMapContent = "# Sqlfile -> Database map\n";
        foreach ($this->getDatabases() as $datasource => $database) {
            $platform = $database->getPlatform();
            $filename = $database->getName() . '.sql';

            if ($this->getGeneratorConfig()->getBuildProperty('disableIdentifierQuoting')) {
                $platform->setIdentifierQuoting(false);
            }

            $ddl = $platform->getAddTablesDDL($database);

            $file = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $filename;
            if (file_exists($file) && $ddl == file_get_contents($file)) {
                // Unchanged
            } else {
                file_put_contents($file, $ddl);
            }

            $sqlDbMapContent .= sprintf("%s=%s\n", $filename, $datasource);
        }

        file_put_contents($this->getSqlDbMapFilename(), $sqlDbMapContent);
    }
776730
private function _constructSql() {
        if($this->sql) {
            return [$this->sql,$this->params];
        }
        $distinct = $this->distinct ? 'DISTINCT' : '';
        $groupby = '';
        if (!empty($this->group)) {
            $groupby = 'GROUP BY ' . $this->group;
        }
        if (!empty($this->having)) {
            $groupby .= ' ' . $this->having;
        }
        $order = !empty($this->order) ? "ORDER BY $this->order" : '';

        $this->fields = $this->fields?$this->fields:'*';
        $sql = "SELECT $distinct $this->fields FROM `$this->table` $this->alias $this->join $this->where $groupby $order $this->limit";
        $sql = str_replace('table.',$this->alias.'.',$sql);
        return [$sql,$this->params];
    }
374323
protected function buildQuery()
	{
		$this->setup();

		$query = array();

		// Index always needs to be provided. _all means a cross index search.
		$query['index'] = empty($this->indices) ? '_all' : implode(',', array_values($this->indices));

		// Type is not required, will search in the entire index.
		if (!empty($this->types)) {
			$query['type'] = implode(',', array_values($this->types));
		}

		// Replace Fragments with their raw body.
		$query['body'] = $this->fragmentParser->parse($this->body);

		// Add all query string params, the SDK will only add known params to the URL.
		foreach ($this->queryStringParams as $paramName => $paramValue) {
			$query[$paramName] = $paramValue;
		}

		return $query;
	}
933587
public function query()
    {
        $stmt = call_user_func_array([$this, 'executeSql'], func_get_args());
        if (ActiveRecord::lastError())
            return false;
        return $stmt->fetchAll();
    }
868095
private function buildOriginalQuery()
    {
        return
            'SELECT '.$this->buildSelectedColumns().' FROM '.$this->quoteIdentifier(
                self::cyrus()->getTableName()
            ).' '.$this->getWhere().
            ' '.$this->getGroupBy().' '.$this->buildHavingConditions().' '.$this->getOrderBy().' '.$this->getLimit();
    }