mirror of
https://github.com/dg/dibi.git
synced 2025-09-10 06:10:52 +02:00
Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cec699af0f | ||
|
59a4cc2fe0 | ||
|
985f09417e | ||
|
729d133d70 | ||
|
759c63bca0 | ||
|
f9fc7e330d | ||
|
dbca915bfe | ||
|
1bae6eae08 | ||
|
34b7e22d40 | ||
|
369f5ee7d6 | ||
|
2d74bb3da0 | ||
|
a5422a65c9 | ||
|
5c806ea517 | ||
|
ecafed6246 | ||
|
504b7725c7 | ||
|
822405b478 | ||
|
43d3b57a8d | ||
|
4f0566ece7 | ||
|
67521084d9 | ||
|
22ac601502 | ||
|
b740b70f18 | ||
|
44fc3f4553 |
10
appveyor.yml
10
appveyor.yml
@@ -20,8 +20,8 @@ install:
|
||||
- IF EXIST c:\php5 (SET PHP=0) ELSE (SET PHP=1)
|
||||
- IF %PHP%==1 mkdir c:\php5
|
||||
- IF %PHP%==1 cd c:\php5
|
||||
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-5.6.14-Win32-VC11-x86.zip
|
||||
- IF %PHP%==1 7z x php-5.6.14-Win32-VC11-x86.zip >nul
|
||||
- IF %PHP%==1 curl https://windows.php.net/downloads/releases/archives/php-5.6.14-Win32-VC11-x86.zip --output php.zip
|
||||
- IF %PHP%==1 7z x php.zip >nul
|
||||
- IF %PHP%==1 echo extension_dir=ext >> php.ini
|
||||
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
|
||||
- IF %PHP%==1 appveyor DownloadFile https://files.nette.org/misc/php-sqlsrv.zip
|
||||
@@ -34,8 +34,8 @@ install:
|
||||
- IF EXIST c:\php7 (SET PHP=0) ELSE (SET PHP=1)
|
||||
- IF %PHP%==1 mkdir c:\php7
|
||||
- IF %PHP%==1 cd c:\php7
|
||||
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-7.0.3-Win32-VC14-x86.zip
|
||||
- IF %PHP%==1 7z x php-7.0.3-Win32-VC14-x86.zip >nul
|
||||
- IF %PHP%==1 curl https://windows.php.net/downloads/releases/archives/php-7.0.3-Win32-VC14-x86.zip --output php.zip
|
||||
- IF %PHP%==1 7z x php.zip >nul
|
||||
- IF %PHP%==1 echo extension_dir=ext >> php.ini
|
||||
- IF %PHP%==1 appveyor DownloadFile https://files.nette.org/misc/php-sqlsrv.zip
|
||||
- IF %PHP%==1 7z x php-sqlsrv.zip >nul
|
||||
@@ -56,4 +56,4 @@ test_script:
|
||||
|
||||
on_failure:
|
||||
# Print *.actual content
|
||||
- type tests\dibi\output\*.actual
|
||||
- for /r %%x in (*.actual) do ( type "%%x" )
|
||||
|
@@ -26,7 +26,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.1-dev"
|
||||
"dev-master": "3.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
// connects to SQlite using dibi class
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
@@ -6,7 +6,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
@@ -4,7 +4,9 @@
|
||||
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/loader.php';
|
||||
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
||||
die('Install packages using `composer install`');
|
||||
}
|
||||
|
||||
|
||||
dibi::connect([
|
||||
|
48
readme.md
48
readme.md
@@ -7,22 +7,28 @@
|
||||
[](https://github.com/dg/dibi/releases)
|
||||
[](https://github.com/dg/dibi/blob/master/license.md)
|
||||
|
||||
|
||||
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.
|
||||
|
||||
The best way to install Dibi is to use a [Composer](https://getcomposer.org/download):
|
||||
|
||||
php composer.phar require dibi/dibi
|
||||
Installation
|
||||
------------
|
||||
|
||||
Or you can download the latest package from https://dibiphp.com. In this
|
||||
package is also `Dibi.minified`, shrinked single-file version of whole Dibi,
|
||||
useful when you don't want to modify the library, but just use it.
|
||||
The recommended way to install Dibi is via Composer (alternatively you can [download package](https://github.com/dg/dibi/releases)):
|
||||
|
||||
Dibi requires PHP 5.4.4 or later. It has been tested with PHP 7 too.
|
||||
```bash
|
||||
composer require dibi/dibi
|
||||
```
|
||||
|
||||
The Dibi 3.x requires PHP version 5.4.4 and supports PHP up to 7.2.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
Usage
|
||||
-----
|
||||
|
||||
Refer to the `examples` directory for examples. Dibi documentation is
|
||||
available on the [homepage](https://dibiphp.com).
|
||||
@@ -30,34 +36,34 @@ available on the [homepage](https://dibiphp.com).
|
||||
Connect to database:
|
||||
|
||||
```php
|
||||
// connect to database (static way)
|
||||
dibi::connect([
|
||||
'driver' => 'mysql',
|
||||
$dibi = new Dibi\Connection([
|
||||
'driver' => 'mysqli',
|
||||
'host' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => '***',
|
||||
]);
|
||||
|
||||
// or object way; in all other examples use $connection-> instead of dibi::
|
||||
$connection = new DibiConnection($options);
|
||||
|
||||
// or static way; in all other examples use dibi:: instead of $dibi->
|
||||
dibi::connect($options);
|
||||
```
|
||||
|
||||
SELECT, INSERT, UPDATE
|
||||
|
||||
```php
|
||||
dibi::query('SELECT * FROM users WHERE id = ?', $id);
|
||||
$dibi->query('SELECT * FROM users WHERE id = ?', $id);
|
||||
|
||||
$arr = [
|
||||
'name' => 'John',
|
||||
'is_admin' => true,
|
||||
];
|
||||
dibi::query('INSERT INTO users', $arr);
|
||||
$dibi->query('INSERT INTO users', $arr);
|
||||
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
|
||||
|
||||
dibi::query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
|
||||
$dibi->query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
|
||||
// UPDATE users SET `name`='John', `is_admin`=1 WHERE `id` = 123
|
||||
|
||||
dibi::query('UPDATE users SET', [
|
||||
$dibi->query('UPDATE users SET', [
|
||||
'title' => array('SHA1(?)', 'tajneheslo'),
|
||||
]);
|
||||
// UPDATE users SET 'title' = SHA1('tajneheslo')
|
||||
@@ -66,7 +72,7 @@ dibi::query('UPDATE users SET', [
|
||||
Getting results
|
||||
|
||||
```php
|
||||
$result = dibi::query('SELECT * FROM users');
|
||||
$result = $dibi->query('SELECT * FROM users');
|
||||
|
||||
$value = $result->fetchSingle(); // single value
|
||||
$all = $result->fetchAll(); // all rows
|
||||
@@ -82,7 +88,7 @@ foreach ($result as $n => $row) {
|
||||
Modifiers for arrays:
|
||||
|
||||
```php
|
||||
dibi::query('SELECT * FROM users WHERE %and', [
|
||||
$dibi->query('SELECT * FROM users WHERE %and', [
|
||||
array('number > ?', 10),
|
||||
array('number < ?', 100),
|
||||
]);
|
||||
@@ -105,7 +111,7 @@ dibi::query('SELECT * FROM users WHERE %and', [
|
||||
Modifiers for LIKE
|
||||
|
||||
```php
|
||||
dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
|
||||
$dibi->query("SELECT * FROM table WHERE name LIKE %like~", $query);
|
||||
```
|
||||
|
||||
<table>
|
||||
@@ -117,7 +123,7 @@ dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
|
||||
DateTime:
|
||||
|
||||
```php
|
||||
dibi::query('UPDATE users SET', [
|
||||
$dibi->query('UPDATE users SET', [
|
||||
'time' => new DateTime,
|
||||
]);
|
||||
// UPDATE users SET ('2008-01-01 01:08:10')
|
||||
|
@@ -313,7 +313,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
}
|
||||
return $value->format("'Y-m-d H:i:s.u'");
|
||||
return "'" . substr($value->format('Y-m-d H:i:s.u'), 0, -2) . "'";
|
||||
}
|
||||
|
||||
|
||||
|
@@ -263,7 +263,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
}
|
||||
return $value->format("'Y-m-d H:i:s.u'");
|
||||
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
|
||||
}
|
||||
|
||||
|
||||
|
@@ -33,7 +33,9 @@ class MySqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
use Dibi\Strict;
|
||||
|
||||
const ERROR_ACCESS_DENIED = 1045;
|
||||
|
||||
const ERROR_DUPLICATE_ENTRY = 1062;
|
||||
|
||||
const ERROR_DATA_TRUNCATED = 1265;
|
||||
|
||||
/** @var resource|null */
|
||||
|
@@ -34,7 +34,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
use Dibi\Strict;
|
||||
|
||||
const ERROR_ACCESS_DENIED = 1045;
|
||||
|
||||
const ERROR_DUPLICATE_ENTRY = 1062;
|
||||
|
||||
const ERROR_DATA_TRUNCATED = 1265;
|
||||
|
||||
/** @var \mysqli|null */
|
||||
@@ -148,7 +150,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
$res = @mysqli_query($this->connection, $sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
|
||||
|
||||
if ($code = mysqli_errno($this->connection)) {
|
||||
throw self::createException(mysqli_error($this->connection), $code, $sql);
|
||||
throw static::createException(mysqli_error($this->connection), $code, $sql);
|
||||
|
||||
} elseif (is_object($res)) {
|
||||
return $this->createResultDriver($res);
|
||||
|
@@ -42,6 +42,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/** @var string Date and datetime format */
|
||||
private $fmtDate;
|
||||
|
||||
private $fmtDateTime;
|
||||
|
||||
/** @var int|false Number of affected rows */
|
||||
@@ -119,7 +120,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
||||
$err = oci_error($res);
|
||||
if ($err) {
|
||||
throw self::createException($err['message'], $err['code'], $sql);
|
||||
throw static::createException($err['message'], $err['code'], $sql);
|
||||
|
||||
} elseif (is_resource($res)) {
|
||||
$this->affectedRows = oci_num_rows($res);
|
||||
|
@@ -104,23 +104,14 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
// must detect if SQL returns result set or num of affected rows
|
||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
|
||||
$this->affectedRows = false;
|
||||
|
||||
if (isset($list[$cmd])) {
|
||||
$this->affectedRows = $this->connection->exec($sql);
|
||||
if ($this->affectedRows !== false) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$res = $this->connection->query($sql);
|
||||
if ($res) {
|
||||
return $this->createResultDriver($res);
|
||||
}
|
||||
$res = $this->connection->query($sql);
|
||||
if ($res) {
|
||||
$this->affectedRows = $res->rowCount();
|
||||
return $res->columnCount() ? $this->createResultDriver($res) : null;
|
||||
}
|
||||
|
||||
$this->affectedRows = false;
|
||||
|
||||
list($sqlState, $code, $message) = $this->connection->errorInfo();
|
||||
$message = "SQLSTATE[$sqlState]: $message";
|
||||
switch ($this->driverName) {
|
||||
@@ -348,7 +339,15 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
}
|
||||
return $value->format($this->driverName === 'odbc' ? '#m/d/Y H:i:s.u#' : "'Y-m-d H:i:s.u'");
|
||||
switch ($this->driverName) {
|
||||
case 'odbc':
|
||||
return $value->format('#m/d/Y H:i:s.u#');
|
||||
case 'mssql':
|
||||
case 'sqlsrv':
|
||||
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
|
||||
default:
|
||||
return $value->format("'Y-m-d H:i:s.u'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -96,7 +96,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
pg_set_error_verbosity($this->connection, PGSQL_ERRORS_VERBOSE);
|
||||
|
||||
if (isset($config['charset']) && pg_set_client_encoding($this->connection, $config['charset'])) {
|
||||
throw self::createException(pg_last_error($this->connection));
|
||||
throw static::createException(pg_last_error($this->connection));
|
||||
}
|
||||
|
||||
if (isset($config['schema'])) {
|
||||
@@ -137,7 +137,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
$res = @pg_query($this->connection, $sql); // intentionally @
|
||||
|
||||
if ($res === false) {
|
||||
throw self::createException(pg_last_error($this->connection), null, $sql);
|
||||
throw static::createException(pg_last_error($this->connection), null, $sql);
|
||||
|
||||
} elseif (is_resource($res)) {
|
||||
$this->affectedRows = pg_affected_rows($res);
|
||||
|
@@ -38,10 +38,12 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/** @var string Date and datetime format */
|
||||
private $fmtDate;
|
||||
|
||||
private $fmtDateTime;
|
||||
|
||||
/** @var string character encoding */
|
||||
private $dbcharset;
|
||||
|
||||
private $charset;
|
||||
|
||||
|
||||
@@ -115,7 +117,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
$res = @$this->connection->query($sql); // intentionally @
|
||||
if ($code = $this->connection->lastErrorCode()) {
|
||||
throw self::createException($this->connection->lastErrorMsg(), $code, $sql);
|
||||
throw static::createException($this->connection->lastErrorMsg(), $code, $sql);
|
||||
|
||||
} elseif ($res instanceof \SQLite3Result && $res->numColumns()) {
|
||||
return $this->createResultDriver($res);
|
||||
|
@@ -8,7 +8,6 @@
|
||||
namespace Dibi\Drivers;
|
||||
|
||||
use Dibi;
|
||||
use Dibi\Connection;
|
||||
use Dibi\Helpers;
|
||||
|
||||
|
||||
@@ -287,7 +286,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
}
|
||||
return $value->format("'Y-m-d H:i:s.u'");
|
||||
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
|
||||
}
|
||||
|
||||
|
||||
|
@@ -8,7 +8,6 @@
|
||||
namespace Dibi\Reflection;
|
||||
|
||||
use Dibi;
|
||||
use Dibi\Type;
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -315,7 +315,11 @@ final class Translator
|
||||
if ($modifier) {
|
||||
if ($value !== null && !is_scalar($value)) { // array is already processed
|
||||
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
|
||||
$modifier = 'SQL';
|
||||
return (string) $value;
|
||||
|
||||
} elseif ($value instanceof Expression && $modifier === 'ex') {
|
||||
return call_user_func_array([$this->connection, 'translate'], $value->getValues());
|
||||
|
||||
} elseif (($value instanceof \DateTime || $value instanceof \DateTimeInterface) && ($modifier === 'd' || $modifier === 't' || $modifier === 'dt')) {
|
||||
// continue
|
||||
} else {
|
||||
|
@@ -22,8 +22,8 @@ class dibi
|
||||
|
||||
/** version */
|
||||
const
|
||||
VERSION = '3.1.0',
|
||||
REVISION = 'released on 2017-09-25';
|
||||
VERSION = '3.2.1',
|
||||
REVISION = 'released on 2018-04-14';
|
||||
|
||||
/** sorting order */
|
||||
const
|
||||
@@ -64,7 +64,7 @@ class dibi
|
||||
/** @var string Default dibi driver */
|
||||
public static $defaultDriver = 'mysqli';
|
||||
|
||||
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
|
||||
/** @var Dibi\Connection[] Connection registry storage for Dibi\Connection objects */
|
||||
private static $registry = [];
|
||||
|
||||
/** @var Dibi\Connection Current connection */
|
||||
|
@@ -22,10 +22,11 @@ class Exception extends \Exception
|
||||
* @param string Message describing the exception
|
||||
* @param mixed
|
||||
* @param string SQL command
|
||||
* @param \Exception
|
||||
*/
|
||||
public function __construct($message = '', $code = 0, $sql = null)
|
||||
public function __construct($message = '', $code = 0, $sql = null, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message);
|
||||
parent::__construct($message, 0, $previous);
|
||||
$this->code = $code;
|
||||
$this->sql = $sql;
|
||||
}
|
||||
|
@@ -64,7 +64,6 @@ spl_autoload_register(function ($class) {
|
||||
'Dibi\Translator' => 'Translator.php',
|
||||
'Dibi\Type' => 'Type.php',
|
||||
], $old2new = [
|
||||
'Dibi' => 'dibi.php',
|
||||
'DibiColumnInfo' => 'Dibi\Reflection\Column',
|
||||
'DibiConnection' => 'Dibi\Connection',
|
||||
'DibiDatabaseInfo' => 'Dibi\Reflection\Database',
|
||||
@@ -115,26 +114,9 @@ spl_autoload_register(function ($class) {
|
||||
if (isset($map[$class])) {
|
||||
require __DIR__ . '/Dibi/' . $map[$class];
|
||||
} elseif (isset($old2new[$class])) {
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
$location = isset($trace[1]['file']) ? 'used in ' . $trace[1]['file'] . ':' . $trace[1]['line'] : '';
|
||||
trigger_error("Class $class $location has been renamed to {$old2new[$class]}.", E_USER_DEPRECATED);
|
||||
class_alias($old2new[$class], $class);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// preload for compatiblity
|
||||
array_map('class_exists', [
|
||||
'DibiConnection',
|
||||
'DibiDateTime',
|
||||
'DibiDriverException',
|
||||
'DibiEvent',
|
||||
'DibiException',
|
||||
'DibiFluent',
|
||||
'DibiLiteral',
|
||||
'DibiNotImplementedException',
|
||||
'DibiNotSupportedException',
|
||||
'DibiPcreException',
|
||||
'DibiProcedureException',
|
||||
'DibiResult',
|
||||
'DibiRow',
|
||||
'IDataSource',
|
||||
'IDibiDriver',
|
||||
]);
|
||||
|
@@ -181,6 +181,8 @@ if ($config['system'] === 'odbc') {
|
||||
Assert::same(
|
||||
reformat([
|
||||
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES (#09/26/1212 00:00:00.000000#, #12/31/1969 22:13:20.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, #12/31/1969#, #12/31/1969 22:13:20.000000#, #09/26/1212 00:00:00.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, NULL, NULL, #09/26/1212 16:51:34.012400#)',
|
||||
'mssql' => "INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES (CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), CONVERT(DATETIME2(7), '1969-12-31 22:13:20.000000'), '1212-09-26', CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), '1969-12-31', CONVERT(DATETIME2(7), '1969-12-31 22:13:20.000000'), CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), '1212-09-26', CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), NULL, NULL, CONVERT(DATETIME2(7), '1212-09-26 16:51:34.012400'))",
|
||||
'sqlsrv' => "INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES (CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), CONVERT(DATETIME2(7), '1969-12-31 22:13:20.000000'), '1212-09-26', CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), '1969-12-31', CONVERT(DATETIME2(7), '1969-12-31 22:13:20.000000'), CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), '1212-09-26', CONVERT(DATETIME2(7), '1212-09-26 00:00:00.000000'), NULL, NULL, CONVERT(DATETIME2(7), '1212-09-26 16:51:34.012400'))",
|
||||
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES ('1212-09-26 00:00:00.000000', '1969-12-31 22:13:20.000000', '1212-09-26', '1212-09-26 00:00:00.000000', '1969-12-31', '1969-12-31 22:13:20.000000', '1212-09-26 00:00:00.000000', '1212-09-26', '1212-09-26 00:00:00.000000', NULL, NULL, '1212-09-26 16:51:34.012400')",
|
||||
]),
|
||||
$conn->translate('INSERT INTO test', [
|
||||
@@ -503,6 +505,18 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [table] WHERE (([left] = 1) OR ([top] = 2)) AND (number < 100)'),
|
||||
$conn->translate('SELECT * FROM `table` WHERE %and', [
|
||||
new Dibi\Expression('%or', [
|
||||
'left' => 1,
|
||||
'top' => 2,
|
||||
]),
|
||||
new Dibi\Expression('number < %i', 100),
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$array6 = [
|
||||
'id' => [1, 2, 3, 4],
|
||||
|
@@ -40,9 +40,6 @@ if ($config['driver'] === 'mysql' && PHP_VERSION_ID >= 70000) {
|
||||
}
|
||||
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
|
||||
|
||||
function test(Closure $function)
|
||||
{
|
||||
$function();
|
||||
|
Reference in New Issue
Block a user