mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 06:36:44 +02:00
fixed compatibility with PHP 8 [Closes #379]
This commit is contained in:
@@ -124,7 +124,7 @@ class OdbcDriver implements Dibi\Driver
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ class OdbcDriver implements Dibi\Driver
|
||||
if (!odbc_commit($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)) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -290,7 +290,7 @@ XX
|
||||
if (is_array($v)) {
|
||||
$vx[] = $this->formatValue($v, 'ex');
|
||||
} 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;
|
||||
} else {
|
||||
$vx[] = $this->identifiers->$v;
|
||||
@@ -343,11 +343,13 @@ XX
|
||||
|
||||
case 'sN': // string or null
|
||||
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
|
||||
if ($value == '') {
|
||||
$value = null;
|
||||
if ($value === '' || $value === 0 || $value === null) {
|
||||
return 'NULL';
|
||||
}
|
||||
// break omitted
|
||||
case 'i': // signed int
|
||||
|
@@ -147,7 +147,14 @@ test('', function () {
|
||||
Assert::same(['col' => 1], $result->test(['col' => true]));
|
||||
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' => 1], $result->test(['col' => '1']));
|
||||
Assert::same(['col' => 10], $result->test(['col' => '10']));
|
||||
|
@@ -1,9 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @phpversion 5.5
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tester\Assert;
|
||||
|
Reference in New Issue
Block a user