Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add totals #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/ClickHouseStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace FOD\DBALClickHouse;

use ClickHouseDB\Client;
use ClickHouseDB\Statement as ClientStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -47,6 +48,9 @@ class ClickHouseStatement implements \IteratorAggregate, Statement
/** @var Client */
protected $smi2CHClient;

/** @var ClientStatement */
protected $clientStatement;

/** @var string */
protected $statement;

Expand Down Expand Up @@ -321,23 +325,36 @@ public function getSql() : string
/**
* Specific SMI2 ClickHouse lib statement execution
* If you want to use any other lib for working with CH -- just update this method
*
* @param string $sql
*/
protected function processViaSMI2(string $sql) : void
{
$sql = trim($sql);

$this->rows =
if (
stripos($sql, 'select') === 0 ||
stripos($sql, 'show') === 0 ||
stripos($sql, 'describe') === 0 ?
$this->smi2CHClient->select($sql)->rows() :
$this->smi2CHClient->write($sql)->rows();
stripos($sql, 'describe') === 0
) {
$this->clientStatement = $this->smi2CHClient->select($sql);
} else {
$this->clientStatement = $this->smi2CHClient->write($sql);
}

$this->rows = $this->clientStatement->rows();
}

/**
* @return array
*/
public function getTotals(): array
{
return $this->clientStatement->totals();
}

/**
* @param string|int $key
* @throws ClickHouseException
* @return string
*/
protected function getTypedParam($key) : string
{
Expand Down