mirror of
https://github.com/dg/dibi.git
synced 2025-08-30 01:09:50 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fc5e7db484 | ||
|
44b420f70d | ||
|
4689101b88 | ||
|
db16b9e87a | ||
|
803c9d539c | ||
|
e137dfa28b | ||
|
9651835f5b | ||
|
2cbebc02c4 | ||
|
4d647c2aed | ||
|
5c5838aee4 | ||
|
7df72fd6cf |
@@ -3,6 +3,11 @@ php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
|
||||
before_install:
|
||||
# turn off XDebug
|
||||
|
@@ -26,7 +26,7 @@ Install Dibi via Composer:
|
||||
composer require dibi/dibi
|
||||
```
|
||||
|
||||
The Dibi 4.0 requires PHP version 7.1 and supports PHP up to 7.2. Older Dibi 3.x requires PHP 5.4 and supports PHP up to 7.2.
|
||||
The Dibi 4.0 requires PHP version 7.1 and supports PHP up to 7.4.
|
||||
|
||||
|
||||
Usage
|
||||
|
@@ -119,6 +119,7 @@ class Connection implements IConnection
|
||||
{
|
||||
if ($this->config['driver'] instanceof Driver) {
|
||||
$this->driver = $this->config['driver'];
|
||||
$this->translator = new Translator($this);
|
||||
return;
|
||||
|
||||
} elseif (is_subclass_of($this->config['driver'], Driver::class)) {
|
||||
@@ -135,6 +136,8 @@ class Connection implements IConnection
|
||||
$event = $this->onEvent ? new Event($this, Event::CONNECT) : null;
|
||||
try {
|
||||
$this->driver = new $class($this->config);
|
||||
$this->translator = new Translator($this);
|
||||
|
||||
if ($event) {
|
||||
$this->onEvent($event->done());
|
||||
}
|
||||
@@ -160,7 +163,7 @@ class Connection implements IConnection
|
||||
{
|
||||
if ($this->driver) {
|
||||
$this->driver->disconnect();
|
||||
$this->driver = null;
|
||||
$this->driver = $this->translator = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,11 +264,7 @@ class Connection implements IConnection
|
||||
if (!$this->driver) {
|
||||
$this->connect();
|
||||
}
|
||||
if (!$this->translator) {
|
||||
$this->translator = new Translator($this);
|
||||
}
|
||||
$translator = clone $this->translator;
|
||||
return $translator->translate($args);
|
||||
return (clone $this->translator)->translate($args);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -93,7 +93,7 @@ class MySqliDriver implements Dibi\Driver
|
||||
@$this->connection->real_connect( // intentionally @
|
||||
(empty($config['persistent']) ? '' : 'p:') . $config['host'],
|
||||
$config['username'],
|
||||
$config['password'],
|
||||
$config['password'] ?? '',
|
||||
$config['database'] ?? '',
|
||||
$config['port'] ?? 0,
|
||||
$config['socket'],
|
||||
|
@@ -96,7 +96,7 @@ class SqliteResult implements Dibi\ResultDriver
|
||||
'name' => $this->resultSet->columnName($i),
|
||||
'table' => null,
|
||||
'fullname' => $this->resultSet->columnName($i),
|
||||
'nativetype' => $types[$this->resultSet->columnType($i)],
|
||||
'nativetype' => $types[$this->resultSet->columnType($i)] ?? null, // buggy in PHP 7.4.4 & 7.3.16, bug 79414
|
||||
];
|
||||
}
|
||||
return $columns;
|
||||
|
@@ -65,11 +65,13 @@ class SqlsrvDriver implements Dibi\Driver
|
||||
$options['UID'] = (string) $options['UID'];
|
||||
$options['Database'] = (string) $options['Database'];
|
||||
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
||||
$this->connection = sqlsrv_connect($config['host'], $options);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
}
|
||||
|
||||
if (!is_resource($this->connection)) {
|
||||
$info = sqlsrv_errors();
|
||||
$info = sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
throw new Dibi\DriverException($info[0]['message'], $info[0]['code']);
|
||||
}
|
||||
$this->version = sqlsrv_server_info($this->connection)['SQLServerVersion'];
|
||||
|
@@ -423,7 +423,7 @@ class Fluent implements IDataSource
|
||||
if ($clause === null) {
|
||||
$data = $this->clauses;
|
||||
if ($this->command === 'SELECT' && ($data['LIMIT'] || $data['OFFSET'])) {
|
||||
$args = array_merge(['%lmt %ofs', $data['LIMIT'][0], $data['OFFSET'][0]], $args);
|
||||
$args = array_merge(['%lmt %ofs', $data['LIMIT'][0] ?? null, $data['OFFSET'][0] ?? null], $args);
|
||||
unset($data['LIMIT'], $data['OFFSET']);
|
||||
}
|
||||
|
||||
|
@@ -282,7 +282,7 @@ class Result implements IDataSource
|
||||
}
|
||||
|
||||
} elseif ($as !== '|') { // associative-array node
|
||||
$x = &$x[$row->$as];
|
||||
$x = &$x[(string) $row->$as];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ class Result implements IDataSource
|
||||
}
|
||||
|
||||
} else { // associative-array node
|
||||
$x = &$x[$row->$as];
|
||||
$x = &$x[(string) $row->$as];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,6 +452,7 @@ class Result implements IDataSource
|
||||
continue;
|
||||
}
|
||||
$value = $row[$key];
|
||||
|
||||
if ($type === Type::TEXT) {
|
||||
$row[$key] = (string) $value;
|
||||
|
||||
@@ -497,6 +498,9 @@ class Result implements IDataSource
|
||||
|
||||
} elseif ($type === Type::JSON) {
|
||||
$row[$key] = json_decode($value, true);
|
||||
|
||||
} else {
|
||||
$row[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ class dibi
|
||||
|
||||
/** version */
|
||||
public const
|
||||
VERSION = '4.0.2';
|
||||
VERSION = '4.0.3';
|
||||
|
||||
/** sorting order */
|
||||
public const
|
||||
|
@@ -52,6 +52,17 @@ test(function () use ($config) {
|
||||
});
|
||||
|
||||
|
||||
test(function () use ($config) {
|
||||
$conn = new Connection($config);
|
||||
Assert::equal('hello', $conn->query('SELECT %s', 'hello')->fetchSingle());
|
||||
|
||||
$conn->disconnect();
|
||||
|
||||
$conn->connect();
|
||||
Assert::equal('hello', $conn->query('SELECT %s', 'hello')->fetchSingle());
|
||||
});
|
||||
|
||||
|
||||
test(function () use ($config) {
|
||||
Assert::exception(function () use ($config) {
|
||||
new Connection($config + ['onConnect' => '']);
|
||||
|
Reference in New Issue
Block a user