Build the DROP TABLE query.

@param \Titon\Db\Query $query
@return string
514426
public function buildDropTable(Query $query) {
        return $this->renderStatement(Query::DROP_TABLE, [
            'table' => $this->formatTable($query->getTable())
        ] + $this->formatAttributes($query->getAttributes()));
    }
499520
public function delete($query)
    {
        $resources = $query->getRepository()->getResources();

        foreach ($resources->getLinks() as $link) {
            $query->where($link->child, '=', $link->parent);
        }

        $names = array();

        foreach ($resources as $resource) {
            $query->from($resource->getName().' AS '.$this->_store->quoteName($resource->getAlias()));
            $names[] = $this->_store->quoteName($resource->getAlias());
        }

        $clause = 'DELETE '.implode(', ', $names);

        return $clause;
    }
342354
protected function getTables(Query $query): array
    {
        $tables = [];

        if (is_string($query->table)) {
            $tables[] = $query->table;
        }

        foreach ($query->join as $join) {
            if (is_string($join->table)) {
                $tables[] = $join->table;
            }
        }

        return $tables;
    }
1143868
protected function dsn_select($query)
    {
        // no replication
        if ($this->db_dsnw == $this->db_dsnr) {
            return 'w';
        }

        // Read or write ?
        $mode = preg_match('/^(select|show|set)/i', $query) ? 'r' : 'w';

        $start = '[' . $this->options['identifier_start'] . self::DEFAULT_QUOTE . ']';
        $end   = '[' . $this->options['identifier_end']   . self::DEFAULT_QUOTE . ']';
        $regex = '/(?:^|\s)(from|update|into|join)\s+'.$start.'?([a-z0-9._]+)'.$end.'?\s+/i';

        // find tables involved in this query
        if (preg_match_all($regex, $query, $matches, PREG_SET_ORDER)) {
            foreach ($matches as $m) {
                $table = $m[2];

                // always use direct mapping
                if ($this->options['table_dsn_map'][$table]) {
                    $mode = $this->options['table_dsn_map'][$table];
                    break;  // primary table rules
                }
                else if ($mode == 'r') {
                    // connected to db with the same or "higher" mode for this table
                    $db_mode = $this->table_connections[$table];
                    if ($db_mode == 'w' && !$this->options['dsnw_noread']) {
                        $mode = $db_mode;
                    }
                }
            }

            // remember mode chosen (for primary table)
            $table = $matches[0][2];
            $this->table_connections[$table] = $mode;
        }

        return $mode;
    }
257029
public function getTables(string &$query) : array
    {
        $tables = [];
        foreach ($this->tables as &$table) {
            if (strpos($query, $table['table_name']) !== false) {
                $tables[] = $table['table_name'];
            }
        }

        unset($table);
        return $tables;
    }
846593
final protected function createSelectQuery(Query $query)
    {
        $select = $this->getDatabase()->select('node', 'n')->fields('n', ['nid'])->addTag('node_access');

        if ($this->addGroupby()) {
            $select->groupBy('n.nid');
        }

        return $select;
    }
1053084
public function build(&$query)
    {
        if (isset($query['alias']) && isset($query['id'])) {
            if (!isset($query['get'])) {
                $query['id'] = $query['id'].'-'.$query['alias'];
            }

            unset($query['alias']);
        }

        $has_id = isset($query['id']);
        $segments = parent::build($query);

        if ($has_id) {
            if (isset($query['get'])) {
                $segments[] = $query['get'];

                if ($query['get'] == 'graph') {
                    if (!isset($query['type'])) {
                        $query['type'] = 'followers';
                    }

                    $segments[] = $query['type'];

                    unset($query['type']);
                }

                unset($query['get']);
            }
        } elseif (isset($query['oid'])) {
            if ($query['oid'] == 'viewer') {
                $query['oid'] = get_viewer()->uniqueAlias;
            }

            $segments[] = '@'.$query['oid'];

            unset($query['oid']);
        }

        return $segments;
    }
960900
public function build($query)
    {
        //clone the query so it won't be modified
        $query = clone $query;
        $parts = array();
        $this->_query = $query;
        $this->_store = $query->getRepository()->getStore();
        switch ($query->operation['type']) {
            case AnDomainQuery::QUERY_SELECT_DEFAULT :
            case AnDomainQuery::QUERY_SELECT  :
                $parts[] = $this->select($query);
                $parts[] = $this->from($query);
                $parts[] = '@MYSQL_JOIN_PLACEHOLDER';
                $parts[] = $this->where($query);
                $parts[] = $this->group($query);
                $parts[] = $this->having($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_UPDATE :
                $parts[] = $this->update($query);
                $parts[] = $this->where($query);
                $parts[] = $this->order($query);
                $parts[] = $this->limit($query);
                break;
            case AnDomainQuery::QUERY_DELETE :
                $parts[] = $this->delete($query);
                $parts[] = $this->from($query);
                $parts[] = $this->where($query);
                break;
            default :
                _die();
        }

        $string = implode(' ', $parts);
        $string = $this->parseMethods($query, $string);
        $string = str_replace('@MYSQL_JOIN_PLACEHOLDER', $this->join($query), $string);
        $string = $this->parseMethods($query, $string);

        if (!empty($query->binds)) {
            foreach ($query->binds as $key => $value) {
                $key = ':'.$key;
                $value = $this->_store->quoteValue($value);
                $string = str_replace($key, $value, $string);
            }
        }

        $string = str_replace('@DISTINCT', $query->distinct ? 'DISTINCT' : '', $string);

        return    $string;
    }
1202380
public function limit($query)
    {
        $clause = '';

        if (!empty($query->limit)) {
            switch ($query->operation['type']) {
                case AnDomainQuery::QUERY_SELECT_DEFAULT :
                case AnDomainQuery::QUERY_SELECT  :
                    $clause = ' LIMIT '.$query->offset.' , '.$query->limit;
                    break;
                case AnDomainQuery::QUERY_UPDATE :
                    if ((int) $query->limit > 0) {
                        $clause = ' LIMIT '.$query->limit;
                    }
                    break;
            }
        }

        return $clause;
    }
852202
private function renameSource(Query $query, string $tableName = null):string {
        if($tableName == null) {
            $tableName = $this->getTableName();
        }
        $previusSource = $query->getTable();
        if(!empty($tableName)) {
            $query->table($tableName);
        }
        return $previusSource;
    }
1054659
public function build(&$query)
    {
        if (isset($query['uniqueAlias'])) {
            $query['id'] = $query['uniqueAlias'];
            unset($query['uniqueAlias']);
        }

        return parent::build($query);
    }
914231
protected function filterQuery($query)
    {
        $queryInfo = [];

        foreach (explode('&', $query) as $part) {
            list($name, $value) = explode('=', (false === strpos($part, '=') ? "{$part}=" : $part), 2);

            $name = rawurldecode($name);
            $value = rawurldecode($value);

            if (0 === preg_match_all('/\[([^\]]*)\]/m', $name, $matches)) {
                $queryInfo[$name] = $value;
                continue;
            }

            $name   = substr($name, 0, strpos($name, '['));
            $keys   = array_merge([$name], $matches[1]);
            $target = &$queryInfo;

            foreach ($keys as $index) {
                if ('' === $index) {
                    $target = &$target[];
                } else {
                    $target = &$target[$index];
                }
            }

            $target = $value;
        }

        return $queryInfo;
    }
982012
public function compile_select( &$query )
	{
		$build = ( $query->distinct ? 'select distinct' : 'select' ).' ';

		if ( !empty( $query->fields ) )
		{
			foreach( $query->fields as $key => $field )
			{
				if ( !is_numeric( $key ) )
				{
					$build .= $this->escape( $key ).' as '.$this->escape( $field );
				}
				elseif ( is_array( $field ) )
				{
					$build .= $this->escape( $field[0] ).' as '.$this->escape( $field[1] );
				}
				else 
				{
					$build .= $this->escape( $field );
				}
				$build .= ', ';
			}

			$build = substr( $build, 0, -2 );
		}
		else 
		{
			$build .= '*';
		}

		// append the table
		$build .= ' from '.$this->escape_table( $query );

		// build the where stuff
		$build .= $this->compile_where( $query );
		$build .= $this->compile_group( $query );
		$build .= $this->compile_order( $query );
		$build .= $this->compile_limit_with_offset( $query );

		return $build;
	}
889856
public function runQuery(Query $query): Result {
        $query = $query->getQuery();

        echo self::$debugSparql ? $query . "\n" : '';

        return $this->runSparql($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;
    }
650735
public function where($query)
    {
        $clauses = $this->_where($query);

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

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

        return $clause;
    }
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);
	}