1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-13 17:44:11 +02:00

fixed compatibility with PHP 8 [Closes #379]

This commit is contained in:
David Grudl
2020-10-15 16:50:37 +02:00
parent 3f7171c7a4
commit fa6a1203a9
4 changed files with 17 additions and 12 deletions

View File

@@ -124,7 +124,7 @@ class OdbcDriver implements Dibi\Driver
*/ */
public function begin(string $savepoint = null): void public function begin(string $savepoint = null): void
{ {
if (!odbc_autocommit($this->connection, 0/*false*/)) { if (!odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 0 : false)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
} }
@@ -139,7 +139,7 @@ class OdbcDriver implements Dibi\Driver
if (!odbc_commit($this->connection)) { if (!odbc_commit($this->connection)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
odbc_autocommit($this->connection, 1/*true*/); odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 1 : true);
} }
@@ -152,7 +152,7 @@ class OdbcDriver implements Dibi\Driver
if (!odbc_rollback($this->connection)) { if (!odbc_rollback($this->connection)) {
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
} }
odbc_autocommit($this->connection, 1/*true*/); odbc_autocommit($this->connection, PHP_VERSION_ID < 80000 ? 1 : true);
} }

View File

@@ -290,7 +290,7 @@ XX
if (is_array($v)) { if (is_array($v)) {
$vx[] = $this->formatValue($v, 'ex'); $vx[] = $this->formatValue($v, 'ex');
} elseif (is_string($k)) { } elseif (is_string($k)) {
$v = (is_string($v) && strncasecmp($v, 'd', 1)) || $v > 0 ? 'ASC' : 'DESC'; $v = (is_string($v) ? strncasecmp($v, 'd', 1) : $v > 0) ? 'ASC' : 'DESC';
$vx[] = $this->identifiers->$k . ' ' . $v; $vx[] = $this->identifiers->$k . ' ' . $v;
} else { } else {
$vx[] = $this->identifiers->$v; $vx[] = $this->identifiers->$v;
@@ -343,11 +343,13 @@ XX
case 'sN': // string or null case 'sN': // string or null
case 'sn': case 'sn':
return $value == '' ? 'NULL' : $this->driver->escapeText((string) $value); // notice two equal signs return $value === '' || $value === 0 || $value === null
? 'NULL'
: $this->driver->escapeText((string) $value);
case 'iN': // signed int or null case 'iN': // signed int or null
if ($value == '') { if ($value === '' || $value === 0 || $value === null) {
$value = null; return 'NULL';
} }
// break omitted // break omitted
case 'i': // signed int case 'i': // signed int

View File

@@ -147,7 +147,14 @@ test('', function () {
Assert::same(['col' => 1], $result->test(['col' => true])); Assert::same(['col' => 1], $result->test(['col' => true]));
Assert::same(['col' => 0], $result->test(['col' => false])); Assert::same(['col' => 0], $result->test(['col' => false]));
Assert::same(['col' => 0], @$result->test(['col' => ''])); // triggers warning in PHP 7.1 if (PHP_VERSION_ID < 80000) {
Assert::same(['col' => 0], @$result->test(['col' => ''])); // triggers warning since PHP 7.1
} else {
Assert::exception(function () use ($result) {
Assert::same(['col' => 0], $result->test(['col' => '']));
}, TypeError::class);
}
Assert::same(['col' => 0], $result->test(['col' => '0'])); Assert::same(['col' => 0], $result->test(['col' => '0']));
Assert::same(['col' => 1], $result->test(['col' => '1'])); Assert::same(['col' => 1], $result->test(['col' => '1']));
Assert::same(['col' => 10], $result->test(['col' => '10'])); Assert::same(['col' => 10], $result->test(['col' => '10']));

View File

@@ -1,9 +1,5 @@
<?php <?php
/**
* @phpversion 5.5
*/
declare(strict_types=1); declare(strict_types=1);
use Tester\Assert; use Tester\Assert;