mirror of
https://github.com/dg/dibi.git
synced 2025-08-30 09:19:48 +02:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d571460a6f | ||
|
dc3e1cda19 | ||
|
21039ff379 | ||
|
22b15d9859 | ||
|
6aa8a431c2 | ||
|
69ea60cc16 | ||
|
906e1f2407 | ||
|
6a4f77b684 | ||
|
689597a237 | ||
|
a8ed2a34e5 | ||
|
c8e5f5c8d1 | ||
|
4bfd314225 | ||
|
2b4ea9abe7 | ||
|
3711b1739f | ||
|
45d7e0b365 | ||
|
7d07db1f12 | ||
|
34bdd5f267 |
15
.travis.yml
15
.travis.yml
@@ -6,6 +6,11 @@ php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
|
||||
before_install:
|
||||
# turn off XDebug
|
||||
@@ -33,12 +38,12 @@ jobs:
|
||||
php: 7.1
|
||||
install:
|
||||
# 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
|
||||
- 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:
|
||||
- php temp/code-checker/src/code-checker.php --short-arrays
|
||||
- php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.neon
|
||||
- php temp/code-checker/code-checker
|
||||
- php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.yml
|
||||
|
||||
|
||||
- stage: Code Coverage
|
||||
@@ -63,3 +68,5 @@ cache:
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
dist: trusty
|
||||
|
@@ -1,4 +1,4 @@
|
||||
[Dibi](https://dibiphp.com) - smart database layer for PHP [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
|
||||
[Dibi](https://dibiphp.com) - smart database layer for PHP [](https://nette.org/make-donation?to=dibi)
|
||||
=========================================================
|
||||
|
||||
[](https://packagist.org/packages/dibi/dibi)
|
||||
@@ -14,6 +14,8 @@ Introduction
|
||||
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.
|
||||
|
||||
If you like Dibi, **[please make a donation now](https://nette.org/make-donation?to=dibi)**. Thank you!
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
@@ -50,7 +50,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
||||
}
|
||||
|
||||
$connection = $container->addDefinition($this->prefix('connection'))
|
||||
->setClass('Dibi\Connection', [$config])
|
||||
->setFactory('Dibi\Connection', [$config])
|
||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : true);
|
||||
|
||||
if (class_exists('Tracy\Debugger')) {
|
||||
@@ -61,7 +61,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
||||
}
|
||||
if ($useProfiler) {
|
||||
$panel = $container->addDefinition($this->prefix('panel'))
|
||||
->setClass('Dibi\Bridges\Tracy\Panel', [
|
||||
->setFactory('Dibi\Bridges\Tracy\Panel', [
|
||||
isset($config['explain']) ? $config['explain'] : true,
|
||||
isset($config['filter']) && $config['filter'] === false ? Dibi\Event::ALL : Dibi\Event::QUERY,
|
||||
]);
|
||||
|
@@ -22,7 +22,7 @@ class DateTime extends \DateTime
|
||||
{
|
||||
if (is_numeric($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) {
|
||||
parent::__construct($time);
|
||||
} else {
|
||||
|
@@ -19,6 +19,7 @@ use Dibi;
|
||||
* - password (or pass)
|
||||
* - persistent (bool) => try to find a persistent link?
|
||||
* - resource (resource) => existing connection resource
|
||||
* - microseconds (bool) => use microseconds in datetime format?
|
||||
*/
|
||||
class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
{
|
||||
@@ -33,6 +34,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/** @var bool */
|
||||
private $autoFree = true;
|
||||
|
||||
/** @var bool */
|
||||
private $microseconds = true;
|
||||
|
||||
/** @var int|false Affected rows */
|
||||
private $affectedRows = false;
|
||||
|
||||
@@ -78,6 +82,10 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
if (!is_resource($this->connection)) {
|
||||
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) {
|
||||
$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#');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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->serverVersion = isset($config['version'])
|
||||
? $config['version']
|
||||
@@ -148,7 +152,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
{
|
||||
return $this->connection->lastInsertId();
|
||||
return $this->connection->lastInsertId($sequence);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -548,7 +548,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
$res = $this->query($query);
|
||||
$tables = pg_fetch_all($res->resultSet);
|
||||
return $tables ? $tables : [];
|
||||
return $tables ?: [];
|
||||
}
|
||||
|
||||
|
||||
|
@@ -445,11 +445,12 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
$columns = [];
|
||||
static $types = [SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null'];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$type = $this->resultSet->columnType($i); // buggy in PHP 7.4.4 & 7.3.16, bug 79414
|
||||
$columns[] = [
|
||||
'name' => $this->resultSet->columnName($i),
|
||||
'table' => null,
|
||||
'fullname' => $this->resultSet->columnName($i),
|
||||
'nativetype' => $types[$this->resultSet->columnType($i)],
|
||||
'nativetype' => $type ? $types[$type] : null,
|
||||
];
|
||||
}
|
||||
return $columns;
|
||||
|
@@ -13,7 +13,7 @@ namespace Dibi;
|
||||
*
|
||||
* @method Fluent select(...$field)
|
||||
* @method Fluent distinct()
|
||||
* @method Fluent from($table, ...$args)
|
||||
* @method Fluent from($table, ...$args = null)
|
||||
* @method Fluent where(...$cond)
|
||||
* @method Fluent groupBy(...$field)
|
||||
* @method Fluent having(...$cond)
|
||||
|
@@ -498,8 +498,11 @@ class Result implements IDataSource
|
||||
} elseif ($type === Type::FLOAT) {
|
||||
$value = ltrim((string) $value, '0');
|
||||
$p = strpos($value, '.');
|
||||
if ($p !== false) {
|
||||
$e = strpos($value, 'e');
|
||||
if ($p !== false && $e === false) {
|
||||
$value = rtrim(rtrim($value, '0'), '.');
|
||||
} elseif ($p !== false && $e !== false) {
|
||||
$value = rtrim($value, '.');
|
||||
}
|
||||
if ($value === '' || $value[0] === '.') {
|
||||
$value = '0' . $value;
|
||||
@@ -526,6 +529,9 @@ class Result implements IDataSource
|
||||
|
||||
} elseif ($type === Type::BINARY) {
|
||||
$row[$key] = $this->getResultDriver()->unescapeBinary($value);
|
||||
|
||||
} else {
|
||||
$row[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,8 +21,8 @@ class dibi
|
||||
|
||||
/** version */
|
||||
const
|
||||
VERSION = '3.2.2',
|
||||
REVISION = 'released on 2018-05-02';
|
||||
VERSION = '3.2.4',
|
||||
REVISION = 'released on 2020-03-26';
|
||||
|
||||
/** sorting order */
|
||||
const
|
||||
|
@@ -17,27 +17,30 @@ spl_autoload_register(function ($class) {
|
||||
'Dibi\Bridges\Nette\DibiExtension22' => 'Bridges/Nette/DibiExtension22.php',
|
||||
'Dibi\Bridges\Tracy\Panel' => 'Bridges/Tracy/Panel.php',
|
||||
'Dibi\Connection' => 'Connection.php',
|
||||
'Dibi\ConstraintViolationException' => 'exceptions.php',
|
||||
'Dibi\DataSource' => 'DataSource.php',
|
||||
'Dibi\DateTime' => 'DateTime.php',
|
||||
'Dibi\Driver' => 'interfaces.php',
|
||||
'Dibi\DriverException' => 'exceptions.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\MsSqlReflector' => 'Drivers/MsSqlReflector.php',
|
||||
'Dibi\Drivers\MySqlDriver' => 'Drivers/MySqlDriver.php',
|
||||
'Dibi\Drivers\MySqliDriver' => 'Drivers/MySqliDriver.php',
|
||||
'Dibi\Drivers\MySqlReflector' => 'Drivers/MySqlReflector.php',
|
||||
'Dibi\Drivers\MySqliDriver' => 'Drivers/MySqliDriver.php',
|
||||
'Dibi\Drivers\OdbcDriver' => 'Drivers/OdbcDriver.php',
|
||||
'Dibi\Drivers\OracleDriver' => 'Drivers/OracleDriver.php',
|
||||
'Dibi\Drivers\PdoDriver' => 'Drivers/PdoDriver.php',
|
||||
'Dibi\Drivers\PostgreDriver' => 'Drivers/PostgreDriver.php',
|
||||
'Dibi\Drivers\Sqlite3Driver' => 'Drivers/Sqlite3Driver.php',
|
||||
'Dibi\Drivers\SqliteReflector' => 'Drivers/SqliteReflector.php',
|
||||
'Dibi\Drivers\SqlsrvDriver' => 'Drivers/SqlsrvDriver.php',
|
||||
'Dibi\Drivers\SqlsrvReflector' => 'Drivers/SqlsrvReflector.php',
|
||||
'Dibi\Event' => 'Event.php',
|
||||
'Dibi\Exception' => 'exceptions.php',
|
||||
'Dibi\Expression' => 'Expression.php',
|
||||
'Dibi\Fluent' => 'Fluent.php',
|
||||
'Dibi\ForeignKeyConstraintViolationException' => 'exceptions.php',
|
||||
'Dibi\HashMap' => 'HashMap.php',
|
||||
'Dibi\HashMapBase' => 'HashMap.php',
|
||||
'Dibi\Helpers' => 'Helpers.php',
|
||||
@@ -46,6 +49,7 @@ spl_autoload_register(function ($class) {
|
||||
'Dibi\Loggers\FileLogger' => 'Loggers/FileLogger.php',
|
||||
'Dibi\Loggers\FirePhpLogger' => 'Loggers/FirePhpLogger.php',
|
||||
'Dibi\NotImplementedException' => 'exceptions.php',
|
||||
'Dibi\NotNullConstraintViolationException' => 'exceptions.php',
|
||||
'Dibi\NotSupportedException' => 'exceptions.php',
|
||||
'Dibi\PcreException' => 'exceptions.php',
|
||||
'Dibi\ProcedureException' => 'exceptions.php',
|
||||
@@ -63,6 +67,7 @@ spl_autoload_register(function ($class) {
|
||||
'Dibi\Strict' => 'Strict.php',
|
||||
'Dibi\Translator' => 'Translator.php',
|
||||
'Dibi\Type' => 'Type.php',
|
||||
'Dibi\UniqueConstraintViolationException' => 'exceptions.php',
|
||||
], $old2new = [
|
||||
'DibiColumnInfo' => 'Dibi\Reflection\Column',
|
||||
'DibiConnection' => 'Dibi\Connection',
|
||||
|
41
tests/dibi/PdoDriver.providedConnection.phpt
Normal file
41
tests/dibi/PdoDriver.providedConnection.phpt
Normal 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);
|
||||
});
|
@@ -99,6 +99,11 @@ test(function () {
|
||||
Assert::same(['col' => 1.0], $result->test(['col' => 1]));
|
||||
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');
|
||||
Assert::same(['col' => 0.0], $result->test(['col' => '']));
|
||||
Assert::same(['col' => 0.0], $result->test(['col' => '0']));
|
||||
|
@@ -15,7 +15,7 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', '%a% syntax error', 1);
|
||||
}, 'Dibi\DriverException', '%a%', 1);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
Reference in New Issue
Block a user