@param null $query

@return ConnectionInterface
@throws ConnectionException
185914
public function execute($query = null)
    {
        try {
            $event = new ConnectionEvent($this, $query);
            $this->container->getDispatcher()->dispatch(ConnectionEvent::ON_QUERY, $event);
            $this->affectedRows = parent::exec($query);
        } catch (\Exception $exception) {
            throw new ConnectionException('Executing query has error: [:code] ":error"', [
                'code'  => $exception->getCode(),
                'error' => $exception->getMessage(),
            ]);
        }
        
        return $this;
    }
832192
public function queryBuilder(ConnectionInterface $connection, String $connectionId=null) : QueryBuilderProvider
	{
		return new QueryBuilder($connection, $connectionId);
	}
478033
public function queryBuilder($connection = null)
    {
        $key = $connection ?? $this->defaultConnection;

        if (!isset($this->queryBuilders[$key]))
        {
            $this->connection($key); // init connection
            $this->queryBuilders[$key] = new QueryBuilder($this->adapterProviders[$key]);
        }

        return $this->queryBuilders[$key];
    }
586599
static function doSelectRS(Query $q = null) {
		$q = $q ? clone $q : static::getQuery();

		if (!$q->getTable()) {
			$q->setTable(static::getTableName());
		}

		return $q->doSelect(static::getConnection());
	}
834826
public function query($query) {
    if(method_exists($this->db, 'query')) {
      return $this->db->query($query);
    } else {
      throw new Exception(__METHOD__ . " not implemented");
    }
  }
1044041
protected function sendQuery(string $query)
    {
        if (self::$monitorQueries) {
            self::$queriesCount++;
        }
        $result = $this->link->query($query);
        if ($result === false) {
            throw new SqlException(
                'SQL-error [' . $this->link->errno . ']: ' . $this->link->error . "\nSQL-query: $query",
                $this->link->errno
            );
        }

        return $result === true ? $result : new Query\Result($result);
    }
313252
public function query($query)
    {
        if (is_subclass_of($query, 'Database\Query\QueryAbstract')) {
            return $this->query($this->buildQuery($query));
        }

        $debug = (new Debug\ExecutedQuery($query))->setBacktrace(debug_backtrace());
        $startTime = microtime(true);
        try {
            $result = $this->pdo->query($query);
        } catch (\Throwable $throwable) {
            $debug->setException($throwable);
            throw $throwable;
        } finally {
            $debug->setExecutionTime(microtime(true) - $startTime);
            Debug::addQuery($debug);
        }

        return $this->getPDODatabaseRecord($result);
    }
650380
protected function performJoin($query = null)
    {
        $query = $query ?: $this->query;

        // We need to join to the intermediate table on the related model's primary
        // key column with the intermediate table's foreign key for the related
        // model instance. Then we can set the "where" for the parent models.
        $baseTable = $this->related->getTable();

        $key = $baseTable.'.'.$this->related->getKeyName();

        $query->join($this->table, $key, '=', $this->getQualifiedRelatedKeyName());

        return $this;
    }
1251032
public function getConnection($name = ''): QueryBuilderInterface
	{
		// If the parameter is a string, use it as an array index
		if (is_scalar($name) && isset($this->connections[$name]))
		{
			return $this->connections[$name];
		}
		else if (empty($name) && ! empty($this->connections)) // Otherwise, return the last one
		{
			return end($this->connections);
		}

		// You should actually connect before trying to get a connection...
		throw new InvalidArgumentException('The specified connection does not exist');
	}
801881
public function toQuery ($query)
		{
			if (is_object($query)) {
				$query = clone $query;
			}

			if ($query instanceof DatabaseQuery) {
				return $query;

			} else if ($query instanceof DatabaseQueryCondition) {
				return $this->createQuery()->where($query);

			} else if (is_null($query)) {
				return $this->createQuery();

			} else {
				throw new DatabaseException('Invalid query/condition type.');
			}
		}
486031
public function setQuery($query = null)
    {

        try {

            // need to return << true
            $this->validator->verify($query, ['isNotNull', 'isAcceptLength']);

            if (false === $this->exact) {
                $this->query = ['query' => '%' . $query . '%'];
            }
            else {
                $this->query = ['query' => $query];
            }

        }
        catch(ExceptionFactory $e) {
            echo $e->getMessage();
        }

        return $this;
    }
691573
@Nullable
    public T query() throws SQLException {
        try (ResultSet r = executeQuery()) {
            if (r.next()) {
                return resultMapper.map(r);
            }
            return null;
        }
    }
1339523
public function execute(string $query, array $parameters): CollectionInterface
    {
        $numServers = count($this->availableServers) - 1;

        for ($i = 0; $i <= $numServers; $i++) {
            // always get the first available server
            $server = $this->availableServers[0];

            // Move the selected server to the end of the stack
            $this->availableServers[] = array_shift($this->availableServers);

            $options = array_merge($this->httpOptions, [
                'base_uri' => sprintf('%s://%s', $this->protocol, $server),
                'json'     => [
                    'stmt' => $query,
                    'args' => $parameters,
                ],
            ]);

            try {
                $response     = $this->httpClient->request('POST', '/_sql', $options);
                $responseBody = json_decode((string)$response->getBody(), true);

                return new Collection(
                    $responseBody['rows'],
                    $responseBody['cols'],
                    $responseBody['duration'],
                    $responseBody['rowcount']
                );
            } catch (ConnectException $exception) {
                // Catch it before the BadResponseException but do nothing.
                continue;
            } catch (BadResponseException $exception) {
                $body = (string)$exception->getResponse()->getBody();
                $json = json_decode($body, true);

                if ($json === null && json_last_error() !== JSON_ERROR_NONE) {
                    throw new RuntimeException(sprintf('Server returned non-JSON response: %s', $body), 0, $exception);
                }

                $errorCode    = $json['error']['code'];
                $errorMessage = $json['error']['message'];

                throw new RuntimeException($errorMessage, $errorCode, $exception);
            }
        }

        throw new ConnectException(
            sprintf('No more servers available, exception from last server: %s', $exception->getMessage()),
            $exception->getRequest(),
            $exception
        );
    }
391575
public static function connection($name = null)
    {
        if (is_null($name) || strlen($name) == 0) {
            if (is_null(static::$name)) {
                static::$name = static::$config['default'];
            }

            $name = static::$name;
        }

        if (!isset(static::$config['connection'][$name])) {
            throw new ConnectionException('The connection "' . $name . '" is not defined.');
        }

        if ($name !== static::$name) {
            static::$adapter = null;
        }

        $config = static::$config['connection'][$name];

        static::$name = $name;

        if (static::$adapter === null) {
            if ($name == 'mysql') {
                static::$adapter = new MysqlAdapter($config);
            } elseif ($name == 'sqlite') {
                static::$adapter = new SqliteAdapter($config);
            } else {
                throw new ConnectionException('This driver is not praised');
            }

            static::$adapter->setFetchMode(static::$config['fetch']);
        }

        if (static::$adapter->getConnection() instanceof PDO && $name == static::$name) {
            return static::getInstance();
        }

        return static::getInstance();
    }
895092
public function process(QueryInterface $query)
    {
        if (!$query->isType(QueryInterface::TYPE_USE)) {
            return null;
        }

        $query = new UseQuery($query);
        $keyspace = $query->getDbName();
        $this->dsn->getConfig()->setKeyspace($keyspace);

        if ($this->client instanceof CachingClient) {
            $this->client->clearCache();
        }

        return new EmptyResult();
    }
704407
public function getConnection($connection = null)
    {
        if ($connection) {
            $this->connection = $connection;
        }

        return Redis::connection($this->connection);
    }
89818
public function getDataProvider(Query $query = null) {
		if(!$this instanceof ReadInterface) {
			throw new InvalidConfigException("Repository " . static::class . " not implements of ReadInterface");
		}
		$query = $this->prepareQuery($query);
		$dataProvider = new ActiveDataProvider([
			'query' => $query,
			'service' => $this,
		]);
		$dataProvider->models = $this->afterReadTrigger($dataProvider->models, $query);
		return $dataProvider;
	}