From 8915b0343c14621b550a7370d4e7e5e67af2c44b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Dec 2021 04:09:30 +0100 Subject: [PATCH] removed support for PHP 7 --- src/Dibi/DataSource.php | 31 +++++++++++++------------------ src/Dibi/Drivers/OdbcDriver.php | 6 +++--- src/Dibi/Fluent.php | 7 +------ tests/dibi/Fluent.select.phpt | 8 +++++--- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index 81e538b..c743d3a 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -229,24 +229,19 @@ class DataSource implements IDataSource */ public function __toString(): string { - try { - return $this->connection->translate( - "\nSELECT %n", - (empty($this->cols) ? '*' : $this->cols), - "\nFROM %SQL", - $this->sql, - "\n%ex", - $this->conds ? ['WHERE %and', $this->conds] : null, - "\n%ex", - $this->sorting ? ['ORDER BY %by', $this->sorting] : null, - "\n%ofs %lmt", - $this->offset, - $this->limit, - ); - } catch (\Throwable $e) { - trigger_error($e->getMessage(), E_USER_ERROR); - return ''; - } + return $this->connection->translate( + "\nSELECT %n", + (empty($this->cols) ? '*' : $this->cols), + "\nFROM %SQL", + $this->sql, + "\n%ex", + $this->conds ? ['WHERE %and', $this->conds] : null, + "\n%ex", + $this->sorting ? ['ORDER BY %by', $this->sorting] : null, + "\n%ofs %lmt", + $this->offset, + $this->limit, + ); } diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index 82a3652..9869c7c 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -125,7 +125,7 @@ class OdbcDriver implements Dibi\Driver */ public function begin(?string $savepoint = null): void { - if (!odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 0 : false)) { + if (!odbc_autocommit($this->connection, false)) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } } @@ -141,7 +141,7 @@ class OdbcDriver implements Dibi\Driver throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } - odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 1 : true); + odbc_autocommit($this->connection, true); } @@ -155,7 +155,7 @@ class OdbcDriver implements Dibi\Driver throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } - odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 1 : true); + odbc_autocommit($this->connection, true); } diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index cdbd419..81f7f6a 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -413,12 +413,7 @@ class Fluent implements IDataSource */ final public function __toString(): string { - try { - return $this->connection->translate($this->_export()); - } catch (\Throwable $e) { - trigger_error($e->getMessage(), E_USER_ERROR); - return ''; - } + return $this->connection->translate($this->_export()); } diff --git a/tests/dibi/Fluent.select.phpt b/tests/dibi/Fluent.select.phpt index 7b9ba18..09a645f 100644 --- a/tests/dibi/Fluent.select.phpt +++ b/tests/dibi/Fluent.select.phpt @@ -147,9 +147,11 @@ if ($config['system'] === 'mysql') { ->limit(' 1; DROP TABLE users') ->offset(' 1; DROP TABLE users'); - Assert::error(function () use ($fluent) { - (string) $fluent; - }, E_USER_ERROR, "Expected number, ' 1; DROP TABLE users' given."); + Assert::exception( + fn() => (string) $fluent, + Dibi\Exception::class, + "Expected number, ' 1; DROP TABLE users' given.", + ); }