Method to get the SQL query used to retrieve the list of content items.

@param   mixed  $query  A JDatabaseQuery object or null.

@return  JDatabaseQuery  A database object.

@since   2.5
354738
protected function getListQuery($query = null)
	{
		$db = JFactory::getDbo();

		// Check if we can use the supplied SQL query.
		$query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
			->select('a.id, a.title, a.alias, a.description AS summary, a.extension')
			->select('a.created_user_id AS created_by, a.modified_time AS modified, a.modified_user_id AS modified_by')
			->select('a.metakey, a.metadesc, a.metadata, a.language, a.lft, a.parent_id, a.level')
			->select('a.created_time AS start_date, a.published AS state, a.access, a.params');

		// Handle the alias CASE WHEN portion of the query.
		$case_when_item_alias = ' CASE WHEN ';
		$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
		$case_when_item_alias .= ' THEN ';
		$a_id = $query->castAsChar('a.id');
		$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
		$case_when_item_alias .= ' ELSE ';
		$case_when_item_alias .= $a_id . ' END as slug';
		$query->select($case_when_item_alias)
			->from('#__categories AS a')
			->where($db->quoteName('a.id') . ' > 1');

		return $query;
	}
225431
public function retrieve($query)
	{
		// Eager load configured relationships.
		$query = $this->setEagerLoaded($query);

		// Execute the query.
		$retrieved = $query->get();

		// Eager load configured relationships.
		return $this->setLazyLoaded($retrieved);
	}
831223
public static function plainSql($query)
    {
        $query = static::getBaseQuery($query);
        return self::inlineBindings($query->toSql(), $query->getBindings());
    }
1112690
public function query($sql = null)
    {
        if (!$sql) {
            $sqlWhere = '';
            if (!empty($this->getWhere())) {
                $sqlWhere = $this->getWhere();
            }

            $sqlLimit = '';
            if (!empty($this->getLimit())) {
                $sqlLimit = $this->getLimit();
            }

            $sqlOrder = '';
            $orderBy = $this->getOrderBy();
            if (!empty($orderBy)) {
                $sqlOrder = $orderBy;
            }

            $sqlSelect = "SELECT " . $this->getSelect();
            $sqlFrom = " FROM " . $this->getTable();

            $sql = $sqlSelect . $sqlFrom . $sqlWhere . $sqlOrder . $sqlLimit;
        }
        $this->setLastQuery($sql);

        try {
            $stmt = $this->db->prepare($sql);
            $this->setLastQuery($stmt->queryString, $this->getParameters());
            $stmt->execute($this->getParameters());
        } catch (\PDOException $e) {
            throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);
        }

        $this->setResult($stmt);
        $this->clearQuery();

        return $this;
    }
990718
public static function query($query)
    {
        $res = self::connection()->sql_query($query);

        if (!$res || self::connection()->sql_errno()) {
            // SQL statement failed
            $errorMsg = sprintf(
                'SQL Error: %s [errno: %s]',
                self::connection()->sql_error(),
                self::connection()->sql_errno()
            );

            if (defined('TYPO3_cliMode')) {
                throw new \Exception($errorMsg);
            } else {
                debug('SQL-QUERY: ' . $query, $errorMsg, __LINE__, __FILE__);
            }

            $res = null;
        }

        return $res;
    }
1164199
protected function getQueryString($query)
    {
        $wrapper = ($query instanceof AbstractQuery) ? array('query' => $query->toArray()) : $query->toArray();

        return json_encode($wrapper);
    }
1319104
private function executeQuery($query) {
		$content = (string)$this->getAdapter()->get($query)->getBody();
		if (empty($content)) {
			throw new NoResult(sprintf('Could not execute query %s', $query));
		}

		$data = Xml::build($content);
		if (empty($data) || empty($data->result)) {
			throw new NoResult(sprintf('Could not execute query %s', $query));
		}

		$data = (array)$data->result;

		$adminLevels = [];

		if (!empty($data['isp']) || !empty($data['isp'])) {
			$adminLevels[] = [
				'name' => isset($data['isp']) ? $data['isp'] : null,
				'code' => null,
				'level' => 1
			];
		}

		return $this->returnResults([
			array_merge($this->getDefaults(), [
				'latitude' => isset($data['latitude']) ? $data['latitude'] : null,
				'longitude' => isset($data['longitude']) ? $data['longitude'] : null,
				'locality' => isset($data['city']) ? $data['city'] : null,
				'adminLevels' => $adminLevels,
				'country' => isset($data['countryname']) ? $data['countryname'] : null,
				'countryCode' => isset($data['countrycode']) ? $data['countrycode'] : null,
			])
		]);
	}
1334384
public static function getRow($query)
    {
        $ret = null;

        $res = self::query($query);
        if ($res) {
            if ($row = self::connection()->sql_fetch_assoc($res)) {
                $ret = $row;
            }
            self::free($res);
        }

        return $ret;
    }
1090630
final public static function getObjectByQuery($query, $params=[]) {
		
		$app	= Application::getInstance();
		$db		= Database::getInstance();
		$class	= get_called_class();
		
		// run query
		$db->setQuery($query);
		$row = $db->loadObject($params);
		
		// initialize custom binds
		$customBinds = [];
		
		if (!is_a($row, 'stdClass')) {
			return NULL;
		}
			
		$binds = $class::getBinds();
		
		// get object properties from query
		$fields  = get_object_vars($row);
		
		// search for custom field names
		foreach ($fields as $field=>$value) {
			if (!array_search($field, $binds)) {
				$customBinds[Utilities::getCamelCase($field)] = $field;
			}
		}
		
		$object = new $class($row);
		
		// populate custom properties
		foreach ($customBinds as $customProp=>$customField) {
			$object->$customProp = $row->$customField;
		}
			
		// turn on loaded-from-db flag
		$object->loadedFromDb = TRUE;
			
		$app->logEvent('Loaded a ' . $class . ' object' . (count($customBinds) ? ' with custom fields ' . implode(',', $customBinds) : ''));
		
		return $object;
		
	}
515996
public function search($query)
  {
    $content = $query->getBridgeJson($this->clientKey);

    return $this->query($this->bridgeUrl, $content, self::RESULTS_CLASS);
  }
823444
protected function _where($query)
    {
        $link = null;
        $type_check = true;

        if ($query instanceof AnConfig) {
            $type_check = false;
            $query = $query->query;
        }

        $description = $query->getRepository()->getDescription();
        $clauses = array();
        if ($description->getInheritanceColumn() && $type_check) {
            $resource = $description->getInheritanceColumn()->resource->getAlias();
            //the table type column name
            $type_column_name = $resource.'.'.$description->getInheritanceColumn()->name;

            $scopes = AnConfig::unbox($query->instance_of);
            if (empty($scopes)) {
                $scopes = array($description);
            } else {
                if (!is_array($scopes)) {
                    $scopes = array($scopes);
                }
            }

            foreach ($scopes as $index => $scope) {
                $inheritance_type = $this->_inheritanceTree($scope);
                if (!empty($inheritance_type) && $inheritance_type != '%') {
                    $operator = substr($inheritance_type, -1) == '%' ? 'LIKE' : '=';
                    $scopes[$index] = $type_column_name.' '.$operator.' \''.$inheritance_type.'\'';
                } else {
                    unset($scopes[$index]);
                }
            }
            if (!empty($scopes)) {
                $clauses[] = '('.implode(' OR ', $scopes).')';
            }
        }

        if (!empty($query->where)) {
            $clause = '';
            foreach ($query->where as $where) {
                $clause .= $this->_buildWhere($query, $where);
            }
            if (!empty($clause)) {
                $clauses[] = '('.$clause.')';
            }
        }

        foreach ($query->link as $link) {
            $clauses = array_merge($clauses, $this->_where($link));
        }

        return $clauses;
    }
8567
public function getRawData($query)
    {

        $this->query['query'] = $query;

        // clear error description
        if (isset($this->query['errstr'])) {
            unset($this->query['errstr']);
        }

        if (!isset($this->query['server'])) {
            $this->query['status'] = 'error';
            $this->query['errstr'][] = 'No server specified';
            return (array());
        }

        // Check if protocol is http
        if (substr($this->query['server'], 0, 7) == 'http://' ||
            substr($this->query['server'], 0, 8) == 'https://'
        ) {
            $output = $this->httpQuery($this->query['server']);

            if (!$output) {
                $this->query['status'] = 'error';
                $this->query['errstr'][] = 'Connect failed to: ' . $this->query['server'];
                return (array());
            }

            $this->query['args'] = substr(strchr($this->query['server'], '?'), 1);
            $this->query['server'] = strtok($this->query['server'], '?');

            if (substr($this->query['server'], 0, 7) == 'http://') {
                $this->query['server_port'] = 80;
            } else {
                $this->query['server_port'] = 443;
            }
        } else {
            // Get args
            if (strpos($this->query['server'], '?')) {
                $parts = explode('?', $this->query['server']);
                $this->query['server'] = trim($parts[0]);
                $query_args = trim($parts[1]);

                // replace substitution parameters
                $query_args = str_replace('{query}', $query, $query_args);
                $query_args = str_replace('{version}', 'phpWhois' . $this->codeVersion, $query_args);

                $iptools = new IpTools;
                if (strpos($query_args, '{ip}') !== false) {
                    $query_args = str_replace('{ip}', $iptools->getClientIp(), $query_args);
                }

                if (strpos($query_args, '{hname}') !== false) {
                    $query_args = str_replace('{hname}', gethostbyaddr($iptools->getClientIp()), $query_args);
                }
            } else {
                if (empty($this->query['args'])) {
                    $query_args = $query;
                } else {
                    $query_args = $this->query['args'];
                }
            }

            $this->query['args'] = $query_args;

            if (substr($this->query['server'], 0, 9) == 'rwhois://') {
                $this->query['server'] = substr($this->query['server'], 9);
            }

            if (substr($this->query['server'], 0, 8) == 'whois://') {
                $this->query['server'] = substr($this->query['server'], 8);
            }

            // Get port
            if (strpos($this->query['server'], ':')) {
                $parts = explode(':', $this->query['server']);
                $this->query['server'] = trim($parts[0]);
                $this->query['server_port'] = trim($parts[1]);
            } else {
                $this->query['server_port'] = $this->port;
            }

            // Connect to whois server, or return if failed
            $ptr = $this->connect();

            if ($ptr === false) {
                $this->query['status'] = 'error';
                $this->query['errstr'][] = 'Connect failed to: ' . $this->query['server'];
                return array();
            }

            stream_set_timeout($ptr, $this->stimeout);
            stream_set_blocking($ptr, 0);

            // Send query
            fputs($ptr, trim($query_args) . "\r\n");

            // Prepare to receive result
            $raw = '';
            $start = time();
            $null = null;
            $r = array($ptr);

            while (!feof($ptr)) {
                if (!empty($r)) {
                    if (stream_select($r, $null, $null, $this->stimeout)) {
                        $raw .= fgets($ptr, $this->buffer);
                    }
                }

                if (time() - $start > $this->stimeout) {
                    $this->query['status'] = 'error';
                    $this->query['errstr'][] = 'Timeout reading from ' . $this->query['server'];
                    return array();
                }
            }

            if (array_key_exists($this->query['server'], $this->NON_UTF8)) {
                $raw = utf8_encode($raw);
            }

            $output = explode("\n", $raw);

            // Drop empty last line (if it's empty! - saleck)
            if (empty($output[count($output) - 1])) {
                unset($output[count($output) - 1]);
            }
        }

        return $output;
    }
290178
public function executeQuery($query = null)
    {
        $connection = $this->getConnection();
        
        $connection->transaction(function (ConnectionInterface $connection) use ($query) {
            $connection->execute($query);
        });
        
        return $connection->affectedRows();
    }
697433
public function execute($query)
    {
        $this->_queries[] = $query;

        $sql = is_string($query) ? $query : $query->getString();

        $resultSQL = $this->getAdapter()->execute($sql);
        $result = new Result($resultSQL, $this->getAdapter());
        $result->setQuery($query);

        return $result;
    }
1237230
public final function get(string $query, array $queryParams = null, string $fetchClass = null)
    {
        return $this->query($query, $queryParams, 1, $fetchClass)->getData(0);
    }
668612
public function getArray($query)
    {
        $this->statement = $this->db->query($query);
        if ($this->statement) {
            return $this->statement->fetch(\PDO::FETCH_ASSOC);
        }
        return false;
    }
502401
public function query($query)
    {
        // If the query is empty, we'll return false
        if ($query === null || empty($query)) {
            return false;
        }

        if ($this->read) {
            // If read is true, we'll perform a read search, retrieving one record
            $results = $this->connection->read($this->getDn(), $query, $this->getSelects());
        } elseif ($this->recursive) {
            // If recursive is true, we'll perform a recursive search
            $results = $this->connection->search($this->getDn(), $query, $this->getSelects());
        } else {
            // Read and recursive is false, we'll return a listing
            $results = $this->connection->listing($this->getDn(), $query, $this->getSelects());
        }

        if ($results) {
            return $this->processResults($results);
        }

        return false;
    }