mirror of
https://github.com/dg/dibi.git
synced 2025-09-02 10:32:33 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d70e274244 | ||
|
e05eb01233 | ||
|
2ac618ffff | ||
|
1881fea0e5 | ||
|
cb82357cfb | ||
|
0a29fcb502 | ||
|
8270b7c1c3 |
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: ['7.2', '7.3', '7.4', '8.0']
|
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
|
||||||
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ Install Dibi via Composer:
|
|||||||
composer require dibi/dibi
|
composer require dibi/dibi
|
||||||
```
|
```
|
||||||
|
|
||||||
The Dibi 4.2 requires PHP version 7.2 and supports PHP up to 8.0.
|
The Dibi 4.2 requires PHP version 7.2 and supports PHP up to 8.1.
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
|
@@ -22,10 +22,14 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
/** @var bool|null */
|
/** @var bool|null */
|
||||||
private $debugMode;
|
private $debugMode;
|
||||||
|
|
||||||
|
/** @var bool|null */
|
||||||
|
private $cliMode;
|
||||||
|
|
||||||
public function __construct(bool $debugMode = null)
|
|
||||||
|
public function __construct(bool $debugMode = null, bool $cliMode = null)
|
||||||
{
|
{
|
||||||
$this->debugMode = $debugMode;
|
$this->debugMode = $debugMode;
|
||||||
|
$this->cliMode = $cliMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +42,11 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
$this->debugMode = $container->parameters['debugMode'];
|
$this->debugMode = $container->parameters['debugMode'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$useProfiler = $config['profiler'] ?? (class_exists(Tracy\Debugger::class) && $this->debugMode);
|
if ($this->cliMode === null) {
|
||||||
|
$this->cliMode = $container->parameters['consoleMode'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$useProfiler = $config['profiler'] ?? (class_exists(Tracy\Debugger::class) && $this->debugMode && !$this->cliMode);
|
||||||
|
|
||||||
unset($config['profiler']);
|
unset($config['profiler']);
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ namespace Dibi\Drivers;
|
|||||||
|
|
||||||
use Dibi;
|
use Dibi;
|
||||||
use Dibi\Helpers;
|
use Dibi\Helpers;
|
||||||
|
use PgSql;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,7 +30,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource */
|
/** @var resource|PgSql\Connection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var int|null Affected rows */
|
/** @var int|null Affected rows */
|
||||||
@@ -74,7 +75,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_resource($this->connection)) {
|
if (!is_resource($this->connection) && !$this->connection instanceof PgSql\Connection) {
|
||||||
throw new Dibi\DriverException($error ?: 'Connecting error.');
|
throw new Dibi\DriverException($error ?: 'Connecting error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +121,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
throw static::createException(pg_last_error($this->connection), null, $sql);
|
throw static::createException(pg_last_error($this->connection), null, $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res) || $res instanceof PgSql\Result) {
|
||||||
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
||||||
if (pg_num_fields($res)) {
|
if (pg_num_fields($res)) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
@@ -227,7 +228,9 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : null;
|
return is_resource($this->connection) || $this->connection instanceof PgSql\Connection
|
||||||
|
? $this->connection
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -258,7 +261,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
*/
|
*/
|
||||||
public function escapeText(string $value): string
|
public function escapeText(string $value): string
|
||||||
{
|
{
|
||||||
if (!is_resource($this->connection)) {
|
if (!$this->getResource()) {
|
||||||
throw new Dibi\Exception('Lost connection to server.');
|
throw new Dibi\Exception('Lost connection to server.');
|
||||||
}
|
}
|
||||||
return "'" . pg_escape_string($this->connection, $value) . "'";
|
return "'" . pg_escape_string($this->connection, $value) . "'";
|
||||||
@@ -267,7 +270,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
|
|
||||||
public function escapeBinary(string $value): string
|
public function escapeBinary(string $value): string
|
||||||
{
|
{
|
||||||
if (!is_resource($this->connection)) {
|
if (!$this->getResource()) {
|
||||||
throw new Dibi\Exception('Lost connection to server.');
|
throw new Dibi\Exception('Lost connection to server.');
|
||||||
}
|
}
|
||||||
return "'" . pg_escape_bytea($this->connection, $value) . "'";
|
return "'" . pg_escape_bytea($this->connection, $value) . "'";
|
||||||
|
@@ -102,7 +102,7 @@ class PostgreReflector implements Dibi\Reflector
|
|||||||
a.atttypmod-4 AS character_maximum_length,
|
a.atttypmod-4 AS character_maximum_length,
|
||||||
NOT a.attnotnull AS is_nullable,
|
NOT a.attnotnull AS is_nullable,
|
||||||
a.attnum AS ordinal_position,
|
a.attnum AS ordinal_position,
|
||||||
adef.adsrc AS column_default
|
pg_get_expr(adef.adbin, adef.adrelid) AS column_default
|
||||||
FROM
|
FROM
|
||||||
pg_attribute a
|
pg_attribute a
|
||||||
JOIN pg_type ON a.atttypid = pg_type.oid
|
JOIN pg_type ON a.atttypid = pg_type.oid
|
||||||
|
@@ -11,6 +11,7 @@ namespace Dibi\Drivers;
|
|||||||
|
|
||||||
use Dibi;
|
use Dibi;
|
||||||
use Dibi\Helpers;
|
use Dibi\Helpers;
|
||||||
|
use PgSql;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +21,7 @@ class PostgreResult implements Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource */
|
/** @var resource|PgSql\Result */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@@ -28,7 +29,7 @@ class PostgreResult implements Dibi\ResultDriver
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resource $resultSet
|
* @param resource|PgSql\Result $resultSet
|
||||||
*/
|
*/
|
||||||
public function __construct($resultSet)
|
public function __construct($resultSet)
|
||||||
{
|
{
|
||||||
@@ -108,12 +109,14 @@ class PostgreResult implements Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|null
|
* @return resource|PgSql\Result|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = false;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : null;
|
return is_resource($this->resultSet) || $this->resultSet instanceof PgSql\Result
|
||||||
|
? $this->resultSet
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -181,6 +181,7 @@ class Helpers
|
|||||||
{
|
{
|
||||||
static $patterns = [
|
static $patterns = [
|
||||||
'^_' => Type::TEXT, // PostgreSQL arrays
|
'^_' => Type::TEXT, // PostgreSQL arrays
|
||||||
|
'RANGE$' => Type::TEXT, // PostgreSQL range types
|
||||||
'BYTEA|BLOB|BIN' => Type::BINARY,
|
'BYTEA|BLOB|BIN' => Type::BINARY,
|
||||||
'TEXT|CHAR|POINT|INTERVAL|STRING' => Type::TEXT,
|
'TEXT|CHAR|POINT|INTERVAL|STRING' => Type::TEXT,
|
||||||
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => Type::INTEGER,
|
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => Type::INTEGER,
|
||||||
|
@@ -489,7 +489,7 @@ class Result implements IDataSource
|
|||||||
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||||
|
|
||||||
} elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
|
} elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
|
||||||
if ($value && substr((string) $value, 0, 3) !== '000') { // '', null, false, '0000-00-00', ...
|
if ($value && substr((string) $value, 0, 7) !== '0000-00') { // '', null, false, '0000-00-00', ...
|
||||||
$value = new DateTime($value);
|
$value = new DateTime($value);
|
||||||
$row[$key] = $format ? $value->format($format) : $value;
|
$row[$key] = $format ? $value->format($format) : $value;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -44,6 +44,7 @@ class ResultIterator implements \Iterator, \Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[\ReturnTypeWillChange]
|
||||||
/**
|
/**
|
||||||
* Returns the key of the current element.
|
* Returns the key of the current element.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -54,6 +55,7 @@ class ResultIterator implements \Iterator, \Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[\ReturnTypeWillChange]
|
||||||
/**
|
/**
|
||||||
* Returns the current element.
|
* Returns the current element.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
@@ -37,7 +37,7 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
{
|
{
|
||||||
$time = $this[$key];
|
$time = $this[$key];
|
||||||
if (!$time instanceof DateTime) {
|
if (!$time instanceof DateTime) {
|
||||||
if (!$time || substr((string) $time, 0, 3) === '000') { // '', null, false, '0000-00-00', ...
|
if (!$time || substr((string) $time, 0, 7) === '0000-00') { // '', null, false, '0000-00-00', ...
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$time = new DateTime($time);
|
$time = new DateTime($time);
|
||||||
@@ -62,37 +62,38 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
|
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
|
||||||
|
|
||||||
|
|
||||||
final public function count()
|
final public function count(): int
|
||||||
{
|
{
|
||||||
return count((array) $this);
|
return count((array) $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function getIterator()
|
final public function getIterator(): \ArrayIterator
|
||||||
{
|
{
|
||||||
return new \ArrayIterator($this);
|
return new \ArrayIterator($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function offsetSet($nm, $val)
|
final public function offsetSet($nm, $val): void
|
||||||
{
|
{
|
||||||
$this->$nm = $val;
|
$this->$nm = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[\ReturnTypeWillChange]
|
||||||
final public function offsetGet($nm)
|
final public function offsetGet($nm)
|
||||||
{
|
{
|
||||||
return $this->$nm;
|
return $this->$nm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function offsetExists($nm)
|
final public function offsetExists($nm): bool
|
||||||
{
|
{
|
||||||
return isset($this->$nm);
|
return isset($this->$nm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function offsetUnset($nm)
|
final public function offsetUnset($nm): void
|
||||||
{
|
{
|
||||||
unset($this->$nm);
|
unset($this->$nm);
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ class dibi
|
|||||||
|
|
||||||
/** version */
|
/** version */
|
||||||
public const
|
public const
|
||||||
VERSION = '4.2.3';
|
VERSION = '4.2.5';
|
||||||
|
|
||||||
/** sorting order */
|
/** sorting order */
|
||||||
public const
|
public const
|
||||||
|
@@ -14,8 +14,6 @@ Assert::same('1978-01-23 11:40:00.000000', (string) new DateTime(254400000));
|
|||||||
Assert::same('1978-01-23 11:40:00.000000', (string) (new DateTime)->setTimestamp(254400000));
|
Assert::same('1978-01-23 11:40:00.000000', (string) (new DateTime)->setTimestamp(254400000));
|
||||||
Assert::same(254400000, (new DateTime(254400000))->getTimestamp());
|
Assert::same(254400000, (new DateTime(254400000))->getTimestamp());
|
||||||
|
|
||||||
Assert::same('2050-08-13 11:40:00.000000', (string) new DateTime(2544000000));
|
|
||||||
Assert::same('2050-08-13 11:40:00.000000', (string) (new DateTime)->setTimestamp(2544000000));
|
|
||||||
Assert::same(is_int(2544000000) ? 2544000000 : '2544000000', (new DateTime(2544000000))->getTimestamp()); // 64 bit
|
Assert::same(is_int(2544000000) ? 2544000000 : '2544000000', (new DateTime(2544000000))->getTimestamp()); // 64 bit
|
||||||
|
|
||||||
Assert::same('1978-05-05 00:00:00.000000', (string) new DateTime('1978-05-05'));
|
Assert::same('1978-05-05 00:00:00.000000', (string) new DateTime('1978-05-05'));
|
||||||
|
Reference in New Issue
Block a user