1
0
mirror of https://github.com/dg/dibi.git synced 2025-09-02 02:22:33 +02:00

Compare commits

...

17 Commits
v3.2.2 ... v3.2

Author SHA1 Message Date
David Grudl
d571460a6f Released version 3.2.4 2020-03-26 04:05:01 +01:00
David Grudl
dc3e1cda19 SqliteResult: workaround for PHP bug 79414 2020-03-26 04:02:26 +01:00
David Grudl
21039ff379 Result: does not drop the value if detection fails 2020-03-26 04:00:52 +01:00
David Grudl
22b15d9859 travis: fixed databases 2020-03-26 04:00:52 +01:00
Chrudos Vorlicek
6aa8a431c2 Result::normalize() Fix select float in format of e-notation (#317) v3.2 (#320) 2018-10-25 22:33:22 +02:00
David Grudl
69ea60cc16 travis: added PHP 7.3 2018-10-17 17:47:42 +02:00
David Grudl
906e1f2407 Released version 3.2.3 2018-09-17 13:47:10 +02:00
David Grudl
6a4f77b684 test: fix for PHP 7.3 2018-09-17 13:36:50 +02:00
Jan Kuchař
689597a237 PdoDriver: check for misconfigured PDO connections resource (#294) 2018-09-17 13:36:50 +02:00
David Grudl
a8ed2a34e5 travis: uses NCS 2 2018-09-13 03:28:20 +02:00
David Grudl
c8e5f5c8d1 loader: added missing classes [Closes #310] 2018-08-22 15:38:20 +02:00
David Grudl
4bfd314225 OdbcDriver: added option 'microseconds' 2018-08-09 22:54:00 +02:00
David Grudl
2b4ea9abe7 updated donation links 2018-06-22 11:48:18 +02:00
Miroslav Koula
3711b1739f DibiExtension: compatibility with Nette DI 3.x (#297)
Nette DI 3.x require $container->setFactory() usage except of $container->setClass()
2018-06-19 11:56:01 +02:00
David Grudl
45d7e0b365 cs 2018-06-13 15:39:54 +02:00
Josef Drábek
7d07db1f12 PdoDriver::getInsertId() fixed 2018-06-13 11:49:27 +02:00
Jan Endel
34bdd5f267 typo
for example fluent:

$dibiConnection->select(‘id’)
    ->from(‘users’);

will not pass static analysis although is completely valid code.
2018-06-13 11:48:28 +02:00
15 changed files with 99 additions and 20 deletions

View File

@@ -6,6 +6,11 @@ php:
- 7.0 - 7.0
- 7.1 - 7.1
- 7.2 - 7.2
- 7.3
services:
- mysql
- postgresql
before_install: before_install:
# turn off XDebug # turn off XDebug
@@ -33,12 +38,12 @@ jobs:
php: 7.1 php: 7.1
install: install:
# Install Nette Code Checker # Install Nette Code Checker
- travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-progress - travis_retry composer create-project nette/code-checker temp/code-checker ^3 --no-progress
# Install Nette Coding Standard # Install Nette Coding Standard
- travis_retry composer create-project nette/coding-standard temp/coding-standard --no-progress - travis_retry composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress
script: script:
- php temp/code-checker/src/code-checker.php --short-arrays - php temp/code-checker/code-checker
- php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.neon - php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.yml
- stage: Code Coverage - stage: Code Coverage
@@ -63,3 +68,5 @@ cache:
notifications: notifications:
email: false email: false
dist: trusty

View File

@@ -1,4 +1,4 @@
[Dibi](https://dibiphp.com) - smart database layer for PHP [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN) [Dibi](https://dibiphp.com) - smart database layer for PHP [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https://nette.org/make-donation?to=dibi)
========================================================= =========================================================
[![Downloads this Month](https://img.shields.io/packagist/dm/dibi/dibi.svg)](https://packagist.org/packages/dibi/dibi) [![Downloads this Month](https://img.shields.io/packagist/dm/dibi/dibi.svg)](https://packagist.org/packages/dibi/dibi)
@@ -14,6 +14,8 @@ Introduction
Database access functions in PHP are not standardised. This library Database access functions in PHP are not standardised. This library
hides the differences between them, and above all, it gives you a very handy interface. hides the differences between them, and above all, it gives you a very handy interface.
If you like Dibi, **[please make a donation now](https://nette.org/make-donation?to=dibi)**. Thank you!
Installation Installation
------------ ------------

View File

@@ -50,7 +50,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
} }
$connection = $container->addDefinition($this->prefix('connection')) $connection = $container->addDefinition($this->prefix('connection'))
->setClass('Dibi\Connection', [$config]) ->setFactory('Dibi\Connection', [$config])
->setAutowired(isset($config['autowired']) ? $config['autowired'] : true); ->setAutowired(isset($config['autowired']) ? $config['autowired'] : true);
if (class_exists('Tracy\Debugger')) { if (class_exists('Tracy\Debugger')) {
@@ -61,7 +61,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
} }
if ($useProfiler) { if ($useProfiler) {
$panel = $container->addDefinition($this->prefix('panel')) $panel = $container->addDefinition($this->prefix('panel'))
->setClass('Dibi\Bridges\Tracy\Panel', [ ->setFactory('Dibi\Bridges\Tracy\Panel', [
isset($config['explain']) ? $config['explain'] : true, isset($config['explain']) ? $config['explain'] : true,
isset($config['filter']) && $config['filter'] === false ? Dibi\Event::ALL : Dibi\Event::QUERY, isset($config['filter']) && $config['filter'] === false ? Dibi\Event::ALL : Dibi\Event::QUERY,
]); ]);

View File

@@ -22,7 +22,7 @@ class DateTime extends \DateTime
{ {
if (is_numeric($time)) { if (is_numeric($time)) {
parent::__construct('@' . $time); parent::__construct('@' . $time);
$this->setTimeZone($timezone ? $timezone : new \DateTimeZone(date_default_timezone_get())); $this->setTimeZone($timezone ?: new \DateTimeZone(date_default_timezone_get()));
} elseif ($timezone === null) { } elseif ($timezone === null) {
parent::__construct($time); parent::__construct($time);
} else { } else {

View File

@@ -19,6 +19,7 @@ use Dibi;
* - password (or pass) * - password (or pass)
* - persistent (bool) => try to find a persistent link? * - persistent (bool) => try to find a persistent link?
* - resource (resource) => existing connection resource * - resource (resource) => existing connection resource
* - microseconds (bool) => use microseconds in datetime format?
*/ */
class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
{ {
@@ -33,6 +34,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
/** @var bool */ /** @var bool */
private $autoFree = true; private $autoFree = true;
/** @var bool */
private $microseconds = true;
/** @var int|false Affected rows */ /** @var int|false Affected rows */
private $affectedRows = false; private $affectedRows = false;
@@ -78,6 +82,10 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!is_resource($this->connection)) { if (!is_resource($this->connection)) {
throw new Dibi\DriverException(odbc_errormsg() . ' ' . odbc_error()); throw new Dibi\DriverException(odbc_errormsg() . ' ' . odbc_error());
} }
if (isset($config['microseconds'])) {
$this->microseconds = (bool) $config['microseconds'];
}
} }
@@ -286,7 +294,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value); $value = new Dibi\DateTime($value);
} }
return $value->format('#m/d/Y H:i:s.u#'); return $value->format($this->microseconds ? '#m/d/Y H:i:s.u#' : '#m/d/Y H:i:s#');
} }

View File

@@ -78,6 +78,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
} }
} }
if ($this->connection->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_SILENT) {
throw new Dibi\DriverException('PDO connection in exception or warning error mode is not supported.');
}
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); $this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
$this->serverVersion = isset($config['version']) $this->serverVersion = isset($config['version'])
? $config['version'] ? $config['version']
@@ -148,7 +152,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
*/ */
public function getInsertId($sequence) public function getInsertId($sequence)
{ {
return $this->connection->lastInsertId(); return $this->connection->lastInsertId($sequence);
} }

View File

@@ -548,7 +548,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
$res = $this->query($query); $res = $this->query($query);
$tables = pg_fetch_all($res->resultSet); $tables = pg_fetch_all($res->resultSet);
return $tables ? $tables : []; return $tables ?: [];
} }

View File

@@ -445,11 +445,12 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
$columns = []; $columns = [];
static $types = [SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null']; static $types = [SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null'];
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$type = $this->resultSet->columnType($i); // buggy in PHP 7.4.4 & 7.3.16, bug 79414
$columns[] = [ $columns[] = [
'name' => $this->resultSet->columnName($i), 'name' => $this->resultSet->columnName($i),
'table' => null, 'table' => null,
'fullname' => $this->resultSet->columnName($i), 'fullname' => $this->resultSet->columnName($i),
'nativetype' => $types[$this->resultSet->columnType($i)], 'nativetype' => $type ? $types[$type] : null,
]; ];
} }
return $columns; return $columns;

View File

@@ -13,7 +13,7 @@ namespace Dibi;
* *
* @method Fluent select(...$field) * @method Fluent select(...$field)
* @method Fluent distinct() * @method Fluent distinct()
* @method Fluent from($table, ...$args) * @method Fluent from($table, ...$args = null)
* @method Fluent where(...$cond) * @method Fluent where(...$cond)
* @method Fluent groupBy(...$field) * @method Fluent groupBy(...$field)
* @method Fluent having(...$cond) * @method Fluent having(...$cond)

View File

@@ -498,8 +498,11 @@ class Result implements IDataSource
} elseif ($type === Type::FLOAT) { } elseif ($type === Type::FLOAT) {
$value = ltrim((string) $value, '0'); $value = ltrim((string) $value, '0');
$p = strpos($value, '.'); $p = strpos($value, '.');
if ($p !== false) { $e = strpos($value, 'e');
if ($p !== false && $e === false) {
$value = rtrim(rtrim($value, '0'), '.'); $value = rtrim(rtrim($value, '0'), '.');
} elseif ($p !== false && $e !== false) {
$value = rtrim($value, '.');
} }
if ($value === '' || $value[0] === '.') { if ($value === '' || $value[0] === '.') {
$value = '0' . $value; $value = '0' . $value;
@@ -526,6 +529,9 @@ class Result implements IDataSource
} elseif ($type === Type::BINARY) { } elseif ($type === Type::BINARY) {
$row[$key] = $this->getResultDriver()->unescapeBinary($value); $row[$key] = $this->getResultDriver()->unescapeBinary($value);
} else {
$row[$key] = $value;
} }
} }
} }

View File

@@ -21,8 +21,8 @@ class dibi
/** version */ /** version */
const const
VERSION = '3.2.2', VERSION = '3.2.4',
REVISION = 'released on 2018-05-02'; REVISION = 'released on 2020-03-26';
/** sorting order */ /** sorting order */
const const

View File

@@ -17,27 +17,30 @@ spl_autoload_register(function ($class) {
'Dibi\Bridges\Nette\DibiExtension22' => 'Bridges/Nette/DibiExtension22.php', 'Dibi\Bridges\Nette\DibiExtension22' => 'Bridges/Nette/DibiExtension22.php',
'Dibi\Bridges\Tracy\Panel' => 'Bridges/Tracy/Panel.php', 'Dibi\Bridges\Tracy\Panel' => 'Bridges/Tracy/Panel.php',
'Dibi\Connection' => 'Connection.php', 'Dibi\Connection' => 'Connection.php',
'Dibi\ConstraintViolationException' => 'exceptions.php',
'Dibi\DataSource' => 'DataSource.php', 'Dibi\DataSource' => 'DataSource.php',
'Dibi\DateTime' => 'DateTime.php', 'Dibi\DateTime' => 'DateTime.php',
'Dibi\Driver' => 'interfaces.php', 'Dibi\Driver' => 'interfaces.php',
'Dibi\DriverException' => 'exceptions.php', 'Dibi\DriverException' => 'exceptions.php',
'Dibi\Drivers\FirebirdDriver' => 'Drivers/FirebirdDriver.php', 'Dibi\Drivers\FirebirdDriver' => 'Drivers/FirebirdDriver.php',
'Dibi\Drivers\SqlsrvDriver' => 'Drivers/SqlsrvDriver.php',
'Dibi\Drivers\SqlsrvReflector' => 'Drivers/SqlsrvReflector.php',
'Dibi\Drivers\MsSqlDriver' => 'Drivers/MsSqlDriver.php', 'Dibi\Drivers\MsSqlDriver' => 'Drivers/MsSqlDriver.php',
'Dibi\Drivers\MsSqlReflector' => 'Drivers/MsSqlReflector.php', 'Dibi\Drivers\MsSqlReflector' => 'Drivers/MsSqlReflector.php',
'Dibi\Drivers\MySqlDriver' => 'Drivers/MySqlDriver.php', 'Dibi\Drivers\MySqlDriver' => 'Drivers/MySqlDriver.php',
'Dibi\Drivers\MySqliDriver' => 'Drivers/MySqliDriver.php',
'Dibi\Drivers\MySqlReflector' => 'Drivers/MySqlReflector.php', 'Dibi\Drivers\MySqlReflector' => 'Drivers/MySqlReflector.php',
'Dibi\Drivers\MySqliDriver' => 'Drivers/MySqliDriver.php',
'Dibi\Drivers\OdbcDriver' => 'Drivers/OdbcDriver.php', 'Dibi\Drivers\OdbcDriver' => 'Drivers/OdbcDriver.php',
'Dibi\Drivers\OracleDriver' => 'Drivers/OracleDriver.php', 'Dibi\Drivers\OracleDriver' => 'Drivers/OracleDriver.php',
'Dibi\Drivers\PdoDriver' => 'Drivers/PdoDriver.php', 'Dibi\Drivers\PdoDriver' => 'Drivers/PdoDriver.php',
'Dibi\Drivers\PostgreDriver' => 'Drivers/PostgreDriver.php', 'Dibi\Drivers\PostgreDriver' => 'Drivers/PostgreDriver.php',
'Dibi\Drivers\Sqlite3Driver' => 'Drivers/Sqlite3Driver.php', 'Dibi\Drivers\Sqlite3Driver' => 'Drivers/Sqlite3Driver.php',
'Dibi\Drivers\SqliteReflector' => 'Drivers/SqliteReflector.php', 'Dibi\Drivers\SqliteReflector' => 'Drivers/SqliteReflector.php',
'Dibi\Drivers\SqlsrvDriver' => 'Drivers/SqlsrvDriver.php',
'Dibi\Drivers\SqlsrvReflector' => 'Drivers/SqlsrvReflector.php',
'Dibi\Event' => 'Event.php', 'Dibi\Event' => 'Event.php',
'Dibi\Exception' => 'exceptions.php', 'Dibi\Exception' => 'exceptions.php',
'Dibi\Expression' => 'Expression.php',
'Dibi\Fluent' => 'Fluent.php', 'Dibi\Fluent' => 'Fluent.php',
'Dibi\ForeignKeyConstraintViolationException' => 'exceptions.php',
'Dibi\HashMap' => 'HashMap.php', 'Dibi\HashMap' => 'HashMap.php',
'Dibi\HashMapBase' => 'HashMap.php', 'Dibi\HashMapBase' => 'HashMap.php',
'Dibi\Helpers' => 'Helpers.php', 'Dibi\Helpers' => 'Helpers.php',
@@ -46,6 +49,7 @@ spl_autoload_register(function ($class) {
'Dibi\Loggers\FileLogger' => 'Loggers/FileLogger.php', 'Dibi\Loggers\FileLogger' => 'Loggers/FileLogger.php',
'Dibi\Loggers\FirePhpLogger' => 'Loggers/FirePhpLogger.php', 'Dibi\Loggers\FirePhpLogger' => 'Loggers/FirePhpLogger.php',
'Dibi\NotImplementedException' => 'exceptions.php', 'Dibi\NotImplementedException' => 'exceptions.php',
'Dibi\NotNullConstraintViolationException' => 'exceptions.php',
'Dibi\NotSupportedException' => 'exceptions.php', 'Dibi\NotSupportedException' => 'exceptions.php',
'Dibi\PcreException' => 'exceptions.php', 'Dibi\PcreException' => 'exceptions.php',
'Dibi\ProcedureException' => 'exceptions.php', 'Dibi\ProcedureException' => 'exceptions.php',
@@ -63,6 +67,7 @@ spl_autoload_register(function ($class) {
'Dibi\Strict' => 'Strict.php', 'Dibi\Strict' => 'Strict.php',
'Dibi\Translator' => 'Translator.php', 'Dibi\Translator' => 'Translator.php',
'Dibi\Type' => 'Type.php', 'Dibi\Type' => 'Type.php',
'Dibi\UniqueConstraintViolationException' => 'exceptions.php',
], $old2new = [ ], $old2new = [
'DibiColumnInfo' => 'Dibi\Reflection\Column', 'DibiColumnInfo' => 'Dibi\Reflection\Column',
'DibiConnection' => 'Dibi\Connection', 'DibiConnection' => 'Dibi\Connection',

View File

@@ -0,0 +1,41 @@
<?php
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
function buildPdoDriver($errorMode)
{
$pdo = new PDO('sqlite::memory:');
if ($errorMode !== null) {
$pdo->setAttribute(PDO::ATTR_ERRMODE, $errorMode);
}
$config = ['resource' => $pdo];
$driver = new Dibi\Drivers\PdoDriver;
$driver->connect($config);
}
// PDO error mode: exception
Assert::exception(function () {
buildPdoDriver(PDO::ERRMODE_EXCEPTION);
}, 'Dibi\DriverException', 'PDO connection in exception or warning error mode is not supported.');
// PDO error mode: warning
Assert::exception(function () {
buildPdoDriver(PDO::ERRMODE_WARNING);
}, 'Dibi\DriverException', 'PDO connection in exception or warning error mode is not supported.');
// PDO error mode: explicitly set silent
test(function () {
buildPdoDriver(PDO::ERRMODE_SILENT);
});
// PDO error mode: implicitly set silent
test(function () {
buildPdoDriver(null);
});

View File

@@ -99,6 +99,11 @@ test(function () {
Assert::same(['col' => 1.0], $result->test(['col' => 1])); Assert::same(['col' => 1.0], $result->test(['col' => 1]));
Assert::same(['col' => 1.0], $result->test(['col' => 1.0])); Assert::same(['col' => 1.0], $result->test(['col' => 1.0]));
Assert::same(['col' => '1.1e+10'], $result->test(['col' => '1.1e+10']));
Assert::same(['col' => '1.1e-10'], $result->test(['col' => '1.1e-10']));
Assert::same(['col' => '1.1e+10'], $result->test(['col' => '001.1e+10']));
Assert::notSame(['col' => '1.1e+1'], $result->test(['col' => '1.1e+10']));
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu'); setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
Assert::same(['col' => 0.0], $result->test(['col' => ''])); Assert::same(['col' => 0.0], $result->test(['col' => '']));
Assert::same(['col' => 0.0], $result->test(['col' => '0'])); Assert::same(['col' => 0.0], $result->test(['col' => '0']));

View File

@@ -15,7 +15,7 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
$e = Assert::exception(function () use ($conn) { $e = Assert::exception(function () use ($conn) {
$conn->query('SELECT'); $conn->query('SELECT');
}, 'Dibi\DriverException', '%a% syntax error', 1); }, 'Dibi\DriverException', '%a%', 1);
Assert::same('SELECT', $e->getSql()); Assert::same('SELECT', $e->getSql());