mirror of
https://github.com/dg/dibi.git
synced 2025-09-01 10:02:53 +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.1
|
||||||
- 7.2
|
- 7.2
|
||||||
- 7.3
|
- 7.3
|
||||||
|
- 7.4
|
||||||
|
|
||||||
|
services:
|
||||||
|
- mysql
|
||||||
|
- postgresql
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
# turn off XDebug
|
# turn off XDebug
|
||||||
|
@@ -26,7 +26,7 @@ Install Dibi via Composer:
|
|||||||
composer require dibi/dibi
|
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
|
Usage
|
||||||
|
@@ -119,6 +119,7 @@ class Connection implements IConnection
|
|||||||
{
|
{
|
||||||
if ($this->config['driver'] instanceof Driver) {
|
if ($this->config['driver'] instanceof Driver) {
|
||||||
$this->driver = $this->config['driver'];
|
$this->driver = $this->config['driver'];
|
||||||
|
$this->translator = new Translator($this);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} elseif (is_subclass_of($this->config['driver'], Driver::class)) {
|
} 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;
|
$event = $this->onEvent ? new Event($this, Event::CONNECT) : null;
|
||||||
try {
|
try {
|
||||||
$this->driver = new $class($this->config);
|
$this->driver = new $class($this->config);
|
||||||
|
$this->translator = new Translator($this);
|
||||||
|
|
||||||
if ($event) {
|
if ($event) {
|
||||||
$this->onEvent($event->done());
|
$this->onEvent($event->done());
|
||||||
}
|
}
|
||||||
@@ -160,7 +163,7 @@ class Connection implements IConnection
|
|||||||
{
|
{
|
||||||
if ($this->driver) {
|
if ($this->driver) {
|
||||||
$this->driver->disconnect();
|
$this->driver->disconnect();
|
||||||
$this->driver = null;
|
$this->driver = $this->translator = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,11 +264,7 @@ class Connection implements IConnection
|
|||||||
if (!$this->driver) {
|
if (!$this->driver) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
}
|
}
|
||||||
if (!$this->translator) {
|
return (clone $this->translator)->translate($args);
|
||||||
$this->translator = new Translator($this);
|
|
||||||
}
|
|
||||||
$translator = clone $this->translator;
|
|
||||||
return $translator->translate($args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -93,7 +93,7 @@ class MySqliDriver implements Dibi\Driver
|
|||||||
@$this->connection->real_connect( // intentionally @
|
@$this->connection->real_connect( // intentionally @
|
||||||
(empty($config['persistent']) ? '' : 'p:') . $config['host'],
|
(empty($config['persistent']) ? '' : 'p:') . $config['host'],
|
||||||
$config['username'],
|
$config['username'],
|
||||||
$config['password'],
|
$config['password'] ?? '',
|
||||||
$config['database'] ?? '',
|
$config['database'] ?? '',
|
||||||
$config['port'] ?? 0,
|
$config['port'] ?? 0,
|
||||||
$config['socket'],
|
$config['socket'],
|
||||||
|
@@ -96,7 +96,7 @@ class SqliteResult implements Dibi\ResultDriver
|
|||||||
'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' => $types[$this->resultSet->columnType($i)] ?? null, // buggy in PHP 7.4.4 & 7.3.16, bug 79414
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
|
@@ -65,11 +65,13 @@ class SqlsrvDriver implements Dibi\Driver
|
|||||||
$options['UID'] = (string) $options['UID'];
|
$options['UID'] = (string) $options['UID'];
|
||||||
$options['Database'] = (string) $options['Database'];
|
$options['Database'] = (string) $options['Database'];
|
||||||
|
|
||||||
|
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
||||||
$this->connection = sqlsrv_connect($config['host'], $options);
|
$this->connection = sqlsrv_connect($config['host'], $options);
|
||||||
|
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_resource($this->connection)) {
|
if (!is_resource($this->connection)) {
|
||||||
$info = sqlsrv_errors();
|
$info = sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||||
throw new Dibi\DriverException($info[0]['message'], $info[0]['code']);
|
throw new Dibi\DriverException($info[0]['message'], $info[0]['code']);
|
||||||
}
|
}
|
||||||
$this->version = sqlsrv_server_info($this->connection)['SQLServerVersion'];
|
$this->version = sqlsrv_server_info($this->connection)['SQLServerVersion'];
|
||||||
|
@@ -423,7 +423,7 @@ class Fluent implements IDataSource
|
|||||||
if ($clause === null) {
|
if ($clause === null) {
|
||||||
$data = $this->clauses;
|
$data = $this->clauses;
|
||||||
if ($this->command === 'SELECT' && ($data['LIMIT'] || $data['OFFSET'])) {
|
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']);
|
unset($data['LIMIT'], $data['OFFSET']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -282,7 +282,7 @@ class Result implements IDataSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($as !== '|') { // associative-array node
|
} 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
|
} else { // associative-array node
|
||||||
$x = &$x[$row->$as];
|
$x = &$x[(string) $row->$as];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,6 +452,7 @@ class Result implements IDataSource
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value = $row[$key];
|
$value = $row[$key];
|
||||||
|
|
||||||
if ($type === Type::TEXT) {
|
if ($type === Type::TEXT) {
|
||||||
$row[$key] = (string) $value;
|
$row[$key] = (string) $value;
|
||||||
|
|
||||||
@@ -497,6 +498,9 @@ class Result implements IDataSource
|
|||||||
|
|
||||||
} elseif ($type === Type::JSON) {
|
} elseif ($type === Type::JSON) {
|
||||||
$row[$key] = json_decode($value, true);
|
$row[$key] = json_decode($value, true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$row[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,7 +44,7 @@ class dibi
|
|||||||
|
|
||||||
/** version */
|
/** version */
|
||||||
public const
|
public const
|
||||||
VERSION = '4.0.2';
|
VERSION = '4.0.3';
|
||||||
|
|
||||||
/** sorting order */
|
/** sorting order */
|
||||||
public const
|
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) {
|
test(function () use ($config) {
|
||||||
Assert::exception(function () use ($config) {
|
Assert::exception(function () use ($config) {
|
||||||
new Connection($config + ['onConnect' => '']);
|
new Connection($config + ['onConnect' => '']);
|
||||||
|
Reference in New Issue
Block a user