Skip to content

Commit

Permalink
php 8.0+ support
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaksei.sanikovich authored and aliaksei.sanikovich committed May 24, 2022
1 parent 9bfbfc6 commit 21a0842
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 185 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
composer.lock
vendor/
phpunit.xml
.phpunit.result.cache
Vagrantfile
puphpet/
.vagrant/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sudo: required
php:
- 7.1
- 7.2
- 8.0
- nightly

services:
Expand Down
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
{
"name": "Mitrofanov Nikolay",
"email": "[email protected]"
},
{
"name": "Sanikovich Aleksey",
"email": "[email protected]"
}
],
"require": {
"php": "^7.1",
"ext-PDO": "*",
"php": "^7.1 || ^8.0",
"ext-pdo": "*",
"ext-pcre": "*",
"doctrine/dbal": "^2.7",
"smi2/phpClickHouse": "^1.0"
"smi2/phpclickhouse": "^1.0"
},
"require-dev": {
"doctrine/coding-standard": "^4.0",
"phpunit/phpunit": "^7.0"
"doctrine/coding-standard": "^4.0 || ^9.0",
"phpunit/phpunit": "^7.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand Down
39 changes: 17 additions & 22 deletions src/ClickHouseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class ClickHouseConnection implements Connection, PingableConnection, ServerInfo
/** @var AbstractPlatform */
protected $platform;

/**
* Connection constructor
*
* @param mixed[] $params
*/
public function __construct(
array $params,
string $username,
Expand All @@ -60,15 +55,15 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function prepare($prepareString)
public function prepare($prepareString) : ClickHouseStatement
{
return new ClickHouseStatement($this->smi2CHClient, $prepareString, $this->platform);
}

/**
* {@inheritDoc}
*/
public function query()
public function query() : ClickHouseStatement
{
$args = func_get_args();
$stmt = $this->prepare($args[0]);
Expand Down Expand Up @@ -105,73 +100,73 @@ public function exec($statement) : int
*/
public function lastInsertId($name = null)
{
throw new \LogicException('Unable to get last insert id in ClickHouse');
throw ClickHouseException::notSupported('Unable to get last insert id in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function beginTransaction()
public function beginTransaction() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function commit()
public function commit() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function rollBack()
public function rollBack() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function errorCode()
public function errorCode() : ?string
{
throw new \LogicException('You need to implement ClickHouseConnection::errorCode()');
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorCode()');
}

/**
* {@inheritDoc}
*/
public function errorInfo()
public function errorInfo() : array
{
throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()');
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorInfo()');
}

/**
* {@inheritDoc}
*/
public function ping()
public function ping() : bool
{
return $this->smi2CHClient->ping();
}

/**
* {@inheritDoc}
*/
public function getServerVersion()
public function getServerVersion() : string
{
try {
return $this->smi2CHClient->getServerVersion();
} catch (TransportException $exception) {
} catch (TransportException $e) {
return '';
}
}

/**
* {@inheritDoc}
*/
public function requiresQueryForServerVersion()
public function requiresQueryForServerVersion() : bool
{
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion src/ClickHouseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@

namespace FOD\DBALClickHouse;

use Doctrine\DBAL\Exception;

/**
* Specific Exception for ClickHouse
*/
class ClickHouseException extends \Exception
class ClickHouseException extends Exception
{
public static function notSupported($method) : ClickHouseException
{
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
}
}
Loading

0 comments on commit 21a0842

Please sign in to comment.