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 1 commit
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
20 changes: 12 additions & 8 deletions src/ClickHouseStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,27 @@ 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 =
stripos($sql, 'select') === 0 ||
stripos($sql, 'show') === 0 ||
stripos($sql, 'describe') === 0 ?
$this->smi2CHClient->select($sql)->rows() :
$this->smi2CHClient->write($sql)->rows();
if (stripos($sql, 'select') !== 0 && stripos($sql, 'show') !== 0 && stripos($sql, 'describe') !== 0) {
$this->rows = $this->smi2CHClient->write($sql)->rows();
return;
}

$this->rows = $this->smi2CHClient->select($sql)->rows();
$totals = $this->smi2CHClient->select($sql)->totals();
if (null !== $totals) {
$this->rows = array_merge($this->rows, ['totals' => $totals]);
}
}

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