mirror of
https://github.com/dg/dibi.git
synced 2025-09-04 03:35:26 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4f2a0dac97 | ||
|
a13eb6f3d1 | ||
|
e3f01c879f | ||
|
efae5808f0 | ||
|
6a8a136c0a | ||
|
bbb654fc27 | ||
|
b6933815c7 | ||
|
a8691eb8f5 | ||
|
0cce3b9916 | ||
|
98d1b2a519 |
@@ -2,7 +2,7 @@
|
||||
"name": "dibi/dibi",
|
||||
"description": "Dibi is Database Abstraction Library for PHP",
|
||||
"keywords": ["database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "sqlsrv", "oracle", "access", "pdo", "odbc"],
|
||||
"homepage": "http://dibiphp.com",
|
||||
"homepage": "https://dibiphp.com",
|
||||
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@ The issue tracker is the preferred channel for bug reports, features requests
|
||||
and submitting pull requests, but please respect the following restrictions:
|
||||
|
||||
* Please **do not** use the issue tracker for personal support requests (use
|
||||
[dibi forum](http://forum.dibiphp.com) or [Stack Overflow](http://stackoverflow.com)).
|
||||
[dibi forum](https://forum.dibiphp.com) or [Stack Overflow](http://stackoverflow.com)).
|
||||
|
||||
* Please **do not** derail or troll issues. Keep the discussion on topic and
|
||||
respect the opinions of others.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
[Dibi](http://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://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
|
||||
=========================================================
|
||||
|
||||
[](https://packagist.org/packages/dibi/dibi)
|
||||
@@ -14,7 +14,7 @@ The best way to install Dibi is to use a [Composer](https://getcomposer.org/down
|
||||
|
||||
php composer.phar require dibi/dibi
|
||||
|
||||
Or you can download the latest package from http://dibiphp.com. In this
|
||||
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.
|
||||
|
||||
@@ -25,7 +25,7 @@ Examples
|
||||
--------
|
||||
|
||||
Refer to the `examples` directory for examples. Dibi documentation is
|
||||
available on the [homepage](http://dibiphp.com).
|
||||
available on the [homepage](https://dibiphp.com).
|
||||
|
||||
Connect to database:
|
||||
|
||||
|
@@ -545,7 +545,7 @@ class Connection
|
||||
{
|
||||
return strpos($value, ':') === FALSE
|
||||
? $value
|
||||
: preg_replace_callback('#:([^:\s]*):#', function ($m) { $this->substitutes->{$m[1]}; }, $value);
|
||||
: preg_replace_callback('#:([^:\s]*):#', function ($m) { return $this->substitutes->{$m[1]}; }, $value);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -172,9 +172,6 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
} elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) {
|
||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||
|
||||
} elseif ($code >= 2001 && $code <= 2028) {
|
||||
return new Dibi\ConnectionException($message, $code, $sql);
|
||||
|
||||
} elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) {
|
||||
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
||||
|
||||
|
@@ -67,7 +67,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
if ($config['resource'] instanceof PDO) {
|
||||
$this->connection = $config['resource'];
|
||||
|
||||
unset($config['resource'], $config['pdo']);
|
||||
} else {
|
||||
try {
|
||||
$this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
|
||||
|
@@ -184,7 +184,7 @@ class Helpers
|
||||
'^_' => Type::TEXT, // PostgreSQL arrays
|
||||
'BYTEA|BLOB|BIN' => Type::BINARY,
|
||||
'TEXT|CHAR|POINT|INTERVAL' => Type::TEXT,
|
||||
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT' => Type::INTEGER,
|
||||
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => Type::INTEGER,
|
||||
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => Type::FLOAT,
|
||||
'^TIME$' => Type::TIME,
|
||||
'TIME' => Type::DATETIME, // DATETIME, TIMESTAMP
|
||||
|
@@ -116,6 +116,19 @@ trait Strict
|
||||
list($class, $name) = explode('::', $name);
|
||||
$class = (new ReflectionClass($class))->getName();
|
||||
}
|
||||
|
||||
if (self::$extMethods === NULL) { // for backwards compatibility
|
||||
$list = get_defined_functions();
|
||||
foreach ($list['user'] as $fce) {
|
||||
$pair = explode('_prototype_', $fce);
|
||||
if (count($pair) === 2) {
|
||||
trigger_error("Extension method defined as $fce() is deprecated, use $class::extensionMethod('$name', ...).", E_USER_DEPRECATED);
|
||||
self::$extMethods[$pair[1]][(new ReflectionClass($pair[0]))->getName()] = $fce;
|
||||
self::$extMethods[$pair[1]][''] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$list = & self::$extMethods[strtolower($name)];
|
||||
if ($callback === NULL) { // getter
|
||||
$cache = & $list[''][$class];
|
||||
|
@@ -372,6 +372,7 @@ final class Translator
|
||||
|
||||
case 'd': // date
|
||||
case 't': // datetime
|
||||
case 'dt': // datetime
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
} else {
|
||||
|
@@ -22,8 +22,8 @@ class dibi
|
||||
|
||||
/** version */
|
||||
const
|
||||
VERSION = '3.0.0',
|
||||
REVISION = 'released on 2015-11-07';
|
||||
VERSION = '3.0.1',
|
||||
REVISION = 'released on 2015-12-16';
|
||||
|
||||
/** sorting order */
|
||||
const
|
||||
|
@@ -11,16 +11,46 @@ $conn = new Dibi\Connection($config);
|
||||
$conn->getSubstitutes()->blog = 'wp_';
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE wp_items SET [text]=\'Hello World\''),
|
||||
$conn->translate("UPDATE :blog:items SET [text]='Hello World'")
|
||||
reformat('UPDATE wp_items SET [val]=1'),
|
||||
$conn->translate('UPDATE :blog:items SET [val]=1')
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE \'wp_\' SET [text]=\'Hello World\''),
|
||||
$conn->translate("UPDATE :blog: SET [text]='Hello World'")
|
||||
reformat('UPDATE [wp_items] SET [val]=1'),
|
||||
$conn->translate('UPDATE [:blog:items] SET [val]=1')
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE \':blg:\' SET [text]=\'Hello World\''),
|
||||
$conn->translate("UPDATE :blg: SET [text]='Hello World'")
|
||||
reformat("UPDATE 'wp_' SET [val]=1"),
|
||||
$conn->translate('UPDATE :blog: SET [val]=1')
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat("UPDATE ':blg:' SET [val]=1"),
|
||||
$conn->translate('UPDATE :blg: SET [val]=1')
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat("UPDATE table SET [text]=':blog:a'"),
|
||||
$conn->translate("UPDATE table SET [text]=':blog:a'")
|
||||
);
|
||||
|
||||
|
||||
// create new substitution :: (empty) ==> my_
|
||||
$conn->getSubstitutes()->{''} = 'my_';
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE my_table SET [val]=1'),
|
||||
$conn->translate('UPDATE ::table SET [val]=1')
|
||||
);
|
||||
|
||||
|
||||
// create substitutions using fallback callback
|
||||
$conn->getSubstitutes()->setCallback(function ($expr) {
|
||||
return '_' . $expr . '_';
|
||||
});
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE _account_user SET [val]=1'),
|
||||
$conn->translate('UPDATE :account:user SET [val]=1')
|
||||
);
|
||||
|
Reference in New Issue
Block a user