mirror of
https://github.com/dg/dibi.git
synced 2025-08-02 20:27:35 +02:00
coding style: TRUE/FALSE/NULL -> true/false/null
This commit is contained in:
@@ -89,7 +89,7 @@ try {
|
|||||||
dibi::connect([
|
dibi::connect([
|
||||||
'driver' => 'postgre',
|
'driver' => 'postgre',
|
||||||
'string' => 'host=localhost port=5432 dbname=mary',
|
'string' => 'host=localhost port=5432 dbname=mary',
|
||||||
'persistent' => TRUE,
|
'persistent' => true,
|
||||||
]);
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (Dibi\Exception $e) {
|
} catch (Dibi\Exception $e) {
|
||||||
|
Binary file not shown.
@@ -14,13 +14,13 @@ dibi::connect([
|
|||||||
|
|
||||||
|
|
||||||
// some variables
|
// some variables
|
||||||
$cond1 = TRUE;
|
$cond1 = true;
|
||||||
$cond2 = FALSE;
|
$cond2 = false;
|
||||||
$foo = -1;
|
$foo = -1;
|
||||||
$bar = 2;
|
$bar = 2;
|
||||||
|
|
||||||
// conditional variable
|
// conditional variable
|
||||||
$name = $cond1 ? 'K%' : NULL;
|
$name = $cond1 ? 'K%' : null;
|
||||||
|
|
||||||
// if & end
|
// if & end
|
||||||
dibi::test('
|
dibi::test('
|
||||||
|
@@ -33,7 +33,7 @@ dibi::test('
|
|||||||
REPLACE INTO products', [
|
REPLACE INTO products', [
|
||||||
'title' => 'Super product',
|
'title' => 'Super product',
|
||||||
'price' => 318,
|
'price' => 318,
|
||||||
'active' => TRUE,
|
'active' => true,
|
||||||
]);
|
]);
|
||||||
// -> REPLACE INTO products ([title], [price], [active]) VALUES ('Super product', 318, 1)
|
// -> REPLACE INTO products ([title], [price], [active]) VALUES ('Super product', 318, 1)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ dibi::test('
|
|||||||
$array = [
|
$array = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => null,
|
||||||
'created' => new DateTime,
|
'created' => new DateTime,
|
||||||
];
|
];
|
||||||
dibi::test('INSERT INTO products', $array, $array, $array);
|
dibi::test('INSERT INTO products', $array, $array, $array);
|
||||||
|
@@ -14,7 +14,7 @@ $connection = dibi::connect([
|
|||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => [
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => true,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ $connection = dibi::connect([
|
|||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => [
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => true,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ $id = 10;
|
|||||||
$record = [
|
$record = [
|
||||||
'title' => 'Super product',
|
'title' => 'Super product',
|
||||||
'price' => 318,
|
'price' => 318,
|
||||||
'active' => TRUE,
|
'active' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
// SELECT ...
|
// SELECT ...
|
||||||
|
@@ -14,7 +14,7 @@ dibi::connect([
|
|||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
// enable query logging to this file
|
// enable query logging to this file
|
||||||
'profiler' => [
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => true,
|
||||||
'file' => 'data/log.sql',
|
'file' => 'data/log.sql',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
@@ -13,7 +13,7 @@ dibi::connect([
|
|||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => [
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => true,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ dibi::query('SELECT * FROM users WHERE id = ?', $id);
|
|||||||
|
|
||||||
$arr = [
|
$arr = [
|
||||||
'name' => 'John',
|
'name' => 'John',
|
||||||
'is_admin' => TRUE,
|
'is_admin' => true,
|
||||||
];
|
];
|
||||||
dibi::query('INSERT INTO users', $arr);
|
dibi::query('INSERT INTO users', $arr);
|
||||||
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
|
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
|
||||||
|
@@ -23,7 +23,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
private $debugMode;
|
private $debugMode;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($debugMode = NULL)
|
public function __construct($debugMode = null)
|
||||||
{
|
{
|
||||||
$this->debugMode = $debugMode;
|
$this->debugMode = $debugMode;
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
$container = $this->getContainerBuilder();
|
$container = $this->getContainerBuilder();
|
||||||
$config = $this->getConfig();
|
$config = $this->getConfig();
|
||||||
|
|
||||||
if ($this->debugMode === NULL) {
|
if ($this->debugMode === null) {
|
||||||
$this->debugMode = $container->parameters['debugMode'];
|
$this->debugMode = $container->parameters['debugMode'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
|
|
||||||
$connection = $container->addDefinition($this->prefix('connection'))
|
$connection = $container->addDefinition($this->prefix('connection'))
|
||||||
->setClass(Dibi\Connection::class, [$config])
|
->setClass(Dibi\Connection::class, [$config])
|
||||||
->setAutowired($config['autowired'] ?? TRUE);
|
->setAutowired($config['autowired'] ?? true);
|
||||||
|
|
||||||
if (class_exists(Tracy\Debugger::class)) {
|
if (class_exists(Tracy\Debugger::class)) {
|
||||||
$connection->addSetup(
|
$connection->addSetup(
|
||||||
@@ -63,8 +63,8 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
if ($useProfiler) {
|
if ($useProfiler) {
|
||||||
$panel = $container->addDefinition($this->prefix('panel'))
|
$panel = $container->addDefinition($this->prefix('panel'))
|
||||||
->setClass(Dibi\Bridges\Tracy\Panel::class, [
|
->setClass(Dibi\Bridges\Tracy\Panel::class, [
|
||||||
$config['explain'] ?? TRUE,
|
$config['explain'] ?? true,
|
||||||
isset($config['filter']) && $config['filter'] === FALSE ? Dibi\Event::ALL : Dibi\Event::QUERY,
|
isset($config['filter']) && $config['filter'] === false ? Dibi\Event::ALL : Dibi\Event::QUERY,
|
||||||
]);
|
]);
|
||||||
$connection->addSetup([$panel, 'register'], [$connection]);
|
$connection->addSetup([$panel, 'register'], [$connection]);
|
||||||
}
|
}
|
||||||
|
@@ -9,4 +9,4 @@ dibi:
|
|||||||
username: root
|
username: root
|
||||||
password: ***
|
password: ***
|
||||||
database: foo
|
database: foo
|
||||||
lazy: TRUE
|
lazy: true
|
||||||
|
@@ -35,7 +35,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
private $events = [];
|
private $events = [];
|
||||||
|
|
||||||
|
|
||||||
public function __construct(bool $explain = TRUE, int $filter = NULL)
|
public function __construct(bool $explain = true, int $filter = null)
|
||||||
{
|
{
|
||||||
$this->filter = $filter ?: Event::QUERY;
|
$this->filter = $filter ?: Event::QUERY;
|
||||||
$this->explain = $explain;
|
$this->explain = $explain;
|
||||||
@@ -70,7 +70,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
if ($e instanceof Dibi\Exception && $e->getSql()) {
|
if ($e instanceof Dibi\Exception && $e->getSql()) {
|
||||||
return [
|
return [
|
||||||
'tab' => 'SQL',
|
'tab' => 'SQL',
|
||||||
'panel' => Helpers::dump($e->getSql(), TRUE),
|
'panel' => Helpers::dump($e->getSql(), true),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,20 +99,20 @@ class Panel implements Tracy\IBarPanel
|
|||||||
public function getPanel(): ?string
|
public function getPanel(): ?string
|
||||||
{
|
{
|
||||||
if (!$this->events) {
|
if (!$this->events) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$totalTime = $s = NULL;
|
$totalTime = $s = null;
|
||||||
foreach ($this->events as $event) {
|
foreach ($this->events as $event) {
|
||||||
$totalTime += $event->time;
|
$totalTime += $event->time;
|
||||||
$connection = $event->connection;
|
$connection = $event->connection;
|
||||||
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
$explain = null; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
||||||
if ($this->explain && $event->type === Event::SELECT) {
|
if ($this->explain && $event->type === Event::SELECT) {
|
||||||
try {
|
try {
|
||||||
$backup = [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
|
$backup = [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
|
||||||
$connection->onEvent = NULL;
|
$connection->onEvent = null;
|
||||||
$cmd = is_string($this->explain) ? $this->explain : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
$cmd = is_string($this->explain) ? $this->explain : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
||||||
$explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), TRUE);
|
$explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), true);
|
||||||
} catch (Dibi\Exception $e) {
|
} catch (Dibi\Exception $e) {
|
||||||
}
|
}
|
||||||
[$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime] = $backup;
|
[$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime] = $backup;
|
||||||
@@ -125,7 +125,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
$s .= "<br /><a href='#tracy-debug-DibiProfiler-row-$counter' class='tracy-toggle tracy-collapsed' rel='#tracy-debug-DibiProfiler-row-$counter'>explain</a>";
|
$s .= "<br /><a href='#tracy-debug-DibiProfiler-row-$counter' class='tracy-toggle tracy-collapsed' rel='#tracy-debug-DibiProfiler-row-$counter'>explain</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$s .= '</td><td class="tracy-DibiProfiler-sql">' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, TRUE);
|
$s .= '</td><td class="tracy-DibiProfiler-sql">' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, true);
|
||||||
if ($explain) {
|
if ($explain) {
|
||||||
$s .= "<div id='tracy-debug-DibiProfiler-row-$counter' class='tracy-collapsed'>{$explain}</div>";
|
$s .= "<div id='tracy-debug-DibiProfiler-row-$counter' class='tracy-collapsed'>{$explain}</div>";
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
|
#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
|
||||||
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
||||||
<h1>Queries: ' . count($this->events)
|
<h1>Queries: ' . count($this->events)
|
||||||
. ($totalTime === NULL ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', '
|
. ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', '
|
||||||
. htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
|
. htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
|
||||||
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '</h1>
|
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '</h1>
|
||||||
<div class="tracy-inner tracy-DibiProfiler">
|
<div class="tracy-inner tracy-DibiProfiler">
|
||||||
|
@@ -35,7 +35,7 @@ class Connection
|
|||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
/** @var bool Is connected? */
|
/** @var bool Is connected? */
|
||||||
private $connected = FALSE;
|
private $connected = false;
|
||||||
|
|
||||||
/** @var HashMap Substitutes for identifiers */
|
/** @var HashMap Substitutes for identifiers */
|
||||||
private $substitutes;
|
private $substitutes;
|
||||||
@@ -43,7 +43,7 @@ class Connection
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection options: (see driver-specific options too)
|
* Connection options: (see driver-specific options too)
|
||||||
* - lazy (bool) => if TRUE, connection will be established only when required
|
* - lazy (bool) => if true, connection will be established only when required
|
||||||
* - result (array) => result set options
|
* - result (array) => result set options
|
||||||
* - formatDateTime => date-time format (if empty, DateTime objects will be returned)
|
* - formatDateTime => date-time format (if empty, DateTime objects will be returned)
|
||||||
* - profiler (array or bool)
|
* - profiler (array or bool)
|
||||||
@@ -54,7 +54,7 @@ class Connection
|
|||||||
* @param string connection name
|
* @param string connection name
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($config, string $name = NULL)
|
public function __construct($config, string $name = null)
|
||||||
{
|
{
|
||||||
if (is_string($config)) {
|
if (is_string($config)) {
|
||||||
parse_str($config, $config);
|
parse_str($config, $config);
|
||||||
@@ -142,10 +142,10 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
final public function connect(): void
|
final public function connect(): void
|
||||||
{
|
{
|
||||||
$event = $this->onEvent ? new Event($this, Event::CONNECT) : NULL;
|
$event = $this->onEvent ? new Event($this, Event::CONNECT) : null;
|
||||||
try {
|
try {
|
||||||
$this->driver->connect($this->config);
|
$this->driver->connect($this->config);
|
||||||
$this->connected = TRUE;
|
$this->connected = true;
|
||||||
$event && $this->onEvent($event->done());
|
$event && $this->onEvent($event->done());
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -161,12 +161,12 @@ class Connection
|
|||||||
final public function disconnect(): void
|
final public function disconnect(): void
|
||||||
{
|
{
|
||||||
$this->driver->disconnect();
|
$this->driver->disconnect();
|
||||||
$this->connected = FALSE;
|
$this->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns TRUE when connection was established.
|
* Returns true when connection was established.
|
||||||
*/
|
*/
|
||||||
final public function isConnected(): bool
|
final public function isConnected(): bool
|
||||||
{
|
{
|
||||||
@@ -179,9 +179,9 @@ class Connection
|
|||||||
* @see self::__construct
|
* @see self::__construct
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
final public function getConfig(string $key = NULL, $default = NULL)
|
final public function getConfig(string $key = null, $default = null)
|
||||||
{
|
{
|
||||||
return $key === NULL
|
return $key === null
|
||||||
? $this->config
|
? $this->config
|
||||||
: ($this->config[$key] ?? $default);
|
: ($this->config[$key] ?? $default);
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ class Connection
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Helpers::dump($this->translateArgs($args));
|
Helpers::dump($this->translateArgs($args));
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($e->getSql()) {
|
if ($e->getSql()) {
|
||||||
@@ -236,7 +236,7 @@ class Connection
|
|||||||
} else {
|
} else {
|
||||||
echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '<br>');
|
echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '<br>');
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ class Connection
|
|||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
|
|
||||||
\dibi::$sql = $sql;
|
\dibi::$sql = $sql;
|
||||||
$event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : NULL;
|
$event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : null;
|
||||||
try {
|
try {
|
||||||
$res = $this->driver->query($sql);
|
$res = $this->driver->query($sql);
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ class Connection
|
|||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
$rows = $this->driver->getAffectedRows();
|
$rows = $this->driver->getAffectedRows();
|
||||||
if ($rows === NULL || $rows < 0) {
|
if ($rows === null || $rows < 0) {
|
||||||
throw new Exception('Cannot retrieve number of affected rows.');
|
throw new Exception('Cannot retrieve number of affected rows.');
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows;
|
||||||
@@ -325,7 +325,7 @@ class Connection
|
|||||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getInsertId(string $sequence = NULL): int
|
public function getInsertId(string $sequence = null): int
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
$id = $this->driver->getInsertId($sequence);
|
$id = $this->driver->getInsertId($sequence);
|
||||||
@@ -340,7 +340,7 @@ class Connection
|
|||||||
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function insertId(string $sequence = NULL): int
|
public function insertId(string $sequence = null): int
|
||||||
{
|
{
|
||||||
return $this->getInsertId($sequence);
|
return $this->getInsertId($sequence);
|
||||||
}
|
}
|
||||||
@@ -349,10 +349,10 @@ class Connection
|
|||||||
/**
|
/**
|
||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
$event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : NULL;
|
$event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : null;
|
||||||
try {
|
try {
|
||||||
$this->driver->begin($savepoint);
|
$this->driver->begin($savepoint);
|
||||||
$event && $this->onEvent($event->done());
|
$event && $this->onEvent($event->done());
|
||||||
@@ -367,10 +367,10 @@ class Connection
|
|||||||
/**
|
/**
|
||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
$event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : NULL;
|
$event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : null;
|
||||||
try {
|
try {
|
||||||
$this->driver->commit($savepoint);
|
$this->driver->commit($savepoint);
|
||||||
$event && $this->onEvent($event->done());
|
$event && $this->onEvent($event->done());
|
||||||
@@ -385,10 +385,10 @@ class Connection
|
|||||||
/**
|
/**
|
||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
$event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : NULL;
|
$event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : null;
|
||||||
try {
|
try {
|
||||||
$this->driver->rollback($savepoint);
|
$this->driver->rollback($savepoint);
|
||||||
$event && $this->onEvent($event->done());
|
$event && $this->onEvent($event->done());
|
||||||
@@ -470,7 +470,7 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
public function substitute(string $value): string
|
public function substitute(string $value): string
|
||||||
{
|
{
|
||||||
return strpos($value, ':') === FALSE
|
return strpos($value, ':') === false
|
||||||
? $value
|
? $value
|
||||||
: preg_replace_callback('#:([^:\s]*):#', function ($m) { return $this->substitutes->{$m[1]}; }, $value);
|
: preg_replace_callback('#:([^:\s]*):#', function ($m) { return $this->substitutes->{$m[1]}; }, $value);
|
||||||
}
|
}
|
||||||
@@ -540,7 +540,7 @@ class Connection
|
|||||||
* @param callable $onProgress function (int $count, ?float $percent): void
|
* @param callable $onProgress function (int $count, ?float $percent): void
|
||||||
* @return int count of sql commands
|
* @return int count of sql commands
|
||||||
*/
|
*/
|
||||||
public function loadFile(string $file, callable $onProgress = NULL): int
|
public function loadFile(string $file, callable $onProgress = null): int
|
||||||
{
|
{
|
||||||
return Helpers::loadFromFile($this, $file, $onProgress);
|
return Helpers::loadFromFile($this, $file, $onProgress);
|
||||||
}
|
}
|
||||||
@@ -552,7 +552,7 @@ class Connection
|
|||||||
public function getDatabaseInfo(): Reflection\Database
|
public function getDatabaseInfo(): Reflection\Database
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? NULL);
|
return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -42,10 +42,10 @@ class DataSource implements IDataSource
|
|||||||
/** @var array */
|
/** @var array */
|
||||||
private $conds = [];
|
private $conds = [];
|
||||||
|
|
||||||
/** @var int|NULL */
|
/** @var int|null */
|
||||||
private $offset;
|
private $offset;
|
||||||
|
|
||||||
/** @var int|NULL */
|
/** @var int|null */
|
||||||
private $limit;
|
private $limit;
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class DataSource implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $sql, Connection $connection)
|
public function __construct(string $sql, Connection $connection)
|
||||||
{
|
{
|
||||||
if (strpbrk($sql, " \t\r\n") === FALSE) {
|
if (strpbrk($sql, " \t\r\n") === false) {
|
||||||
$this->sql = $connection->getDriver()->escapeIdentifier($sql); // table name
|
$this->sql = $connection->getDriver()->escapeIdentifier($sql); // table name
|
||||||
} else {
|
} else {
|
||||||
$this->sql = '(' . $sql . ') t'; // SQL command
|
$this->sql = '(' . $sql . ') t'; // SQL command
|
||||||
@@ -68,14 +68,14 @@ class DataSource implements IDataSource
|
|||||||
* @param string|array column name or array of column names
|
* @param string|array column name or array of column names
|
||||||
* @param string column alias
|
* @param string column alias
|
||||||
*/
|
*/
|
||||||
public function select($col, string $as = NULL): self
|
public function select($col, string $as = null): self
|
||||||
{
|
{
|
||||||
if (is_array($col)) {
|
if (is_array($col)) {
|
||||||
$this->cols = $col;
|
$this->cols = $col;
|
||||||
} else {
|
} else {
|
||||||
$this->cols[$col] = $as;
|
$this->cols[$col] = $as;
|
||||||
}
|
}
|
||||||
$this->result = NULL;
|
$this->result = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ class DataSource implements IDataSource
|
|||||||
} else {
|
} else {
|
||||||
$this->conds[] = func_get_args();
|
$this->conds[] = func_get_args();
|
||||||
}
|
}
|
||||||
$this->result = $this->count = NULL;
|
$this->result = $this->count = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ class DataSource implements IDataSource
|
|||||||
} else {
|
} else {
|
||||||
$this->sorting[$row] = $direction;
|
$this->sorting[$row] = $direction;
|
||||||
}
|
}
|
||||||
$this->result = NULL;
|
$this->result = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,11 +115,11 @@ class DataSource implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Limits number of rows.
|
* Limits number of rows.
|
||||||
*/
|
*/
|
||||||
public function applyLimit(int $limit, int $offset = NULL): self
|
public function applyLimit(int $limit, int $offset = null): self
|
||||||
{
|
{
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
$this->offset = $offset;
|
$this->offset = $offset;
|
||||||
$this->result = $this->count = NULL;
|
$this->result = $this->count = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ class DataSource implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function getResult(): Result
|
public function getResult(): Result
|
||||||
{
|
{
|
||||||
if ($this->result === NULL) {
|
if ($this->result === null) {
|
||||||
$this->result = $this->connection->nativeQuery($this->__toString());
|
$this->result = $this->connection->nativeQuery($this->__toString());
|
||||||
}
|
}
|
||||||
return $this->result;
|
return $this->result;
|
||||||
@@ -166,7 +166,7 @@ class DataSource implements IDataSource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Like fetch(), but returns only first field.
|
* Like fetch(), but returns only first field.
|
||||||
* @return mixed value on success, NULL if no next record
|
* @return mixed value on success, null if no next record
|
||||||
*/
|
*/
|
||||||
public function fetchSingle()
|
public function fetchSingle()
|
||||||
{
|
{
|
||||||
@@ -195,7 +195,7 @@ class DataSource implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Fetches all records from table like $key => $value pairs.
|
* Fetches all records from table like $key => $value pairs.
|
||||||
*/
|
*/
|
||||||
public function fetchPairs(string $key = NULL, string $value = NULL): array
|
public function fetchPairs(string $key = null, string $value = null): array
|
||||||
{
|
{
|
||||||
return $this->getResult()->fetchPairs($key, $value);
|
return $this->getResult()->fetchPairs($key, $value);
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ class DataSource implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function release(): void
|
public function release(): void
|
||||||
{
|
{
|
||||||
$this->result = $this->count = $this->totalCount = NULL;
|
$this->result = $this->count = $this->totalCount = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -240,8 +240,8 @@ class DataSource implements IDataSource
|
|||||||
return $this->connection->translate('
|
return $this->connection->translate('
|
||||||
SELECT %n', (empty($this->cols) ? '*' : $this->cols), '
|
SELECT %n', (empty($this->cols) ? '*' : $this->cols), '
|
||||||
FROM %SQL', $this->sql, '
|
FROM %SQL', $this->sql, '
|
||||||
%ex', $this->conds ? ['WHERE %and', $this->conds] : NULL, '
|
%ex', $this->conds ? ['WHERE %and', $this->conds] : null, '
|
||||||
%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : NULL, '
|
%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : null, '
|
||||||
%ofs %lmt', $this->offset, $this->limit
|
%ofs %lmt', $this->offset, $this->limit
|
||||||
);
|
);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -258,7 +258,7 @@ FROM %SQL', $this->sql, '
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
if ($this->count === NULL) {
|
if ($this->count === null) {
|
||||||
$this->count = $this->conds || $this->offset || $this->limit
|
$this->count = $this->conds || $this->offset || $this->limit
|
||||||
? (int) $this->connection->nativeQuery(
|
? (int) $this->connection->nativeQuery(
|
||||||
'SELECT COUNT(*) FROM (' . $this->__toString() . ') t'
|
'SELECT COUNT(*) FROM (' . $this->__toString() . ') t'
|
||||||
@@ -274,7 +274,7 @@ FROM %SQL', $this->sql, '
|
|||||||
*/
|
*/
|
||||||
public function getTotalCount(): int
|
public function getTotalCount(): int
|
||||||
{
|
{
|
||||||
if ($this->totalCount === NULL) {
|
if ($this->totalCount === null) {
|
||||||
$this->totalCount = (int) $this->connection->nativeQuery(
|
$this->totalCount = (int) $this->connection->nativeQuery(
|
||||||
'SELECT COUNT(*) FROM ' . $this->sql
|
'SELECT COUNT(*) FROM ' . $this->sql
|
||||||
)->fetchSingle();
|
)->fetchSingle();
|
||||||
|
@@ -20,12 +20,12 @@ class DateTime extends \DateTime
|
|||||||
/**
|
/**
|
||||||
* @param string|int
|
* @param string|int
|
||||||
*/
|
*/
|
||||||
public function __construct($time = 'now', \DateTimeZone $timezone = NULL)
|
public function __construct($time = 'now', \DateTimeZone $timezone = null)
|
||||||
{
|
{
|
||||||
if (is_numeric($time)) {
|
if (is_numeric($time)) {
|
||||||
parent::__construct('@' . $time);
|
parent::__construct('@' . $time);
|
||||||
$this->setTimeZone($timezone ? $timezone : new \DateTimeZone(date_default_timezone_get()));
|
$this->setTimeZone($timezone ? $timezone : new \DateTimeZone(date_default_timezone_get()));
|
||||||
} elseif ($timezone === NULL) {
|
} elseif ($timezone === null) {
|
||||||
parent::__construct($time);
|
parent::__construct($time);
|
||||||
} else {
|
} else {
|
||||||
parent::__construct($time, $timezone);
|
parent::__construct($time, $timezone);
|
||||||
|
@@ -31,20 +31,20 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
const ERROR_EXCEPTION_THROWN = -836;
|
const ERROR_EXCEPTION_THROWN = -836;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $transaction;
|
private $transaction;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $inTransaction = FALSE;
|
private $inTransaction = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +110,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
$resource = $this->inTransaction ? $this->transaction : $this->connection;
|
$resource = $this->inTransaction ? $this->transaction : $this->connection;
|
||||||
$res = ibase_query($resource, $sql);
|
$res = ibase_query($resource, $sql);
|
||||||
|
|
||||||
if ($res === FALSE) {
|
if ($res === false) {
|
||||||
if (ibase_errcode() == self::ERROR_EXCEPTION_THROWN) {
|
if (ibase_errcode() == self::ERROR_EXCEPTION_THROWN) {
|
||||||
preg_match('/exception (\d+) (\w+) (.*)/i', ibase_errmsg(), $match);
|
preg_match('/exception (\d+) (\w+) (.*)/i', ibase_errmsg(), $match);
|
||||||
throw new Dibi\ProcedureException($match[3], $match[1], $match[2], $sql);
|
throw new Dibi\ProcedureException($match[3], $match[1], $match[2], $sql);
|
||||||
@@ -122,7 +122,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,13 +148,13 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if ($savepoint !== NULL) {
|
if ($savepoint !== null) {
|
||||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||||
}
|
}
|
||||||
$this->transaction = ibase_trans($this->getResource());
|
$this->transaction = ibase_trans($this->getResource());
|
||||||
$this->inTransaction = TRUE;
|
$this->inTransaction = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,9 +162,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if ($savepoint !== NULL) {
|
if ($savepoint !== null) {
|
||||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
throw new Dibi\DriverException('Unable to handle operation - failure when commiting transaction.');
|
throw new Dibi\DriverException('Unable to handle operation - failure when commiting transaction.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->inTransaction = FALSE;
|
$this->inTransaction = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -180,9 +180,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if ($savepoint !== NULL) {
|
if ($savepoint !== null) {
|
||||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
throw new Dibi\DriverException('Unable to handle operation - failure when rolbacking transaction.');
|
throw new Dibi\DriverException('Unable to handle operation - failure when rolbacking transaction.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->inTransaction = FALSE;
|
$this->inTransaction = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,11 +205,11 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -377,18 +377,18 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
ibase_free_result($this->resultSet);
|
ibase_free_result($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$tables[] = [
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => $row[1] === 'TRUE',
|
'view' => $row[1] === 'TRUE',
|
||||||
@@ -474,7 +474,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
);
|
);
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$key = $row['FIELD_NAME'];
|
$key = $row['FIELD_NAME'];
|
||||||
$columns[$key] = [
|
$columns[$key] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
@@ -483,7 +483,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
'size' => $row['FIELD_LENGTH'],
|
'size' => $row['FIELD_LENGTH'],
|
||||||
'nullable' => $row['NULLABLE'] === 'TRUE',
|
'nullable' => $row['NULLABLE'] === 'TRUE',
|
||||||
'default' => $row['DEFAULT_VALUE'],
|
'default' => $row['DEFAULT_VALUE'],
|
||||||
'autoincrement' => FALSE,
|
'autoincrement' => false,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
@@ -510,7 +510,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
ORDER BY s.RDB\$FIELD_POSITION"
|
ORDER BY s.RDB\$FIELD_POSITION"
|
||||||
);
|
);
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$key = $row['INDEX_NAME'];
|
$key = $row['INDEX_NAME'];
|
||||||
$indexes[$key]['name'] = $key;
|
$indexes[$key]['name'] = $key;
|
||||||
$indexes[$key]['unique'] = $row['UNIQUE_FLAG'] === 1;
|
$indexes[$key]['unique'] = $row['UNIQUE_FLAG'] === 1;
|
||||||
@@ -538,7 +538,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
ORDER BY s.RDB\$FIELD_POSITION"
|
ORDER BY s.RDB\$FIELD_POSITION"
|
||||||
);
|
);
|
||||||
$keys = [];
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$key = $row['INDEX_NAME'];
|
$key = $row['INDEX_NAME'];
|
||||||
$keys[$key] = [
|
$keys[$key] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
@@ -563,7 +563,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
AND RDB\$FOREIGN_KEY IS NULL;"
|
AND RDB\$FOREIGN_KEY IS NULL;"
|
||||||
);
|
);
|
||||||
$indices = [];
|
$indices = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$indices[] = $row[0];
|
$indices[] = $row[0];
|
||||||
}
|
}
|
||||||
return $indices;
|
return $indices;
|
||||||
@@ -585,7 +585,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
);"
|
);"
|
||||||
);
|
);
|
||||||
$constraints = [];
|
$constraints = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$constraints[] = $row[0];
|
$constraints[] = $row[0];
|
||||||
}
|
}
|
||||||
return $constraints;
|
return $constraints;
|
||||||
@@ -596,7 +596,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Returns metadata for all triggers in a table or database.
|
* Returns metadata for all triggers in a table or database.
|
||||||
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
||||||
*/
|
*/
|
||||||
public function getTriggersMeta(string $table = NULL): array
|
public function getTriggersMeta(string $table = null): array
|
||||||
{
|
{
|
||||||
$res = $this->query("
|
$res = $this->query("
|
||||||
SELECT TRIM(RDB\$TRIGGER_NAME) AS TRIGGER_NAME,
|
SELECT TRIM(RDB\$TRIGGER_NAME) AS TRIGGER_NAME,
|
||||||
@@ -622,10 +622,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
END AS TRIGGER_ENABLED
|
END AS TRIGGER_ENABLED
|
||||||
FROM RDB\$TRIGGERS
|
FROM RDB\$TRIGGERS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0"
|
WHERE RDB\$SYSTEM_FLAG = 0"
|
||||||
. ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
. ($table === null ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
||||||
);
|
);
|
||||||
$triggers = [];
|
$triggers = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$triggers[$row['TRIGGER_NAME']] = [
|
$triggers[$row['TRIGGER_NAME']] = [
|
||||||
'name' => $row['TRIGGER_NAME'],
|
'name' => $row['TRIGGER_NAME'],
|
||||||
'table' => $row['TABLE_NAME'],
|
'table' => $row['TABLE_NAME'],
|
||||||
@@ -642,16 +642,16 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Returns list of triggers for given table.
|
* Returns list of triggers for given table.
|
||||||
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
||||||
*/
|
*/
|
||||||
public function getTriggers(string $table = NULL): array
|
public function getTriggers(string $table = null): array
|
||||||
{
|
{
|
||||||
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
|
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
|
||||||
FROM RDB\$TRIGGERS
|
FROM RDB\$TRIGGERS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0";
|
WHERE RDB\$SYSTEM_FLAG = 0";
|
||||||
$q .= $table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')";
|
$q .= $table === null ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')";
|
||||||
|
|
||||||
$res = $this->query($q);
|
$res = $this->query($q);
|
||||||
$triggers = [];
|
$triggers = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$triggers[] = $row[0];
|
$triggers[] = $row[0];
|
||||||
}
|
}
|
||||||
return $triggers;
|
return $triggers;
|
||||||
@@ -696,7 +696,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;"
|
ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;"
|
||||||
);
|
);
|
||||||
$procedures = [];
|
$procedures = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$key = $row['PROCEDURE_NAME'];
|
$key = $row['PROCEDURE_NAME'];
|
||||||
$io = trim($row['PARAMETER_TYPE']);
|
$io = trim($row['PARAMETER_TYPE']);
|
||||||
$num = $row['PARAMETER_NUMBER'];
|
$num = $row['PARAMETER_NUMBER'];
|
||||||
@@ -719,7 +719,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
FROM RDB\$PROCEDURES;"
|
FROM RDB\$PROCEDURES;"
|
||||||
);
|
);
|
||||||
$procedures = [];
|
$procedures = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$procedures[] = $row[0];
|
$procedures[] = $row[0];
|
||||||
}
|
}
|
||||||
return $procedures;
|
return $procedures;
|
||||||
@@ -737,7 +737,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$generators = [];
|
$generators = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$generators[] = $row[0];
|
$generators[] = $row[0];
|
||||||
}
|
}
|
||||||
return $generators;
|
return $generators;
|
||||||
@@ -755,7 +755,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$functions = [];
|
$functions = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$functions[] = $row[0];
|
$functions[] = $row[0];
|
||||||
}
|
}
|
||||||
return $functions;
|
return $functions;
|
||||||
|
@@ -28,14 +28,14 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +58,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (isset($config['resource'])) {
|
if (isset($config['resource'])) {
|
||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
} elseif (empty($config['persistent'])) {
|
} elseif (empty($config['persistent'])) {
|
||||||
$this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE); // intentionally @
|
$this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], true); // intentionally @
|
||||||
} else {
|
} else {
|
||||||
$this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']); // intentionally @
|
$this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']); // intentionally @
|
||||||
}
|
}
|
||||||
@@ -90,13 +90,13 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
$res = @mssql_query($sql, $this->connection); // intentionally @
|
$res = @mssql_query($sql, $this->connection); // intentionally @
|
||||||
|
|
||||||
if ($res === FALSE) {
|
if ($res === false) {
|
||||||
throw new Dibi\DriverException(mssql_get_last_message(), 0, $sql);
|
throw new Dibi\DriverException(mssql_get_last_message(), 0, $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$row = mssql_fetch_row($res);
|
$row = mssql_fetch_row($res);
|
||||||
return $row[0];
|
return $row[0];
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query('BEGIN TRANSACTION');
|
$this->query('BEGIN TRANSACTION');
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query('COMMIT');
|
$this->query('COMMIT');
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query('ROLLBACK');
|
$this->query('ROLLBACK');
|
||||||
}
|
}
|
||||||
@@ -155,11 +155,11 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
} elseif ($limit < 0) {
|
} elseif ($limit < 0) {
|
||||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -308,7 +308,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves cursor position without fetching row.
|
* Moves cursor position without fetching row.
|
||||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
* @return bool true on success, false if unable to seek to specified record
|
||||||
*/
|
*/
|
||||||
public function seek(int $row): bool
|
public function seek(int $row): bool
|
||||||
{
|
{
|
||||||
@@ -322,7 +322,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
mssql_free_result($this->resultSet);
|
mssql_free_result($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -348,11 +348,11 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
FROM INFORMATION_SCHEMA.TABLES
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
');
|
');
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$tables[] = [
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
@@ -53,24 +53,24 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
/**
|
/**
|
||||||
* Returns count of rows in a table
|
* Returns count of rows in a table
|
||||||
*/
|
*/
|
||||||
public function getTableCount(string $table, bool $fallback = TRUE): int
|
public function getTableCount(string $table, bool $fallback = true): int
|
||||||
{
|
{
|
||||||
if (empty($table)) {
|
if (empty($table)) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$result = $this->driver->query("
|
$result = $this->driver->query("
|
||||||
SELECT MAX(rowcnt)
|
SELECT MAX(rowcnt)
|
||||||
FROM sys.sysindexes
|
FROM sys.sysindexes
|
||||||
WHERE id=OBJECT_ID({$this->driver->escapeIdentifier($table)})
|
WHERE id=OBJECT_ID({$this->driver->escapeIdentifier($table)})
|
||||||
");
|
");
|
||||||
$row = $result->fetch(FALSE);
|
$row = $result->fetch(false);
|
||||||
|
|
||||||
if (!is_array($row) || count($row) < 1) {
|
if (!is_array($row) || count($row) < 1) {
|
||||||
if ($fallback) {
|
if ($fallback) {
|
||||||
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(FALSE);
|
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(false);
|
||||||
$count = intval($row[0]);
|
$count = intval($row[0]);
|
||||||
} else {
|
} else {
|
||||||
$count = NULL;
|
$count = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$count = intval($row[0]);
|
$count = intval($row[0]);
|
||||||
@@ -92,8 +92,8 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
ORDER BY TABLE_NAME, ORDINAL_POSITION
|
ORDER BY TABLE_NAME, ORDINAL_POSITION
|
||||||
");
|
");
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$size = FALSE;
|
$size = false;
|
||||||
$type = strtoupper($row['DATA_TYPE']);
|
$type = strtoupper($row['DATA_TYPE']);
|
||||||
|
|
||||||
$size_cols = [
|
$size_cols = [
|
||||||
@@ -116,10 +116,10 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => $type,
|
'nativetype' => $type,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
'unsigned' => NULL,
|
'unsigned' => null,
|
||||||
'nullable' => $row['IS_NULLABLE'] === 'YES',
|
'nullable' => $row['IS_NULLABLE'] === 'YES',
|
||||||
'default' => $row['COLUMN_DEFAULT'],
|
'default' => $row['COLUMN_DEFAULT'],
|
||||||
'autoincrement' => FALSE,
|
'autoincrement' => false,
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$index_name = $row['index_name'];
|
$index_name = $row['index_name'];
|
||||||
|
|
||||||
if (!isset($indexes[$index_name])) {
|
if (!isset($indexes[$index_name])) {
|
||||||
@@ -188,7 +188,7 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$keys = [];
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$key_name = $row['foreign_key'];
|
$key_name = $row['foreign_key'];
|
||||||
|
|
||||||
if (!isset($keys[$key_name])) {
|
if (!isset($keys[$key_name])) {
|
||||||
@@ -196,8 +196,8 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
$keys[$key_name]['local'] = [$row['column_name']]; // local columns
|
$keys[$key_name]['local'] = [$row['column_name']]; // local columns
|
||||||
$keys[$key_name]['table'] = $row['reference_table_name']; // referenced table
|
$keys[$key_name]['table'] = $row['reference_table_name']; // referenced table
|
||||||
$keys[$key_name]['foreign'] = [$row['reference_column_name']]; // referenced columns
|
$keys[$key_name]['foreign'] = [$row['reference_column_name']]; // referenced columns
|
||||||
$keys[$key_name]['onDelete'] = FALSE;
|
$keys[$key_name]['onDelete'] = false;
|
||||||
$keys[$key_name]['onUpdate'] = FALSE;
|
$keys[$key_name]['onUpdate'] = false;
|
||||||
} else {
|
} else {
|
||||||
$keys[$key_name]['local'][] = $row['column_name']; // local columns
|
$keys[$key_name]['local'][] = $row['column_name']; // local columns
|
||||||
$keys[$key_name]['foreign'][] = $row['reference_column_name']; // referenced columns
|
$keys[$key_name]['foreign'][] = $row['reference_column_name']; // referenced columns
|
||||||
|
@@ -37,7 +37,7 @@ class MySqlReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query('SHOW FULL TABLES');
|
$res = $this->driver->query('SHOW FULL TABLES');
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$tables[] = [
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
@@ -54,13 +54,13 @@ class MySqlReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}");
|
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}");
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$type = explode('(', $row['Type']);
|
$type = explode('(', $row['Type']);
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => $row['Field'],
|
'name' => $row['Field'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($type[0]),
|
'nativetype' => strtoupper($type[0]),
|
||||||
'size' => isset($type[1]) ? (int) $type[1] : NULL,
|
'size' => isset($type[1]) ? (int) $type[1] : null,
|
||||||
'unsigned' => (bool) strstr($row['Type'], 'unsigned'),
|
'unsigned' => (bool) strstr($row['Type'], 'unsigned'),
|
||||||
'nullable' => $row['Null'] === 'YES',
|
'nullable' => $row['Null'] === 'YES',
|
||||||
'default' => $row['Default'],
|
'default' => $row['Default'],
|
||||||
@@ -79,7 +79,7 @@ class MySqlReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}");
|
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}");
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
|
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
|
||||||
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
|
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
|
||||||
$indexes[$row['Key_name']]['primary'] = $row['Key_name'] === 'PRIMARY';
|
$indexes[$row['Key_name']]['primary'] = $row['Key_name'] === 'PRIMARY';
|
||||||
@@ -95,7 +95,7 @@ class MySqlReflector implements Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getForeignKeys(string $table): array
|
public function getForeignKeys(string $table): array
|
||||||
{
|
{
|
||||||
$data = $this->driver->query("SELECT `ENGINE` FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = {$this->driver->escapeText($table)}")->fetch(TRUE);
|
$data = $this->driver->query("SELECT `ENGINE` FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = {$this->driver->escapeText($table)}")->fetch(true);
|
||||||
if ($data['ENGINE'] !== 'InnoDB') {
|
if ($data['ENGINE'] !== 'InnoDB') {
|
||||||
throw new Dibi\NotSupportedException("Foreign keys are not supported in {$data['ENGINE']} tables.");
|
throw new Dibi\NotSupportedException("Foreign keys are not supported in {$data['ENGINE']} tables.");
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ class MySqlReflector implements Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$foreignKeys = [];
|
$foreignKeys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$keyName = $row['CONSTRAINT_NAME'];
|
$keyName = $row['CONSTRAINT_NAME'];
|
||||||
|
|
||||||
$foreignKeys[$keyName]['name'] = $keyName;
|
$foreignKeys[$keyName]['name'] = $keyName;
|
||||||
|
@@ -39,14 +39,14 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
const ERROR_DUPLICATE_ENTRY = 1062;
|
const ERROR_DUPLICATE_ENTRY = 1062;
|
||||||
const ERROR_DATA_TRUNCATED = 1265;
|
const ERROR_DATA_TRUNCATED = 1265;
|
||||||
|
|
||||||
/** @var \mysqli|NULL */
|
/** @var \mysqli|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var \mysqli_result|NULL */
|
/** @var \mysqli_result|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var bool Is buffered (seekable and countable)? */
|
/** @var bool Is buffered (seekable and countable)? */
|
||||||
private $buffered;
|
private $buffered;
|
||||||
@@ -81,7 +81,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
'username' => ini_get('mysqli.default_user'),
|
'username' => ini_get('mysqli.default_user'),
|
||||||
'password' => ini_get('mysqli.default_pw'),
|
'password' => ini_get('mysqli.default_pw'),
|
||||||
'socket' => (string) ini_get('mysqli.default_socket'),
|
'socket' => (string) ini_get('mysqli.default_socket'),
|
||||||
'port' => NULL,
|
'port' => null,
|
||||||
];
|
];
|
||||||
if (!isset($config['host'])) {
|
if (!isset($config['host'])) {
|
||||||
$host = ini_get('mysqli.default_host');
|
$host = ini_get('mysqli.default_host');
|
||||||
@@ -89,8 +89,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$config['host'] = $host;
|
$config['host'] = $host;
|
||||||
$config['port'] = ini_get('mysqli.default_port');
|
$config['port'] = ini_get('mysqli.default_port');
|
||||||
} else {
|
} else {
|
||||||
$config['host'] = NULL;
|
$config['host'] = null;
|
||||||
$config['port'] = NULL;
|
$config['port'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,19 +156,19 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
} elseif (is_object($res)) {
|
} elseif (is_object($res)) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
||||||
{
|
{
|
||||||
if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
|
if (in_array($code, [1216, 1217, 1451, 1452, 1701], true)) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) {
|
} elseif (in_array($code, [1062, 1557, 1569, 1586], true)) {
|
||||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) {
|
} elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], true)) {
|
||||||
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -200,7 +200,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function getAffectedRows(): ?int
|
public function getAffectedRows(): ?int
|
||||||
{
|
{
|
||||||
return mysqli_affected_rows($this->connection) === -1 ? NULL : mysqli_affected_rows($this->connection);
|
return mysqli_affected_rows($this->connection) === -1 ? null : mysqli_affected_rows($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function getResource(): \mysqli
|
public function getResource(): \mysqli
|
||||||
{
|
{
|
||||||
return @$this->connection->thread_id ? $this->connection : NULL;
|
return @$this->connection->thread_id ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -353,9 +353,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($limit < 0 || $offset < 0) {
|
if ($limit < 0 || $offset < 0) {
|
||||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL || $offset) {
|
} elseif ($limit !== null || $offset) {
|
||||||
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
|
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
|
||||||
$sql .= ' LIMIT ' . ($limit === NULL ? '18446744073709551615' : (int) $limit)
|
$sql .= ' LIMIT ' . ($limit === null ? '18446744073709551615' : (int) $limit)
|
||||||
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -414,7 +414,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
mysqli_free_result($this->resultSet);
|
mysqli_free_result($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -424,8 +424,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function getResultColumns(): array
|
public function getResultColumns(): array
|
||||||
{
|
{
|
||||||
static $types;
|
static $types;
|
||||||
if ($types === NULL) {
|
if ($types === null) {
|
||||||
$consts = get_defined_constants(TRUE);
|
$consts = get_defined_constants(true);
|
||||||
$types = [];
|
$types = [];
|
||||||
foreach ($consts['mysqli'] ?? [] as $key => $value) {
|
foreach ($consts['mysqli'] ?? [] as $key => $value) {
|
||||||
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
|
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
|
||||||
@@ -444,7 +444,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
'table' => $row['orgtable'],
|
'table' => $row['orgtable'],
|
||||||
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
||||||
'nativetype' => $types[$row['type']] ?? $row['type'],
|
'nativetype' => $types[$row['type']] ?? $row['type'],
|
||||||
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : NULL,
|
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : null,
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -457,7 +457,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function getResultResource(): ?\mysqli_result
|
public function getResultResource(): ?\mysqli_result
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return $this->resultSet;
|
return $this->resultSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,16 +27,16 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var int|NULL Affected rows */
|
/** @var int|null Affected rows */
|
||||||
private $affectedRows;
|
private $affectedRows;
|
||||||
|
|
||||||
/** @var int Cursor */
|
/** @var int Cursor */
|
||||||
@@ -98,17 +98,17 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
$this->affectedRows = NULL;
|
$this->affectedRows = null;
|
||||||
$res = @odbc_exec($this->connection, $sql); // intentionally @
|
$res = @odbc_exec($this->connection, $sql); // intentionally @
|
||||||
|
|
||||||
if ($res === FALSE) {
|
if ($res === false) {
|
||||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql);
|
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
$this->affectedRows = Dibi\Helpers::false2Null(odbc_num_rows($res));
|
$this->affectedRows = Dibi\Helpers::false2Null(odbc_num_rows($res));
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,9 +134,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!odbc_autocommit($this->connection, 0/*FALSE*/)) {
|
if (!odbc_autocommit($this->connection, 0/*false*/)) {
|
||||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,12 +146,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!odbc_commit($this->connection)) {
|
if (!odbc_commit($this->connection)) {
|
||||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||||
}
|
}
|
||||||
odbc_autocommit($this->connection, 1/*TRUE*/);
|
odbc_autocommit($this->connection, 1/*true*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -159,12 +159,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!odbc_rollback($this->connection)) {
|
if (!odbc_rollback($this->connection)) {
|
||||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||||
}
|
}
|
||||||
odbc_autocommit($this->connection, 1/*TRUE*/);
|
odbc_autocommit($this->connection, 1/*true*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,11 +179,11 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
} elseif ($limit < 0) {
|
} elseif ($limit < 0) {
|
||||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,7 +322,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -331,7 +331,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
} else {
|
} else {
|
||||||
$set = $this->resultSet;
|
$set = $this->resultSet;
|
||||||
if (!odbc_fetch_row($set, ++$this->row)) {
|
if (!odbc_fetch_row($set, ++$this->row)) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$count = odbc_num_fields($set);
|
$count = odbc_num_fields($set);
|
||||||
$cols = [];
|
$cols = [];
|
||||||
@@ -349,7 +349,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
public function seek(int $row): bool
|
public function seek(int $row): bool
|
||||||
{
|
{
|
||||||
$this->row = $row;
|
$this->row = $row;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
odbc_free_result($this->resultSet);
|
odbc_free_result($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -373,7 +373,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => odbc_field_name($this->resultSet, $i),
|
'name' => odbc_field_name($this->resultSet, $i),
|
||||||
'table' => NULL,
|
'table' => null,
|
||||||
'fullname' => odbc_field_name($this->resultSet, $i),
|
'fullname' => odbc_field_name($this->resultSet, $i),
|
||||||
'nativetype' => odbc_field_type($this->resultSet, $i),
|
'nativetype' => odbc_field_type($this->resultSet, $i),
|
||||||
];
|
];
|
||||||
@@ -384,12 +384,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ use Dibi;
|
|||||||
* - password (or pass)
|
* - password (or pass)
|
||||||
* - charset => character encoding to set
|
* - charset => character encoding to set
|
||||||
* - schema => alters session schema
|
* - schema => alters session schema
|
||||||
* - nativeDate => use native date format (defaults to TRUE)
|
* - nativeDate => use native date format (defaults to true)
|
||||||
* - resource (resource) => existing connection resource
|
* - resource (resource) => existing connection resource
|
||||||
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
|
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
|
||||||
* - lazy, profiler, result, substitutes, ... => see Dibi\Connection options
|
* - lazy, profiler, result, substitutes, ... => see Dibi\Connection options
|
||||||
@@ -30,22 +30,22 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autocommit = TRUE;
|
private $autocommit = true;
|
||||||
|
|
||||||
/** @var bool use native datetime format */
|
/** @var bool use native datetime format */
|
||||||
private $nativeDate;
|
private $nativeDate;
|
||||||
|
|
||||||
/** @var int|NULL Number of affected rows */
|
/** @var int|null Number of affected rows */
|
||||||
private $affectedRows;
|
private $affectedRows;
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (isset($config['formatDate']) || isset($config['formatDateTime'])) {
|
if (isset($config['formatDate']) || isset($config['formatDateTime'])) {
|
||||||
trigger_error('OracleDriver: options formatDate and formatDateTime are deprecated.', E_USER_DEPRECATED);
|
trigger_error('OracleDriver: options formatDate and formatDateTime are deprecated.', E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
$this->nativeDate = $config['nativeDate'] ?? TRUE;
|
$this->nativeDate = $config['nativeDate'] ?? true;
|
||||||
|
|
||||||
if (isset($config['resource'])) {
|
if (isset($config['resource'])) {
|
||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
@@ -107,7 +107,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
$this->affectedRows = NULL;
|
$this->affectedRows = null;
|
||||||
$res = oci_parse($this->connection, $sql);
|
$res = oci_parse($this->connection, $sql);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
||||||
@@ -123,19 +123,19 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
$err = oci_error($this->connection);
|
$err = oci_error($this->connection);
|
||||||
throw new Dibi\DriverException($err['message'], $err['code'], $sql);
|
throw new Dibi\DriverException($err['message'], $err['code'], $sql);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
||||||
{
|
{
|
||||||
if (in_array($code, [1, 2299, 38911], TRUE)) {
|
if (in_array($code, [1, 2299, 38911], true)) {
|
||||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (in_array($code, [1400], TRUE)) {
|
} elseif (in_array($code, [1400], true)) {
|
||||||
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (in_array($code, [2266, 2291, 2292], TRUE)) {
|
} elseif (in_array($code, [2266, 2291, 2292], true)) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -158,17 +158,17 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getInsertId(?string $sequence): ?int
|
public function getInsertId(?string $sequence): ?int
|
||||||
{
|
{
|
||||||
$row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(TRUE);
|
$row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(true);
|
||||||
return isset($row['ID']) ? (int) $row['ID'] : NULL;
|
return isset($row['ID']) ? (int) $row['ID'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->autocommit = FALSE;
|
$this->autocommit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -176,13 +176,13 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!oci_commit($this->connection)) {
|
if (!oci_commit($this->connection)) {
|
||||||
$err = oci_error($this->connection);
|
$err = oci_error($this->connection);
|
||||||
throw new Dibi\DriverException($err['message'], $err['code']);
|
throw new Dibi\DriverException($err['message'], $err['code']);
|
||||||
}
|
}
|
||||||
$this->autocommit = TRUE;
|
$this->autocommit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,23 +190,23 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!oci_rollback($this->connection)) {
|
if (!oci_rollback($this->connection)) {
|
||||||
$err = oci_error($this->connection);
|
$err = oci_error($this->connection);
|
||||||
throw new Dibi\DriverException($err['message'], $err['code']);
|
throw new Dibi\DriverException($err['message'], $err['code']);
|
||||||
}
|
}
|
||||||
$this->autocommit = TRUE;
|
$this->autocommit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -321,10 +321,10 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
} elseif ($offset) {
|
} elseif ($offset) {
|
||||||
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
|
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
|
||||||
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
|
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
|
||||||
. ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
|
. ($limit !== null ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
|
||||||
. ') WHERE "__rnum" > '. (int) $offset;
|
. ') WHERE "__rnum" > '. (int) $offset;
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
|
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -376,7 +376,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
oci_free_statement($this->resultSet);
|
oci_free_statement($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -391,7 +391,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
$type = oci_field_type($this->resultSet, $i);
|
$type = oci_field_type($this->resultSet, $i);
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => oci_field_name($this->resultSet, $i),
|
'name' => oci_field_name($this->resultSet, $i),
|
||||||
'table' => NULL,
|
'table' => null,
|
||||||
'fullname' => oci_field_name($this->resultSet, $i),
|
'fullname' => oci_field_name($this->resultSet, $i),
|
||||||
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
|
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
|
||||||
];
|
];
|
||||||
@@ -402,12 +402,12 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -421,7 +421,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->query('SELECT * FROM cat');
|
$res = $this->query('SELECT * FROM cat');
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
|
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
|
||||||
$tables[] = [
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
@@ -440,12 +440,12 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->query('SELECT * FROM "ALL_TAB_COLUMNS" WHERE "TABLE_NAME" = ' . $this->escapeText($table));
|
$res = $this->query('SELECT * FROM "ALL_TAB_COLUMNS" WHERE "TABLE_NAME" = ' . $this->escapeText($table));
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'table' => $row['TABLE_NAME'],
|
'table' => $row['TABLE_NAME'],
|
||||||
'name' => $row['COLUMN_NAME'],
|
'name' => $row['COLUMN_NAME'],
|
||||||
'nativetype' => $row['DATA_TYPE'],
|
'nativetype' => $row['DATA_TYPE'],
|
||||||
'size' => $row['DATA_LENGTH'] ?? NULL,
|
'size' => $row['DATA_LENGTH'] ?? null,
|
||||||
'nullable' => $row['NULLABLE'] === 'Y',
|
'nullable' => $row['NULLABLE'] === 'Y',
|
||||||
'default' => $row['DATA_DEFAULT'],
|
'default' => $row['DATA_DEFAULT'],
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
|
@@ -33,10 +33,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
/** @var PDO Connection resource */
|
/** @var PDO Connection resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var \PDOStatement|NULL Resultset resource */
|
/** @var \PDOStatement|null Resultset resource */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var int|NULL Affected rows */
|
/** @var int|null Affected rows */
|
||||||
private $affectedRows;
|
private $affectedRows;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@@ -91,7 +91,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function disconnect(): void
|
public function disconnect(): void
|
||||||
{
|
{
|
||||||
$this->connection = NULL;
|
$this->connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,12 +104,12 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
// must detect if SQL returns result set or num of affected rows
|
// must detect if SQL returns result set or num of affected rows
|
||||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||||
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
|
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
|
||||||
$this->affectedRows = NULL;
|
$this->affectedRows = null;
|
||||||
|
|
||||||
if (isset($list[$cmd])) {
|
if (isset($list[$cmd])) {
|
||||||
$this->affectedRows = Helpers::false2Null($this->connection->exec($sql));
|
$this->affectedRows = Helpers::false2Null($this->connection->exec($sql));
|
||||||
if ($this->affectedRows !== NULL) {
|
if ($this->affectedRows !== null) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$res = $this->connection->query($sql);
|
$res = $this->connection->query($sql);
|
||||||
@@ -161,7 +161,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!$this->connection->beginTransaction()) {
|
if (!$this->connection->beginTransaction()) {
|
||||||
$err = $this->connection->errorInfo();
|
$err = $this->connection->errorInfo();
|
||||||
@@ -174,7 +174,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!$this->connection->commit()) {
|
if (!$this->connection->commit()) {
|
||||||
$err = $this->connection->errorInfo();
|
$err = $this->connection->errorInfo();
|
||||||
@@ -187,7 +187,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
if (!$this->connection->rollBack()) {
|
if (!$this->connection->rollBack()) {
|
||||||
$err = $this->connection->errorInfo();
|
$err = $this->connection->errorInfo();
|
||||||
@@ -379,15 +379,15 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
switch ($this->driverName) {
|
switch ($this->driverName) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
if ($limit !== NULL || $offset) {
|
if ($limit !== null || $offset) {
|
||||||
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
|
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
|
||||||
$sql .= ' LIMIT ' . ($limit === NULL ? '18446744073709551615' : (int) $limit)
|
$sql .= ' LIMIT ' . ($limit === null ? '18446744073709551615' : (int) $limit)
|
||||||
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
if ($limit !== NULL) {
|
if ($limit !== null) {
|
||||||
$sql .= ' LIMIT ' . (int) $limit;
|
$sql .= ' LIMIT ' . (int) $limit;
|
||||||
}
|
}
|
||||||
if ($offset) {
|
if ($offset) {
|
||||||
@@ -396,8 +396,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
if ($limit !== NULL || $offset) {
|
if ($limit !== null || $offset) {
|
||||||
$sql .= ' LIMIT ' . ($limit === NULL ? '-1' : (int) $limit)
|
$sql .= ' LIMIT ' . ($limit === null ? '-1' : (int) $limit)
|
||||||
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -406,10 +406,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($offset) {
|
if ($offset) {
|
||||||
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
|
// see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
|
||||||
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
|
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
|
||||||
. ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
|
. ($limit !== null ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
|
||||||
. ') WHERE "__rnum" > '. (int) $offset;
|
. ') WHERE "__rnum" > '. (int) $offset;
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
|
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -419,7 +419,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
case 'dblib':
|
case 'dblib':
|
||||||
if (version_compare($this->serverVersion, '11.0') >= 0) { // 11 == SQL Server 2012
|
if (version_compare($this->serverVersion, '11.0') >= 0) { // 11 == SQL Server 2012
|
||||||
// requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx
|
// requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx
|
||||||
if ($limit !== NULL) {
|
if ($limit !== null) {
|
||||||
$sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit);
|
$sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit);
|
||||||
} elseif ($offset) {
|
} elseif ($offset) {
|
||||||
$sql = sprintf('%s OFFSET %d ROWS', rtrim($sql), $offset);
|
$sql = sprintf('%s OFFSET %d ROWS', rtrim($sql), $offset);
|
||||||
@@ -432,7 +432,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($offset) {
|
if ($offset) {
|
||||||
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -480,7 +480,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -494,11 +494,11 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$columns = [];
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = @$this->resultSet->getColumnMeta($i); // intentionally @
|
$row = @$this->resultSet->getColumnMeta($i); // intentionally @
|
||||||
if ($row === FALSE) {
|
if ($row === false) {
|
||||||
throw new Dibi\NotSupportedException('Driver does not support meta data.');
|
throw new Dibi\NotSupportedException('Driver does not support meta data.');
|
||||||
}
|
}
|
||||||
$row = $row + [
|
$row = $row + [
|
||||||
'table' => NULL,
|
'table' => null,
|
||||||
'native_type' => 'VAR_STRING',
|
'native_type' => 'VAR_STRING',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -506,7 +506,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'table' => $row['table'],
|
'table' => $row['table'],
|
||||||
'nativetype' => $row['native_type'],
|
'nativetype' => $row['native_type'],
|
||||||
'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : NULL,
|
'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : null,
|
||||||
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
];
|
];
|
||||||
|
@@ -29,16 +29,16 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var int|NULL Affected rows */
|
/** @var int|null Affected rows */
|
||||||
private $affectedRows;
|
private $affectedRows;
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function connect(array &$config): void
|
public function connect(array &$config): void
|
||||||
{
|
{
|
||||||
$error = NULL;
|
$error = null;
|
||||||
if (isset($config['resource'])) {
|
if (isset($config['resource'])) {
|
||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
|
|
||||||
@@ -132,11 +132,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
$this->affectedRows = NULL;
|
$this->affectedRows = null;
|
||||||
$res = @pg_query($this->connection, $sql); // intentionally @
|
$res = @pg_query($this->connection, $sql); // intentionally @
|
||||||
|
|
||||||
if ($res === FALSE) {
|
if ($res === false) {
|
||||||
throw self::createException(pg_last_error($this->connection), NULL, $sql);
|
throw self::createException(pg_last_error($this->connection), null, $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
||||||
@@ -144,18 +144,18 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function createException(string $message, $code = NULL, string $sql = NULL): Dibi\DriverException
|
public static function createException(string $message, $code = null, string $sql = null): Dibi\DriverException
|
||||||
{
|
{
|
||||||
if ($code === NULL && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) {
|
if ($code === null && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) {
|
||||||
$code = $m[1];
|
$code = $m[1];
|
||||||
$message = substr($message, strlen($m[0]));
|
$message = substr($message, strlen($m[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code === '0A000' && strpos($message, 'truncate') !== FALSE) {
|
if ($code === '0A000' && strpos($message, 'truncate') !== false) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif ($code === '23502') {
|
} elseif ($code === '23502') {
|
||||||
@@ -187,7 +187,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getInsertId(?string $sequence): ?int
|
public function getInsertId(?string $sequence): ?int
|
||||||
{
|
{
|
||||||
if ($sequence === NULL) {
|
if ($sequence === null) {
|
||||||
// PostgreSQL 8.1 is needed
|
// PostgreSQL 8.1 is needed
|
||||||
$res = $this->query('SELECT LASTVAL()');
|
$res = $this->query('SELECT LASTVAL()');
|
||||||
} else {
|
} else {
|
||||||
@@ -195,11 +195,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = $res->fetch(FALSE);
|
$row = $res->fetch(false);
|
||||||
return is_array($row) ? $row[0] : NULL;
|
return is_array($row) ? $row[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||||
}
|
}
|
||||||
@@ -238,17 +238,17 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function inTransaction(): bool
|
public function inTransaction(): bool
|
||||||
{
|
{
|
||||||
return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], TRUE);
|
return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if ($limit < 0 || $offset < 0) {
|
if ($limit < 0 || $offset < 0) {
|
||||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||||
}
|
}
|
||||||
if ($limit !== NULL) {
|
if ($limit !== null) {
|
||||||
$sql .= ' LIMIT ' . (int) $limit;
|
$sql .= ' LIMIT ' . (int) $limit;
|
||||||
}
|
}
|
||||||
if ($offset) {
|
if ($offset) {
|
||||||
@@ -395,11 +395,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
return Helpers::false2Null(pg_fetch_array($this->resultSet, NULL, $assoc ? PGSQL_ASSOC : PGSQL_NUM));
|
return Helpers::false2Null(pg_fetch_array($this->resultSet, null, $assoc ? PGSQL_ASSOC : PGSQL_NUM));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -418,7 +418,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
pg_free_result($this->resultSet);
|
pg_free_result($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -444,12 +444,12 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -543,13 +543,13 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
}
|
}
|
||||||
|
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$size = (int) max($row['character_maximum_length'], $row['numeric_precision']);
|
$size = (int) max($row['character_maximum_length'], $row['numeric_precision']);
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => $row['column_name'],
|
'name' => $row['column_name'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($row['udt_name']),
|
'nativetype' => strtoupper($row['udt_name']),
|
||||||
'size' => $size > 0 ? $size : NULL,
|
'size' => $size > 0 ? $size : null,
|
||||||
'nullable' => $row['is_nullable'] === 'YES' || $row['is_nullable'] === 't',
|
'nullable' => $row['is_nullable'] === 'YES' || $row['is_nullable'] === 't',
|
||||||
'default' => $row['column_default'],
|
'default' => $row['column_default'],
|
||||||
'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval',
|
'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval',
|
||||||
@@ -581,7 +581,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$columns[$row['ordinal_position']] = $row['column_name'];
|
$columns[$row['ordinal_position']] = $row['column_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$indexes[$row['relname']]['name'] = $row['relname'];
|
$indexes[$row['relname']]['name'] = $row['relname'];
|
||||||
$indexes[$row['relname']]['unique'] = $row['indisunique'] === 't';
|
$indexes[$row['relname']]['unique'] = $row['indisunique'] === 't';
|
||||||
$indexes[$row['relname']]['primary'] = $row['indisprimary'] === 't';
|
$indexes[$row['relname']]['primary'] = $row['indisprimary'] === 't';
|
||||||
@@ -653,7 +653,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$fKeys = $references = [];
|
$fKeys = $references = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
if (!isset($fKeys[$row['name']])) {
|
if (!isset($fKeys[$row['name']])) {
|
||||||
$fKeys[$row['name']] = [
|
$fKeys[$row['name']] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
|
@@ -29,14 +29,14 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var SQLite3|NULL */
|
/** @var SQLite3|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var \SQLite3Result|NULL */
|
/** @var \SQLite3Result|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var string Date and datetime format */
|
/** @var string Date and datetime format */
|
||||||
private $fmtDate, $fmtDateTime;
|
private $fmtDate, $fmtDateTime;
|
||||||
@@ -79,7 +79,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
|
$this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
|
||||||
$this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
|
$this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
|
||||||
if (strcasecmp($this->dbcharset, $this->charset) === 0) {
|
if (strcasecmp($this->dbcharset, $this->charset) === 0) {
|
||||||
$this->dbcharset = $this->charset = NULL;
|
$this->dbcharset = $this->charset = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced)
|
// enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced)
|
||||||
@@ -105,7 +105,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
if ($this->dbcharset !== NULL) {
|
if ($this->dbcharset !== null) {
|
||||||
$sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql);
|
$sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
} elseif ($res instanceof \SQLite3Result) {
|
} elseif ($res instanceof \SQLite3Result) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,19 +125,19 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($code !== 19) {
|
if ($code !== 19) {
|
||||||
return new Dibi\DriverException($message, $code, $sql);
|
return new Dibi\DriverException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'must be unique') !== FALSE
|
} elseif (strpos($message, 'must be unique') !== false
|
||||||
|| strpos($message, 'is not unique') !== FALSE
|
|| strpos($message, 'is not unique') !== false
|
||||||
|| strpos($message, 'UNIQUE constraint failed') !== FALSE
|
|| strpos($message, 'UNIQUE constraint failed') !== false
|
||||||
) {
|
) {
|
||||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'may not be NULL') !== FALSE
|
} elseif (strpos($message, 'may not be null') !== false
|
||||||
|| strpos($message, 'NOT NULL constraint failed') !== FALSE
|
|| strpos($message, 'NOT NULL constraint failed') !== false
|
||||||
) {
|
) {
|
||||||
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'foreign key constraint failed') !== FALSE
|
} elseif (strpos($message, 'foreign key constraint failed') !== false
|
||||||
|| strpos($message, 'FOREIGN KEY constraint failed') !== FALSE
|
|| strpos($message, 'FOREIGN KEY constraint failed') !== false
|
||||||
) {
|
) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'BEGIN');
|
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'BEGIN');
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||||
}
|
}
|
||||||
@@ -305,8 +305,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($limit < 0 || $offset < 0) {
|
if ($limit < 0 || $offset < 0) {
|
||||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL || $offset) {
|
} elseif ($limit !== null || $offset) {
|
||||||
$sql .= ' LIMIT ' . ($limit === NULL ? '-1' : (int) $limit)
|
$sql .= ' LIMIT ' . ($limit === null ? '-1' : (int) $limit)
|
||||||
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
. ($offset ? ' OFFSET ' . (int) $offset : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,19 +336,19 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
$row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM);
|
$row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM);
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT';
|
$charset = $this->charset === null ? null : $this->charset . '//TRANSLIT';
|
||||||
if ($row && ($assoc || $charset)) {
|
if ($row && ($assoc || $charset)) {
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
foreach ($row as $k => $v) {
|
foreach ($row as $k => $v) {
|
||||||
if ($charset !== NULL && is_string($v)) {
|
if ($charset !== null && is_string($v)) {
|
||||||
$v = iconv($this->dbcharset, $charset, $v);
|
$v = iconv($this->dbcharset, $charset, $v);
|
||||||
}
|
}
|
||||||
$tmp[str_replace(['[', ']'], '', $k)] = $v;
|
$tmp[str_replace(['[', ']'], '', $k)] = $v;
|
||||||
@@ -375,7 +375,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
$this->resultSet->finalize();
|
$this->resultSet->finalize();
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'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)],
|
||||||
];
|
];
|
||||||
@@ -404,7 +404,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function getResultResource(): ?\SQLite3Result
|
public function getResultResource(): ?\SQLite3Result
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return $this->resultSet;
|
return $this->resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
ORDER BY name
|
ORDER BY name
|
||||||
");
|
");
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$tables[] = $row;
|
$tables[] = $row;
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
@@ -56,7 +56,7 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})");
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$column = $row['name'];
|
$column = $row['name'];
|
||||||
$type = explode('(', $row['type']);
|
$type = explode('(', $row['type']);
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
@@ -64,7 +64,7 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
'table' => $table,
|
'table' => $table,
|
||||||
'fullname' => "$table.$column",
|
'fullname' => "$table.$column",
|
||||||
'nativetype' => strtoupper($type[0]),
|
'nativetype' => strtoupper($type[0]),
|
||||||
'size' => isset($type[1]) ? (int) $type[1] : NULL,
|
'size' => isset($type[1]) ? (int) $type[1] : null,
|
||||||
'nullable' => $row['notnull'] == '0',
|
'nullable' => $row['notnull'] == '0',
|
||||||
'default' => $row['dflt_value'],
|
'default' => $row['dflt_value'],
|
||||||
'autoincrement' => $row['pk'] && $type[0] === 'INTEGER',
|
'autoincrement' => $row['pk'] && $type[0] === 'INTEGER',
|
||||||
@@ -82,14 +82,14 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})");
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$indexes[$row['name']]['name'] = $row['name'];
|
$indexes[$row['name']]['name'] = $row['name'];
|
||||||
$indexes[$row['name']]['unique'] = (bool) $row['unique'];
|
$indexes[$row['name']]['unique'] = (bool) $row['unique'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($indexes as $index => $values) {
|
foreach ($indexes as $index => $values) {
|
||||||
$res = $this->driver->query("PRAGMA index_info({$this->driver->escapeIdentifier($index)})");
|
$res = $this->driver->query("PRAGMA index_info({$this->driver->escapeIdentifier($index)})");
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$indexes[$index]['columns'][$row['seqno']] = $row['name'];
|
$indexes[$index]['columns'][$row['seqno']] = $row['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
$columns = $this->getColumns($table);
|
$columns = $this->getColumns($table);
|
||||||
foreach ($indexes as $index => $values) {
|
foreach ($indexes as $index => $values) {
|
||||||
$column = $indexes[$index]['columns'][0];
|
$column = $indexes[$index]['columns'][0];
|
||||||
$primary = FALSE;
|
$primary = false;
|
||||||
foreach ($columns as $info) {
|
foreach ($columns as $info) {
|
||||||
if ($column == $info['name']) {
|
if ($column == $info['name']) {
|
||||||
$primary = $info['vendor']['pk'];
|
$primary = $info['vendor']['pk'];
|
||||||
@@ -111,8 +111,8 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
if ($column['vendor']['pk']) {
|
if ($column['vendor']['pk']) {
|
||||||
$indexes[] = [
|
$indexes[] = [
|
||||||
'name' => 'ROWID',
|
'name' => 'ROWID',
|
||||||
'unique' => TRUE,
|
'unique' => true,
|
||||||
'primary' => TRUE,
|
'primary' => true,
|
||||||
'columns' => [$column['name']],
|
'columns' => [$column['name']],
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
@@ -131,7 +131,7 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})");
|
||||||
$keys = [];
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$keys[$row['id']]['name'] = $row['id']; // foreign key name
|
$keys[$row['id']]['name'] = $row['id']; // foreign key name
|
||||||
$keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns
|
$keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns
|
||||||
$keys[$row['id']]['table'] = $row['table']; // referenced table
|
$keys[$row['id']]['table'] = $row['table']; // referenced table
|
||||||
@@ -139,8 +139,8 @@ class SqliteReflector implements Dibi\Reflector
|
|||||||
$keys[$row['id']]['onDelete'] = $row['on_delete'];
|
$keys[$row['id']]['onDelete'] = $row['on_delete'];
|
||||||
$keys[$row['id']]['onUpdate'] = $row['on_update'];
|
$keys[$row['id']]['onUpdate'] = $row['on_update'];
|
||||||
|
|
||||||
if ($keys[$row['id']]['foreign'][0] == NULL) {
|
if ($keys[$row['id']]['foreign'][0] == null) {
|
||||||
$keys[$row['id']]['foreign'] = NULL;
|
$keys[$row['id']]['foreign'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_values($keys);
|
return array_values($keys);
|
||||||
|
@@ -31,16 +31,16 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|NULL */
|
/** @var resource|null */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $autoFree = TRUE;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var int|NULL Affected rows */
|
/** @var int|null Affected rows */
|
||||||
private $affectedRows;
|
private $affectedRows;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@@ -107,10 +107,10 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
$this->affectedRows = NULL;
|
$this->affectedRows = null;
|
||||||
$res = sqlsrv_query($this->connection, $sql);
|
$res = sqlsrv_query($this->connection, $sql);
|
||||||
|
|
||||||
if ($res === FALSE) {
|
if ($res === false) {
|
||||||
$info = sqlsrv_errors();
|
$info = sqlsrv_errors();
|
||||||
throw new Dibi\DriverException($info[0]['message'], $info[0]['code'], $sql);
|
throw new Dibi\DriverException($info[0]['message'], $info[0]['code'], $sql);
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$this->affectedRows = Helpers::false2Null(sqlsrv_rows_affected($res));
|
$this->affectedRows = Helpers::false2Null(sqlsrv_rows_affected($res));
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC);
|
$row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC);
|
||||||
return (int) $row[0];
|
return (int) $row[0];
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function begin(string $savepoint = NULL): void
|
public function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
sqlsrv_begin_transaction($this->connection);
|
sqlsrv_begin_transaction($this->connection);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function commit(string $savepoint = NULL): void
|
public function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
sqlsrv_commit($this->connection);
|
sqlsrv_commit($this->connection);
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function rollback(string $savepoint = NULL): void
|
public function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
sqlsrv_rollback($this->connection);
|
sqlsrv_rollback($this->connection);
|
||||||
}
|
}
|
||||||
@@ -177,11 +177,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource()
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) ? $this->connection : NULL;
|
return is_resource($this->connection) ? $this->connection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -292,11 +292,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($offset) {
|
if ($offset) {
|
||||||
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
$sql = sprintf('SELECT TOP (%d) * FROM (%s) t', $limit, $sql);
|
$sql = sprintf('SELECT TOP (%d) * FROM (%s) t', $limit, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($limit !== NULL) {
|
} elseif ($limit !== null) {
|
||||||
// requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx
|
// requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx
|
||||||
$sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit);
|
$sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit);
|
||||||
} elseif ($offset) {
|
} elseif ($offset) {
|
||||||
@@ -329,7 +329,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
*/
|
*/
|
||||||
public function fetch(bool $assoc): ?array
|
public function fetch(bool $assoc): ?array
|
||||||
{
|
{
|
||||||
@@ -352,7 +352,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function free(): void
|
public function free(): void
|
||||||
{
|
{
|
||||||
sqlsrv_free_stmt($this->resultSet);
|
sqlsrv_free_stmt($this->resultSet);
|
||||||
$this->resultSet = NULL;
|
$this->resultSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -375,11 +375,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|NULL
|
* @return resource|null
|
||||||
*/
|
*/
|
||||||
public function getResultResource()
|
public function getResultResource()
|
||||||
{
|
{
|
||||||
$this->autoFree = FALSE;
|
$this->autoFree = false;
|
||||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
return is_resource($this->resultSet) ? $this->resultSet : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$res = $this->driver->query("SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE [TABLE_SCHEMA] = 'dbo'");
|
$res = $this->driver->query("SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE [TABLE_SCHEMA] = 'dbo'");
|
||||||
$tables = [];
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(false)) {
|
||||||
$tables[] = [
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
@@ -60,7 +60,7 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
");
|
");
|
||||||
|
|
||||||
$autoIncrements = [];
|
$autoIncrements = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT'];
|
$autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,13 +80,13 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
WHERE C.TABLE_NAME = {$this->driver->escapeText($table)}
|
WHERE C.TABLE_NAME = {$this->driver->escapeText($table)}
|
||||||
");
|
");
|
||||||
$columns = [];
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => $row['COLUMN_NAME'],
|
'name' => $row['COLUMN_NAME'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($row['DATA_TYPE']),
|
'nativetype' => strtoupper($row['DATA_TYPE']),
|
||||||
'size' => $row['CHARACTER_MAXIMUM_LENGTH'],
|
'size' => $row['CHARACTER_MAXIMUM_LENGTH'],
|
||||||
'unsigned' => TRUE,
|
'unsigned' => true,
|
||||||
'nullable' => $row['IS_NULLABLE'] === 'YES',
|
'nullable' => $row['IS_NULLABLE'] === 'YES',
|
||||||
'default' => $row['COLUMN_DEFAULT'],
|
'default' => $row['COLUMN_DEFAULT'],
|
||||||
'autoincrement' => $autoIncrements[$row['COLUMN_NAME']],
|
'autoincrement' => $autoIncrements[$row['COLUMN_NAME']],
|
||||||
@@ -104,13 +104,13 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
{
|
{
|
||||||
$keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table)));
|
$keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table)));
|
||||||
$keyUsages = [];
|
$keyUsages = [];
|
||||||
while ($row = $keyUsagesRes->fetch(TRUE)) {
|
while ($row = $keyUsagesRes->fetch(true)) {
|
||||||
$keyUsages[$row['index_name']] = explode(',', $row['index_keys']);
|
$keyUsages[$row['index_name']] = explode(',', $row['index_keys']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->driver->query("SELECT [i].* FROM [sys].[indexes] [i] INNER JOIN [sys].[tables] [t] ON [i].[object_id] = [t].[object_id] WHERE [t].[name] = {$this->driver->escapeText($table)}");
|
$res = $this->driver->query("SELECT [i].* FROM [sys].[indexes] [i] INNER JOIN [sys].[tables] [t] ON [i].[object_id] = [t].[object_id] WHERE [t].[name] = {$this->driver->escapeText($table)}");
|
||||||
$indexes = [];
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(true)) {
|
||||||
$indexes[$row['name']]['name'] = $row['name'];
|
$indexes[$row['name']]['name'] = $row['name'];
|
||||||
$indexes[$row['name']]['unique'] = $row['is_unique'] === 1;
|
$indexes[$row['name']]['unique'] = $row['is_unique'] === 1;
|
||||||
$indexes[$row['name']]['primary'] = $row['is_primary_key'] === 1;
|
$indexes[$row['name']]['primary'] = $row['is_primary_key'] === 1;
|
||||||
|
@@ -39,7 +39,7 @@ class Event
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
public $sql;
|
public $sql;
|
||||||
|
|
||||||
/** @var Result|DriverException|NULL */
|
/** @var Result|DriverException|null */
|
||||||
public $result;
|
public $result;
|
||||||
|
|
||||||
/** @var float */
|
/** @var float */
|
||||||
@@ -52,12 +52,12 @@ class Event
|
|||||||
public $source;
|
public $source;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Connection $connection, $type, $sql = NULL)
|
public function __construct(Connection $connection, $type, $sql = null)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->sql = trim($sql);
|
$this->sql = trim($sql);
|
||||||
$this->time = -microtime(TRUE);
|
$this->time = -microtime(true);
|
||||||
|
|
||||||
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
||||||
static $types = [
|
static $types = [
|
||||||
@@ -76,22 +76,22 @@ class Event
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
\dibi::$elapsedTime = FALSE;
|
\dibi::$elapsedTime = false;
|
||||||
\dibi::$numOfQueries++;
|
\dibi::$numOfQueries++;
|
||||||
\dibi::$sql = $sql;
|
\dibi::$sql = $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function done($result = NULL)
|
public function done($result = null)
|
||||||
{
|
{
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
try {
|
try {
|
||||||
$this->count = $result instanceof Result ? count($result) : NULL;
|
$this->count = $result instanceof Result ? count($result) : null;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->count = NULL;
|
$this->count = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->time += microtime(TRUE);
|
$this->time += microtime(true);
|
||||||
\dibi::$elapsedTime = $this->time;
|
\dibi::$elapsedTime = $this->time;
|
||||||
\dibi::$totalTime += $this->time;
|
\dibi::$totalTime += $this->time;
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -35,7 +35,7 @@ class Fluent implements IDataSource
|
|||||||
{
|
{
|
||||||
use Strict;
|
use Strict;
|
||||||
|
|
||||||
const REMOVE = FALSE;
|
const REMOVE = false;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public static $masks = [
|
public static $masks = [
|
||||||
@@ -67,11 +67,11 @@ class Fluent implements IDataSource
|
|||||||
'GROUP BY' => ',',
|
'GROUP BY' => ',',
|
||||||
'HAVING' => 'AND',
|
'HAVING' => 'AND',
|
||||||
'ORDER BY' => ',',
|
'ORDER BY' => ',',
|
||||||
'LIMIT' => FALSE,
|
'LIMIT' => false,
|
||||||
'OFFSET' => FALSE,
|
'OFFSET' => false,
|
||||||
'SET' => ',',
|
'SET' => ',',
|
||||||
'VALUES' => ',',
|
'VALUES' => ',',
|
||||||
'INTO' => FALSE,
|
'INTO' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array clauses */
|
/** @var array clauses */
|
||||||
@@ -108,7 +108,7 @@ class Fluent implements IDataSource
|
|||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
|
|
||||||
if (self::$normalizer === NULL) {
|
if (self::$normalizer === null) {
|
||||||
self::$normalizer = new HashMap([__CLASS__, '_formatClause']);
|
self::$normalizer = new HashMap([__CLASS__, '_formatClause']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,9 +122,9 @@ class Fluent implements IDataSource
|
|||||||
$clause = self::$normalizer->$clause;
|
$clause = self::$normalizer->$clause;
|
||||||
|
|
||||||
// lazy initialization
|
// lazy initialization
|
||||||
if ($this->command === NULL) {
|
if ($this->command === null) {
|
||||||
if (isset(self::$masks[$clause])) {
|
if (isset(self::$masks[$clause])) {
|
||||||
$this->clauses = array_fill_keys(self::$masks[$clause], NULL);
|
$this->clauses = array_fill_keys(self::$masks[$clause], null);
|
||||||
}
|
}
|
||||||
$this->cursor = &$this->clauses[$clause];
|
$this->cursor = &$this->clauses[$clause];
|
||||||
$this->cursor = [];
|
$this->cursor = [];
|
||||||
@@ -142,13 +142,13 @@ class Fluent implements IDataSource
|
|||||||
|
|
||||||
// TODO: really delete?
|
// TODO: really delete?
|
||||||
if ($args === [self::REMOVE]) {
|
if ($args === [self::REMOVE]) {
|
||||||
$this->cursor = NULL;
|
$this->cursor = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset(self::$separators[$clause])) {
|
if (isset(self::$separators[$clause])) {
|
||||||
$sep = self::$separators[$clause];
|
$sep = self::$separators[$clause];
|
||||||
if ($sep === FALSE) { // means: replace
|
if ($sep === false) { // means: replace
|
||||||
$this->cursor = [];
|
$this->cursor = [];
|
||||||
|
|
||||||
} elseif (!empty($this->cursor)) {
|
} elseif (!empty($this->cursor)) {
|
||||||
@@ -165,15 +165,15 @@ class Fluent implements IDataSource
|
|||||||
$this->cursor[] = $clause;
|
$this->cursor[] = $clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cursor === NULL) {
|
if ($this->cursor === null) {
|
||||||
$this->cursor = [];
|
$this->cursor = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// special types or argument
|
// special types or argument
|
||||||
if (count($args) === 1) {
|
if (count($args) === 1) {
|
||||||
$arg = $args[0];
|
$arg = $args[0];
|
||||||
// TODO: really ignore TRUE?
|
// TODO: really ignore true?
|
||||||
if ($arg === TRUE) { // flag
|
if ($arg === true) { // flag
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
||||||
@@ -186,7 +186,7 @@ class Fluent implements IDataSource
|
|||||||
} elseif (is_string(key($arg))) { // associative array
|
} elseif (is_string(key($arg))) { // associative array
|
||||||
$args = ['%a', $arg];
|
$args = ['%a', $arg];
|
||||||
}
|
}
|
||||||
} // case $arg === FALSE is handled above
|
} // case $arg === false is handled above
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
@@ -206,7 +206,7 @@ class Fluent implements IDataSource
|
|||||||
public function clause(string $clause): self
|
public function clause(string $clause): self
|
||||||
{
|
{
|
||||||
$this->cursor = &$this->clauses[self::$normalizer->$clause];
|
$this->cursor = &$this->clauses[self::$normalizer->$clause];
|
||||||
if ($this->cursor === NULL) {
|
if ($this->cursor === null) {
|
||||||
$this->cursor = [];
|
$this->cursor = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ class Fluent implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function removeClause(string $clause): self
|
public function removeClause(string $clause): self
|
||||||
{
|
{
|
||||||
$this->clauses[self::$normalizer->$clause] = NULL;
|
$this->clauses[self::$normalizer->$clause] = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,11 +227,11 @@ class Fluent implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Change a SQL flag.
|
* Change a SQL flag.
|
||||||
*/
|
*/
|
||||||
public function setFlag(string $flag, bool $value = TRUE): self
|
public function setFlag(string $flag, bool $value = true): self
|
||||||
{
|
{
|
||||||
$flag = strtoupper($flag);
|
$flag = strtoupper($flag);
|
||||||
if ($value) {
|
if ($value) {
|
||||||
$this->flags[$flag] = TRUE;
|
$this->flags[$flag] = true;
|
||||||
} else {
|
} else {
|
||||||
unset($this->flags[$flag]);
|
unset($this->flags[$flag]);
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ class Fluent implements IDataSource
|
|||||||
* @return Result|int result set or number of affected rows
|
* @return Result|int result set or number of affected rows
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function execute($return = NULL)
|
public function execute($return = null)
|
||||||
{
|
{
|
||||||
$res = $this->query($this->_export());
|
$res = $this->query($this->_export());
|
||||||
switch ($return) {
|
switch ($return) {
|
||||||
@@ -307,7 +307,7 @@ class Fluent implements IDataSource
|
|||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||||
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetch();
|
return $this->query($this->_export(null, ['%lmt', 1]))->fetch();
|
||||||
} else {
|
} else {
|
||||||
return $this->query($this->_export())->fetch();
|
return $this->query($this->_export())->fetch();
|
||||||
}
|
}
|
||||||
@@ -316,12 +316,12 @@ class Fluent implements IDataSource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Like fetch(), but returns only first field.
|
* Like fetch(), but returns only first field.
|
||||||
* @return mixed value on success, NULL if no next record
|
* @return mixed value on success, null if no next record
|
||||||
*/
|
*/
|
||||||
public function fetchSingle()
|
public function fetchSingle()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||||
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetchSingle();
|
return $this->query($this->_export(null, ['%lmt', 1]))->fetchSingle();
|
||||||
} else {
|
} else {
|
||||||
return $this->query($this->_export())->fetchSingle();
|
return $this->query($this->_export())->fetchSingle();
|
||||||
}
|
}
|
||||||
@@ -331,9 +331,9 @@ class Fluent implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Fetches all records from table.
|
* Fetches all records from table.
|
||||||
*/
|
*/
|
||||||
public function fetchAll(int $offset = NULL, int $limit = NULL): array
|
public function fetchAll(int $offset = null, int $limit = null): array
|
||||||
{
|
{
|
||||||
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->fetchAll();
|
return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ class Fluent implements IDataSource
|
|||||||
* Fetches all records from table like $key => $value pairs.
|
* Fetches all records from table like $key => $value pairs.
|
||||||
* @param string associative key
|
* @param string associative key
|
||||||
*/
|
*/
|
||||||
public function fetchPairs(string $key = NULL, string $value = NULL): array
|
public function fetchPairs(string $key = null, string $value = null): array
|
||||||
{
|
{
|
||||||
return $this->query($this->_export())->fetchPairs($key, $value);
|
return $this->query($this->_export())->fetchPairs($key, $value);
|
||||||
}
|
}
|
||||||
@@ -360,9 +360,9 @@ class Fluent implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Required by the IteratorAggregate interface.
|
* Required by the IteratorAggregate interface.
|
||||||
*/
|
*/
|
||||||
public function getIterator(int $offset = NULL, int $limit = NULL): ResultIterator
|
public function getIterator(int $offset = null, int $limit = null): ResultIterator
|
||||||
{
|
{
|
||||||
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->getIterator();
|
return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->getIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ class Fluent implements IDataSource
|
|||||||
* Generates and prints SQL query or it's part.
|
* Generates and prints SQL query or it's part.
|
||||||
* @param string clause name
|
* @param string clause name
|
||||||
*/
|
*/
|
||||||
public function test(string $clause = NULL): bool
|
public function test(string $clause = null): bool
|
||||||
{
|
{
|
||||||
return $this->connection->test($this->_export($clause));
|
return $this->connection->test($this->_export($clause));
|
||||||
}
|
}
|
||||||
@@ -421,9 +421,9 @@ class Fluent implements IDataSource
|
|||||||
* Generates parameters for Translator.
|
* Generates parameters for Translator.
|
||||||
* @param string clause name
|
* @param string clause name
|
||||||
*/
|
*/
|
||||||
protected function _export(string $clause = NULL, array $args = []): array
|
protected function _export(string $clause = null, array $args = []): array
|
||||||
{
|
{
|
||||||
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], $data['OFFSET'][0]], $args);
|
||||||
@@ -440,7 +440,7 @@ class Fluent implements IDataSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $clause => $statement) {
|
foreach ($data as $clause => $statement) {
|
||||||
if ($statement !== NULL) {
|
if ($statement !== null) {
|
||||||
$args[] = $clause;
|
$args[] = $clause;
|
||||||
if ($clause === $this->command && $this->flags) {
|
if ($clause === $this->command && $this->flags) {
|
||||||
$args[] = implode(' ', array_keys($this->flags));
|
$args[] = implode(' ', array_keys($this->flags));
|
||||||
|
@@ -22,7 +22,7 @@ class Helpers
|
|||||||
* Prints out a syntax highlighted version of the SQL command or Result.
|
* Prints out a syntax highlighted version of the SQL command or Result.
|
||||||
* @param string|Result
|
* @param string|Result
|
||||||
*/
|
*/
|
||||||
public static function dump($sql = NULL, bool $return = FALSE): string
|
public static function dump($sql = null, bool $return = false): string
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
if ($sql instanceof Result && PHP_SAPI === 'cli') {
|
if ($sql instanceof Result && PHP_SAPI === 'cli') {
|
||||||
@@ -68,7 +68,7 @@ class Helpers
|
|||||||
: "</tbody>\n</table>\n";
|
: "</tbody>\n</table>\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ($sql === NULL) {
|
if ($sql === null) {
|
||||||
$sql = \dibi::$sql;
|
$sql = \dibi::$sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ class Helpers
|
|||||||
*/
|
*/
|
||||||
public static function getSuggestion(array $items, $value): ?string
|
public static function getSuggestion(array $items, $value): ?string
|
||||||
{
|
{
|
||||||
$best = NULL;
|
$best = null;
|
||||||
$min = (strlen($value) / 4 + 1) * 10 + .1;
|
$min = (strlen($value) / 4 + 1) * 10 + .1;
|
||||||
foreach (array_unique($items, SORT_REGULAR) as $item) {
|
foreach (array_unique($items, SORT_REGULAR) as $item) {
|
||||||
$item = is_object($item) ? $item->getName() : $item;
|
$item = is_object($item) ? $item->getName() : $item;
|
||||||
@@ -195,7 +195,7 @@ class Helpers
|
|||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ class Helpers
|
|||||||
*/
|
*/
|
||||||
public static function getTypeCache()
|
public static function getTypeCache()
|
||||||
{
|
{
|
||||||
if (self::$types === NULL) {
|
if (self::$types === null) {
|
||||||
self::$types = new HashMap([__CLASS__, 'detectType']);
|
self::$types = new HashMap([__CLASS__, 'detectType']);
|
||||||
}
|
}
|
||||||
return self::$types;
|
return self::$types;
|
||||||
@@ -232,7 +232,7 @@ class Helpers
|
|||||||
* Import SQL dump from file.
|
* Import SQL dump from file.
|
||||||
* @return int count of sql commands
|
* @return int count of sql commands
|
||||||
*/
|
*/
|
||||||
public static function loadFromFile(Connection $connection, $file, callable $onProgress = NULL): int
|
public static function loadFromFile(Connection $connection, $file, callable $onProgress = null): int
|
||||||
{
|
{
|
||||||
@set_time_limit(0); // intentionally @
|
@set_time_limit(0); // intentionally @
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ class Helpers
|
|||||||
$delimiter = ';';
|
$delimiter = ';';
|
||||||
$sql = '';
|
$sql = '';
|
||||||
$driver = $connection->getDriver();
|
$driver = $connection->getDriver();
|
||||||
while (($s = fgets($handle)) !== FALSE) {
|
while (($s = fgets($handle)) !== false) {
|
||||||
$size += strlen($s);
|
$size += strlen($s);
|
||||||
if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
|
if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
|
||||||
$delimiter = trim(substr($s, 10));
|
$delimiter = trim(substr($s, 10));
|
||||||
@@ -257,7 +257,7 @@ class Helpers
|
|||||||
$sql = '';
|
$sql = '';
|
||||||
$count++;
|
$count++;
|
||||||
if ($onProgress) {
|
if ($onProgress) {
|
||||||
$onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL);
|
$onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -269,7 +269,7 @@ class Helpers
|
|||||||
$driver->query($sql);
|
$driver->query($sql);
|
||||||
$count++;
|
$count++;
|
||||||
if ($onProgress) {
|
if ($onProgress) {
|
||||||
$onProgress($count, isset($stat['size']) ? 100 : NULL);
|
$onProgress($count, isset($stat['size']) ? 100 : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
@@ -282,6 +282,6 @@ class Helpers
|
|||||||
*/
|
*/
|
||||||
public static function false2Null($val)
|
public static function false2Null($val)
|
||||||
{
|
{
|
||||||
return $val === FALSE ? NULL : $val;
|
return $val === false ? null : $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ class FileLogger
|
|||||||
public $filter;
|
public $filter;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $file, int $filter = NULL)
|
public function __construct(string $file, int $filter = null)
|
||||||
{
|
{
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$this->filter = $filter ?: Dibi\Event::QUERY;
|
$this->filter = $filter ?: Dibi\Event::QUERY;
|
||||||
|
@@ -47,7 +47,7 @@ class FirePhpLogger
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __construct(int $filter = NULL)
|
public function __construct(int $filter = null)
|
||||||
{
|
{
|
||||||
$this->filter = $filter ?: Dibi\Event::QUERY;
|
$this->filter = $filter ?: Dibi\Event::QUERY;
|
||||||
}
|
}
|
||||||
|
@@ -21,24 +21,24 @@ use Dibi\Type;
|
|||||||
* @property-read Table $table
|
* @property-read Table $table
|
||||||
* @property-read string $type
|
* @property-read string $type
|
||||||
* @property-read mixed $nativeType
|
* @property-read mixed $nativeType
|
||||||
* @property-read int|NULL $size
|
* @property-read int|null $size
|
||||||
* @property-read bool|NULL $unsigned
|
* @property-read bool|null $unsigned
|
||||||
* @property-read bool|NULL $nullable
|
* @property-read bool|null $nullable
|
||||||
* @property-read bool|NULL $autoIncrement
|
* @property-read bool|null $autoIncrement
|
||||||
* @property-read mixed $default
|
* @property-read mixed $default
|
||||||
*/
|
*/
|
||||||
class Column
|
class Column
|
||||||
{
|
{
|
||||||
use Dibi\Strict;
|
use Dibi\Strict;
|
||||||
|
|
||||||
/** @var Dibi\Reflector|NULL when created by Result */
|
/** @var Dibi\Reflector|null when created by Result */
|
||||||
private $reflector;
|
private $reflector;
|
||||||
|
|
||||||
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
|
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
|
||||||
private $info;
|
private $info;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Reflector $reflector = NULL, array $info)
|
public function __construct(Dibi\Reflector $reflector = null, array $info)
|
||||||
{
|
{
|
||||||
$this->reflector = $reflector;
|
$this->reflector = $reflector;
|
||||||
$this->info = $info;
|
$this->info = $info;
|
||||||
@@ -53,7 +53,7 @@ class Column
|
|||||||
|
|
||||||
public function getFullName(): string
|
public function getFullName(): string
|
||||||
{
|
{
|
||||||
return $this->info['fullname'] ?? NULL;
|
return $this->info['fullname'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ class Column
|
|||||||
|
|
||||||
public function getTableName(): ?string
|
public function getTableName(): ?string
|
||||||
{
|
{
|
||||||
return isset($this->info['table']) && $this->info['table'] != NULL ? $this->info['table'] : NULL; // intentionally ==
|
return isset($this->info['table']) && $this->info['table'] != null ? $this->info['table'] : null; // intentionally ==
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -92,25 +92,25 @@ class Column
|
|||||||
|
|
||||||
public function getSize(): ?int
|
public function getSize(): ?int
|
||||||
{
|
{
|
||||||
return isset($this->info['size']) ? (int) $this->info['size'] : NULL;
|
return isset($this->info['size']) ? (int) $this->info['size'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isUnsigned(): ?bool
|
public function isUnsigned(): ?bool
|
||||||
{
|
{
|
||||||
return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : NULL;
|
return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isNullable(): ?bool
|
public function isNullable(): ?bool
|
||||||
{
|
{
|
||||||
return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : NULL;
|
return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isAutoIncrement(): ?bool
|
public function isAutoIncrement(): ?bool
|
||||||
{
|
{
|
||||||
return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : NULL;
|
return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ class Column
|
|||||||
*/
|
*/
|
||||||
public function getDefault()
|
public function getDefault()
|
||||||
{
|
{
|
||||||
return $this->info['default'] ?? NULL;
|
return $this->info['default'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +128,6 @@ class Column
|
|||||||
*/
|
*/
|
||||||
public function getVendorInfo(string $key)
|
public function getVendorInfo(string $key)
|
||||||
{
|
{
|
||||||
return $this->info['vendor'][$key] ?? NULL;
|
return $this->info['vendor'][$key] ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -92,7 +92,7 @@ class Database
|
|||||||
|
|
||||||
protected function init(): void
|
protected function init(): void
|
||||||
{
|
{
|
||||||
if ($this->tables === NULL) {
|
if ($this->tables === null) {
|
||||||
$this->tables = [];
|
$this->tables = [];
|
||||||
foreach ($this->reflector->getTables() as $info) {
|
foreach ($this->reflector->getTables() as $info) {
|
||||||
$this->tables[strtolower($info['name'])] = new Table($this->reflector, $info);
|
$this->tables[strtolower($info['name'])] = new Table($this->reflector, $info);
|
||||||
|
@@ -51,7 +51,7 @@ class Result
|
|||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getColumnNames(bool $fullNames = FALSE): array
|
public function getColumnNames(bool $fullNames = false): array
|
||||||
{
|
{
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$res = [];
|
$res = [];
|
||||||
@@ -84,9 +84,9 @@ class Result
|
|||||||
|
|
||||||
protected function initColumns(): void
|
protected function initColumns(): void
|
||||||
{
|
{
|
||||||
if ($this->columns === NULL) {
|
if ($this->columns === null) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
$reflector = $this->driver instanceof Dibi\Reflector ? $this->driver : NULL;
|
$reflector = $this->driver instanceof Dibi\Reflector ? $this->driver : null;
|
||||||
foreach ($this->driver->getResultColumns() as $info) {
|
foreach ($this->driver->getResultColumns() as $info) {
|
||||||
$this->columns[] = $this->names[strtolower($info['name'])] = new Column($reflector, $info);
|
$this->columns[] = $this->names[strtolower($info['name'])] = new Column($reflector, $info);
|
||||||
}
|
}
|
||||||
|
@@ -142,7 +142,7 @@ class Table
|
|||||||
|
|
||||||
protected function initColumns(): void
|
protected function initColumns(): void
|
||||||
{
|
{
|
||||||
if ($this->columns === NULL) {
|
if ($this->columns === null) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
foreach ($this->reflector->getColumns($this->name) as $info) {
|
foreach ($this->reflector->getColumns($this->name) as $info) {
|
||||||
$this->columns[strtolower($info['name'])] = new Column($this->reflector, $info);
|
$this->columns[strtolower($info['name'])] = new Column($this->reflector, $info);
|
||||||
@@ -153,7 +153,7 @@ class Table
|
|||||||
|
|
||||||
protected function initIndexes(): void
|
protected function initIndexes(): void
|
||||||
{
|
{
|
||||||
if ($this->indexes === NULL) {
|
if ($this->indexes === null) {
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$this->indexes = [];
|
$this->indexes = [];
|
||||||
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
||||||
|
@@ -42,7 +42,7 @@ class Result implements IDataSource
|
|||||||
private $meta;
|
private $meta;
|
||||||
|
|
||||||
/** @var bool Already fetched? Used for allowance for first seek(0) */
|
/** @var bool Already fetched? Used for allowance for first seek(0) */
|
||||||
private $fetched = FALSE;
|
private $fetched = false;
|
||||||
|
|
||||||
/** @var string returned object class */
|
/** @var string returned object class */
|
||||||
private $rowClass = Row::class;
|
private $rowClass = Row::class;
|
||||||
@@ -66,9 +66,9 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function free(): void
|
final public function free(): void
|
||||||
{
|
{
|
||||||
if ($this->driver !== NULL) {
|
if ($this->driver !== null) {
|
||||||
$this->driver->free();
|
$this->driver->free();
|
||||||
$this->driver = $this->meta = NULL;
|
$this->driver = $this->meta = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function getResultDriver(): ResultDriver
|
final public function getResultDriver(): ResultDriver
|
||||||
{
|
{
|
||||||
if ($this->driver === NULL) {
|
if ($this->driver === null) {
|
||||||
throw new \RuntimeException('Result-set was released from memory.');
|
throw new \RuntimeException('Result-set was released from memory.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function seek(int $row): bool
|
final public function seek(int $row): bool
|
||||||
{
|
{
|
||||||
return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : TRUE;
|
return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,11 +165,11 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function fetch(): ?Row
|
final public function fetch(): ?Row
|
||||||
{
|
{
|
||||||
$row = $this->getResultDriver()->fetch(TRUE);
|
$row = $this->getResultDriver()->fetch(true);
|
||||||
if ($row === NULL) {
|
if ($row === null) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$this->fetched = TRUE;
|
$this->fetched = true;
|
||||||
$this->normalize($row);
|
$this->normalize($row);
|
||||||
if ($this->rowFactory) {
|
if ($this->rowFactory) {
|
||||||
return ($this->rowFactory)($row);
|
return ($this->rowFactory)($row);
|
||||||
@@ -182,15 +182,15 @@ class Result implements IDataSource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Like fetch(), but returns only first field.
|
* Like fetch(), but returns only first field.
|
||||||
* @return mixed value on success, NULL if no next record
|
* @return mixed value on success, null if no next record
|
||||||
*/
|
*/
|
||||||
final public function fetchSingle()
|
final public function fetchSingle()
|
||||||
{
|
{
|
||||||
$row = $this->getResultDriver()->fetch(TRUE);
|
$row = $this->getResultDriver()->fetch(true);
|
||||||
if ($row === NULL) {
|
if ($row === null) {
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$this->fetched = TRUE;
|
$this->fetched = true;
|
||||||
$this->normalize($row);
|
$this->normalize($row);
|
||||||
return reset($row);
|
return reset($row);
|
||||||
}
|
}
|
||||||
@@ -200,9 +200,9 @@ class Result implements IDataSource
|
|||||||
* Fetches all records from table.
|
* Fetches all records from table.
|
||||||
* @return Row[]
|
* @return Row[]
|
||||||
*/
|
*/
|
||||||
final public function fetchAll(int $offset = NULL, int $limit = NULL): array
|
final public function fetchAll(int $offset = null, int $limit = null): array
|
||||||
{
|
{
|
||||||
$limit = $limit === NULL ? -1 : $limit;
|
$limit = $limit === null ? -1 : $limit;
|
||||||
$this->seek($offset ?: 0);
|
$this->seek($offset ?: 0);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
@@ -233,7 +233,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function fetchAssoc(string $assoc): array
|
final public function fetchAssoc(string $assoc): array
|
||||||
{
|
{
|
||||||
if (strpos($assoc, ',') !== FALSE) {
|
if (strpos($assoc, ',') !== false) {
|
||||||
return $this->oldFetchAssoc($assoc);
|
return $this->oldFetchAssoc($assoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,12 +243,12 @@ class Result implements IDataSource
|
|||||||
return []; // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = NULL;
|
$data = null;
|
||||||
$assoc = preg_split('#(\[\]|->|=|\|)#', $assoc, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
$assoc = preg_split('#(\[\]|->|=|\|)#', $assoc, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
// check columns
|
// check columns
|
||||||
foreach ($assoc as $as) {
|
foreach ($assoc as $as) {
|
||||||
// offsetExists ignores NULL in PHP 5.2.1, isset() surprisingly NULL accepts
|
// offsetExists ignores null in PHP 5.2.1, isset() surprisingly null accepts
|
||||||
if ($as !== '[]' && $as !== '=' && $as !== '->' && $as !== '|' && !property_exists($row, $as)) {
|
if ($as !== '[]' && $as !== '=' && $as !== '->' && $as !== '|' && !property_exists($row, $as)) {
|
||||||
throw new \InvalidArgumentException("Unknown column '$as' in associative descriptor.");
|
throw new \InvalidArgumentException("Unknown column '$as' in associative descriptor.");
|
||||||
}
|
}
|
||||||
@@ -276,10 +276,10 @@ class Result implements IDataSource
|
|||||||
continue 2;
|
continue 2;
|
||||||
|
|
||||||
} elseif ($as === '->') { // "object" node
|
} elseif ($as === '->') { // "object" node
|
||||||
if ($x === NULL) {
|
if ($x === null) {
|
||||||
$x = clone $row;
|
$x = clone $row;
|
||||||
$x = &$x->{$assoc[$i + 1]};
|
$x = &$x->{$assoc[$i + 1]};
|
||||||
$x = NULL; // prepare child node
|
$x = null; // prepare child node
|
||||||
} else {
|
} else {
|
||||||
$x = &$x->{$assoc[$i + 1]};
|
$x = &$x->{$assoc[$i + 1]};
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ class Result implements IDataSource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($x === NULL) { // build leaf
|
if ($x === null) { // build leaf
|
||||||
$x = $row;
|
$x = $row;
|
||||||
}
|
}
|
||||||
} while ($row = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
@@ -310,7 +310,7 @@ class Result implements IDataSource
|
|||||||
return []; // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = NULL;
|
$data = null;
|
||||||
$assoc = explode(',', $assoc);
|
$assoc = explode(',', $assoc);
|
||||||
|
|
||||||
// strip leading = and @
|
// strip leading = and @
|
||||||
@@ -335,19 +335,19 @@ class Result implements IDataSource
|
|||||||
$x = &$x[];
|
$x = &$x[];
|
||||||
|
|
||||||
} elseif ($as === '=') { // "record" node
|
} elseif ($as === '=') { // "record" node
|
||||||
if ($x === NULL) {
|
if ($x === null) {
|
||||||
$x = $row->toArray();
|
$x = $row->toArray();
|
||||||
$x = &$x[ $assoc[$i + 1] ];
|
$x = &$x[ $assoc[$i + 1] ];
|
||||||
$x = NULL; // prepare child node
|
$x = null; // prepare child node
|
||||||
} else {
|
} else {
|
||||||
$x = &$x[ $assoc[$i + 1] ];
|
$x = &$x[ $assoc[$i + 1] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($as === '@') { // "object" node
|
} elseif ($as === '@') { // "object" node
|
||||||
if ($x === NULL) {
|
if ($x === null) {
|
||||||
$x = clone $row;
|
$x = clone $row;
|
||||||
$x = &$x->{$assoc[$i + 1]};
|
$x = &$x->{$assoc[$i + 1]};
|
||||||
$x = NULL; // prepare child node
|
$x = null; // prepare child node
|
||||||
} else {
|
} else {
|
||||||
$x = &$x->{$assoc[$i + 1]};
|
$x = &$x->{$assoc[$i + 1]};
|
||||||
}
|
}
|
||||||
@@ -357,7 +357,7 @@ class Result implements IDataSource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($x === NULL) { // build leaf
|
if ($x === null) { // build leaf
|
||||||
if ($leaf === '=') {
|
if ($leaf === '=') {
|
||||||
$x = $row->toArray();
|
$x = $row->toArray();
|
||||||
} else {
|
} else {
|
||||||
@@ -375,7 +375,7 @@ class Result implements IDataSource
|
|||||||
* Fetches all records from table like $key => $value pairs.
|
* Fetches all records from table like $key => $value pairs.
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
final public function fetchPairs(string $key = NULL, string $value = NULL): array
|
final public function fetchPairs(string $key = null, string $value = null): array
|
||||||
{
|
{
|
||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
@@ -385,8 +385,8 @@ class Result implements IDataSource
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
if ($value === NULL) {
|
if ($value === null) {
|
||||||
if ($key !== NULL) {
|
if ($key !== null) {
|
||||||
throw new \InvalidArgumentException('Either none or both columns must be specified.');
|
throw new \InvalidArgumentException('Either none or both columns must be specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ class Result implements IDataSource
|
|||||||
throw new \InvalidArgumentException("Unknown value column '$value'.");
|
throw new \InvalidArgumentException("Unknown value column '$value'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($key === NULL) { // indexed-array
|
if ($key === null) { // indexed-array
|
||||||
do {
|
do {
|
||||||
$data[] = $row[$value];
|
$data[] = $row[$value];
|
||||||
} while ($row = $this->fetch());
|
} while ($row = $this->fetch());
|
||||||
@@ -451,7 +451,7 @@ class Result implements IDataSource
|
|||||||
private function normalize(array &$row): void
|
private function normalize(array &$row): void
|
||||||
{
|
{
|
||||||
foreach ($this->types as $key => $type) {
|
foreach ($this->types as $key => $type) {
|
||||||
if (!isset($row[$key])) { // NULL
|
if (!isset($row[$key])) { // null
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value = $row[$key];
|
$value = $row[$key];
|
||||||
@@ -466,7 +466,7 @@ class Result implements IDataSource
|
|||||||
} elseif ($type === Type::FLOAT) {
|
} elseif ($type === Type::FLOAT) {
|
||||||
$value = ltrim((string) $value, '0');
|
$value = ltrim((string) $value, '0');
|
||||||
$p = strpos($value, '.');
|
$p = strpos($value, '.');
|
||||||
if ($p !== FALSE) {
|
if ($p !== false) {
|
||||||
$value = rtrim(rtrim($value, '0'), '.');
|
$value = rtrim(rtrim($value, '0'), '.');
|
||||||
}
|
}
|
||||||
if ($value === '' || $value[0] === '.') {
|
if ($value === '' || $value[0] === '.') {
|
||||||
@@ -480,11 +480,11 @@ class Result implements IDataSource
|
|||||||
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||||
|
|
||||||
} elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
|
} elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
|
||||||
if ($value && substr((string) $value, 0, 3) !== '000') { // '', NULL, FALSE, '0000-00-00', ...
|
if ($value && substr((string) $value, 0, 3) !== '000') { // '', null, false, '0000-00-00', ...
|
||||||
$value = new DateTime($value);
|
$value = new DateTime($value);
|
||||||
$row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]);
|
$row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]);
|
||||||
} else {
|
} else {
|
||||||
$row[$key] = NULL;
|
$row[$key] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($type === Type::TIME_INTERVAL) {
|
} elseif ($type === Type::TIME_INTERVAL) {
|
||||||
@@ -515,7 +515,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function getType($column): string
|
final public function getType($column): string
|
||||||
{
|
{
|
||||||
return $this->types[$column] ?? NULL;
|
return $this->types[$column] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -534,7 +534,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function getFormat($type): ?string
|
final public function getFormat($type): ?string
|
||||||
{
|
{
|
||||||
return $this->formats[$type] ?? NULL;
|
return $this->formats[$type] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -546,7 +546,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function getInfo(): Reflection\Result
|
public function getInfo(): Reflection\Result
|
||||||
{
|
{
|
||||||
if ($this->meta === NULL) {
|
if ($this->meta === null) {
|
||||||
$this->meta = new Reflection\Result($this->getResultDriver());
|
$this->meta = new Reflection\Result($this->getResultDriver());
|
||||||
}
|
}
|
||||||
return $this->meta;
|
return $this->meta;
|
||||||
|
@@ -32,16 +32,16 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
|
|||||||
/**
|
/**
|
||||||
* Converts value to DateTime object.
|
* Converts value to DateTime object.
|
||||||
*/
|
*/
|
||||||
public function asDateTime(string $key, string $format = NULL): \DateTime
|
public function asDateTime(string $key, string $format = null): \DateTime
|
||||||
{
|
{
|
||||||
$time = $this[$key];
|
$time = $this[$key];
|
||||||
if (!$time instanceof DateTime) {
|
if (!$time instanceof DateTime) {
|
||||||
if (!$time || substr((string) $time, 0, 3) === '000') { // '', NULL, FALSE, '0000-00-00', ...
|
if (!$time || substr((string) $time, 0, 3) === '000') { // '', null, false, '0000-00-00', ...
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
$time = new DateTime($time);
|
$time = new DateTime($time);
|
||||||
}
|
}
|
||||||
return $format === NULL ? $time : $time->format($format);
|
return $format === null ? $time : $time->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -87,7 +87,7 @@ trait Strict
|
|||||||
|
|
||||||
public function __isset($name): bool
|
public function __isset($name): bool
|
||||||
{
|
{
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -105,9 +105,9 @@ trait Strict
|
|||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function extensionMethod(string $name, callable $callback = NULL)
|
public static function extensionMethod(string $name, callable $callback = null)
|
||||||
{
|
{
|
||||||
if (strpos($name, '::') === FALSE) {
|
if (strpos($name, '::') === false) {
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
} else {
|
} else {
|
||||||
[$class, $name] = explode('::', $name);
|
[$class, $name] = explode('::', $name);
|
||||||
@@ -115,7 +115,7 @@ trait Strict
|
|||||||
}
|
}
|
||||||
|
|
||||||
$list = & self::$extMethods[strtolower($name)];
|
$list = & self::$extMethods[strtolower($name)];
|
||||||
if ($callback === NULL) { // getter
|
if ($callback === null) { // getter
|
||||||
$cache = &$list[''][$class];
|
$cache = &$list[''][$class];
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
return $cache;
|
return $cache;
|
||||||
@@ -126,11 +126,11 @@ trait Strict
|
|||||||
return $cache = $list[$cl];
|
return $cache = $list[$cl];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $cache = FALSE;
|
return $cache = false;
|
||||||
|
|
||||||
} else { // setter
|
} else { // setter
|
||||||
$list[$class] = $callback;
|
$list[$class] = $callback;
|
||||||
$list[''] = NULL;
|
$list[''] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ final class Translator
|
|||||||
private $errors;
|
private $errors;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $comment = FALSE;
|
private $comment = false;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $ifLevel = 0;
|
private $ifLevel = 0;
|
||||||
@@ -71,8 +71,8 @@ final class Translator
|
|||||||
}
|
}
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
|
|
||||||
$commandIns = NULL;
|
$commandIns = null;
|
||||||
$lastArr = NULL;
|
$lastArr = null;
|
||||||
$cursor = &$this->cursor;
|
$cursor = &$this->cursor;
|
||||||
$comment = &$this->comment;
|
$comment = &$this->comment;
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ final class Translator
|
|||||||
|
|
||||||
if (is_array($arg) && is_string(key($arg))) {
|
if (is_array($arg) && is_string(key($arg))) {
|
||||||
// associative array -> autoselect between SET or VALUES & LIST
|
// associative array -> autoselect between SET or VALUES & LIST
|
||||||
if ($commandIns === NULL) {
|
if ($commandIns === null) {
|
||||||
$commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6));
|
$commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6));
|
||||||
$commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC';
|
$commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC';
|
||||||
$sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a');
|
$sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a');
|
||||||
@@ -142,7 +142,7 @@ final class Translator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default processing
|
// default processing
|
||||||
$sql[] = $this->formatValue($arg, NULL);
|
$sql[] = $this->formatValue($arg, null);
|
||||||
} // while
|
} // while
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ final class Translator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply limit
|
// apply limit
|
||||||
if ($this->limit !== NULL || $this->offset !== NULL) {
|
if ($this->limit !== null || $this->offset !== null) {
|
||||||
$this->driver->applyLimit($sql, $this->limit, $this->offset);
|
$this->driver->applyLimit($sql, $this->limit, $this->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ final class Translator
|
|||||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||||
$k = $this->identifiers->{$pair[0]} . ' ';
|
$k = $this->identifiers->{$pair[0]} . ' ';
|
||||||
if (!isset($pair[1])) {
|
if (!isset($pair[1])) {
|
||||||
$v = $this->formatValue($v, NULL);
|
$v = $this->formatValue($v, null);
|
||||||
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
|
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
|
||||||
|
|
||||||
} elseif ($pair[1] === 'ex') {
|
} elseif ($pair[1] === 'ex') {
|
||||||
@@ -204,7 +204,7 @@ final class Translator
|
|||||||
$v = $this->formatValue($v, $pair[1]);
|
$v = $this->formatValue($v, $pair[1]);
|
||||||
if ($pair[1] === 'l' || $pair[1] === 'in') {
|
if ($pair[1] === 'l' || $pair[1] === 'in') {
|
||||||
$op = 'IN ';
|
$op = 'IN ';
|
||||||
} elseif (strpos($pair[1], 'like') !== FALSE) {
|
} elseif (strpos($pair[1], 'like') !== false) {
|
||||||
$op = 'LIKE ';
|
$op = 'LIKE ';
|
||||||
} elseif ($v === 'NULL') {
|
} elseif ($v === 'NULL') {
|
||||||
$op = 'IS ';
|
$op = 'IS ';
|
||||||
@@ -236,7 +236,7 @@ final class Translator
|
|||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||||
$vx[] = $this->identifiers->{$pair[0]} . '='
|
$vx[] = $this->identifiers->{$pair[0]} . '='
|
||||||
. $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL));
|
. $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null));
|
||||||
}
|
}
|
||||||
return implode(', ', $vx);
|
return implode(', ', $vx);
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ final class Translator
|
|||||||
case 'l': // (val, val, ...)
|
case 'l': // (val, val, ...)
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$pair = explode('%', (string) $k, 2); // split into identifier & modifier
|
$pair = explode('%', (string) $k, 2); // split into identifier & modifier
|
||||||
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL));
|
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null));
|
||||||
}
|
}
|
||||||
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ final class Translator
|
|||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||||
$kx[] = $this->identifiers->{$pair[0]};
|
$kx[] = $this->identifiers->{$pair[0]};
|
||||||
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL));
|
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null));
|
||||||
}
|
}
|
||||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ final class Translator
|
|||||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||||
$kx[] = $this->identifiers->{$pair[0]};
|
$kx[] = $this->identifiers->{$pair[0]};
|
||||||
foreach ($v as $k2 => $v2) {
|
foreach ($v as $k2 => $v2) {
|
||||||
$vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : NULL));
|
$vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($vx as $k => $v) {
|
foreach ($vx as $k => $v) {
|
||||||
@@ -311,7 +311,7 @@ final class Translator
|
|||||||
|
|
||||||
// with modifier procession
|
// with modifier procession
|
||||||
if ($modifier) {
|
if ($modifier) {
|
||||||
if ($value !== NULL && !is_scalar($value)) { // array is already processed
|
if ($value !== null && !is_scalar($value)) { // array is already processed
|
||||||
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
|
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
|
||||||
$modifier = 'SQL';
|
$modifier = 'SQL';
|
||||||
} elseif ($value instanceof \DateTimeInterface && ($modifier === 'd' || $modifier === 't')) {
|
} elseif ($value instanceof \DateTimeInterface && ($modifier === 'd' || $modifier === 't')) {
|
||||||
@@ -324,27 +324,27 @@ final class Translator
|
|||||||
|
|
||||||
switch ($modifier) {
|
switch ($modifier) {
|
||||||
case 's': // string
|
case 's': // string
|
||||||
return $value === NULL ? 'NULL' : $this->driver->escapeText((string) $value);
|
return $value === null ? 'NULL' : $this->driver->escapeText((string) $value);
|
||||||
|
|
||||||
case 'bin':// binary
|
case 'bin':// binary
|
||||||
return $value === NULL ? 'NULL' : $this->driver->escapeBinary($value);
|
return $value === null ? 'NULL' : $this->driver->escapeBinary($value);
|
||||||
|
|
||||||
case 'b': // boolean
|
case 'b': // boolean
|
||||||
return $value === NULL ? 'NULL' : $this->driver->escapeBool($value);
|
return $value === null ? 'NULL' : $this->driver->escapeBool($value);
|
||||||
|
|
||||||
case 'sN': // string or NULL
|
case 'sN': // string or null
|
||||||
case 'sn':
|
case 'sn':
|
||||||
return $value == '' ? 'NULL' : $this->driver->escapeText((string) $value); // notice two equal signs
|
return $value == '' ? 'NULL' : $this->driver->escapeText((string) $value); // notice two equal signs
|
||||||
|
|
||||||
case 'iN': // signed int or NULL
|
case 'iN': // signed int or null
|
||||||
if ($value == '') {
|
if ($value == '') {
|
||||||
$value = NULL;
|
$value = null;
|
||||||
}
|
}
|
||||||
// intentionally break omitted
|
// intentionally break omitted
|
||||||
|
|
||||||
case 'i': // signed int
|
case 'i': // signed int
|
||||||
case 'u': // unsigned int, ignored
|
case 'u': // unsigned int, ignored
|
||||||
if ($value === NULL) {
|
if ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} elseif (is_string($value) && preg_match('#[+-]?\d++(?:e\d+)?\z#A', $value)) {
|
} elseif (is_string($value) && preg_match('#[+-]?\d++(?:e\d+)?\z#A', $value)) {
|
||||||
return $value; // support for long numbers - keep them unchanged
|
return $value; // support for long numbers - keep them unchanged
|
||||||
@@ -353,7 +353,7 @@ final class Translator
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'f': // float
|
case 'f': // float
|
||||||
if ($value === NULL) {
|
if ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} elseif (is_string($value) && is_numeric($value) && substr($value, 1, 1) !== 'x') {
|
} elseif (is_string($value) && is_numeric($value) && substr($value, 1, 1) !== 'x') {
|
||||||
return $value; // support for extreme numbers - keep them unchanged
|
return $value; // support for extreme numbers - keep them unchanged
|
||||||
@@ -364,7 +364,7 @@ final class Translator
|
|||||||
case 'd': // date
|
case 'd': // date
|
||||||
case 't': // datetime
|
case 't': // datetime
|
||||||
case 'dt': // datetime
|
case 'dt': // datetime
|
||||||
if ($value === NULL) {
|
if ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} else {
|
} else {
|
||||||
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
||||||
@@ -434,7 +434,7 @@ final class Translator
|
|||||||
} elseif (is_bool($value)) {
|
} elseif (is_bool($value)) {
|
||||||
return $this->driver->escapeBool($value);
|
return $this->driver->escapeBool($value);
|
||||||
|
|
||||||
} elseif ($value === NULL) {
|
} elseif ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
|
|
||||||
} elseif ($value instanceof \DateTimeInterface) {
|
} elseif ($value instanceof \DateTimeInterface) {
|
||||||
@@ -476,7 +476,7 @@ final class Translator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cursor++;
|
$cursor++;
|
||||||
return $this->formatValue($this->args[$cursor - 1], NULL);
|
return $this->formatValue($this->args[$cursor - 1], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($matches[10])) { // modifier
|
if (!empty($matches[10])) { // modifier
|
||||||
@@ -493,7 +493,7 @@ final class Translator
|
|||||||
if (!$this->comment && !$this->args[$cursor - 1]) {
|
if (!$this->comment && !$this->args[$cursor - 1]) {
|
||||||
// open comment
|
// open comment
|
||||||
$this->ifLevelStart = $this->ifLevel;
|
$this->ifLevelStart = $this->ifLevel;
|
||||||
$this->comment = TRUE;
|
$this->comment = true;
|
||||||
return '/*';
|
return '/*';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -501,11 +501,11 @@ final class Translator
|
|||||||
} elseif ($mod === 'else') {
|
} elseif ($mod === 'else') {
|
||||||
if ($this->ifLevelStart === $this->ifLevel) {
|
if ($this->ifLevelStart === $this->ifLevel) {
|
||||||
$this->ifLevelStart = 0;
|
$this->ifLevelStart = 0;
|
||||||
$this->comment = FALSE;
|
$this->comment = false;
|
||||||
return '*/';
|
return '*/';
|
||||||
} elseif (!$this->comment) {
|
} elseif (!$this->comment) {
|
||||||
$this->ifLevelStart = $this->ifLevel;
|
$this->ifLevelStart = $this->ifLevel;
|
||||||
$this->comment = TRUE;
|
$this->comment = true;
|
||||||
return '/*';
|
return '/*';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,7 +514,7 @@ final class Translator
|
|||||||
if ($this->ifLevelStart === $this->ifLevel + 1) {
|
if ($this->ifLevelStart === $this->ifLevel + 1) {
|
||||||
// close comment
|
// close comment
|
||||||
$this->ifLevelStart = 0;
|
$this->ifLevelStart = 0;
|
||||||
$this->comment = FALSE;
|
$this->comment = false;
|
||||||
return '*/';
|
return '*/';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@@ -525,7 +525,7 @@ final class Translator
|
|||||||
|
|
||||||
} elseif ($mod === 'lmt') { // apply limit
|
} elseif ($mod === 'lmt') { // apply limit
|
||||||
$arg = $this->args[$cursor++];
|
$arg = $this->args[$cursor++];
|
||||||
if ($arg === NULL) {
|
if ($arg === null) {
|
||||||
} elseif ($this->comment) {
|
} elseif ($this->comment) {
|
||||||
return "(limit $arg)";
|
return "(limit $arg)";
|
||||||
} else {
|
} else {
|
||||||
@@ -535,7 +535,7 @@ final class Translator
|
|||||||
|
|
||||||
} elseif ($mod === 'ofs') { // apply offset
|
} elseif ($mod === 'ofs') { // apply offset
|
||||||
$arg = $this->args[$cursor++];
|
$arg = $this->args[$cursor++];
|
||||||
if ($arg === NULL) {
|
if ($arg === null) {
|
||||||
} elseif ($this->comment) {
|
} elseif ($this->comment) {
|
||||||
return "(offset $arg)";
|
return "(offset $arg)";
|
||||||
} else {
|
} else {
|
||||||
@@ -572,7 +572,7 @@ final class Translator
|
|||||||
if ($matches[8]) { // SQL identifier substitution
|
if ($matches[8]) { // SQL identifier substitution
|
||||||
$m = substr($matches[8], 0, -1);
|
$m = substr($matches[8], 0, -1);
|
||||||
$m = $this->connection->getSubstitutes()->$m;
|
$m = $this->connection->getSubstitutes()->$m;
|
||||||
return $matches[9] == '' ? $this->formatValue($m, NULL) : $m . $matches[9]; // value or identifier
|
return $matches[9] == '' ? $this->formatValue($m, null) : $m . $matches[9]; // value or identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('this should be never executed');
|
throw new \Exception('this should be never executed');
|
||||||
|
@@ -83,11 +83,11 @@ class dibi
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns TRUE when connection was established.
|
* Returns true when connection was established.
|
||||||
*/
|
*/
|
||||||
public static function isConnected(): bool
|
public static function isConnected(): bool
|
||||||
{
|
{
|
||||||
return (self::$connection !== NULL) && self::$connection->isConnected();
|
return (self::$connection !== null) && self::$connection->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,10 +95,10 @@ class dibi
|
|||||||
* Retrieve active connection.
|
* Retrieve active connection.
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function getConnection(string $name = NULL): Dibi\Connection
|
public static function getConnection(string $name = null): Dibi\Connection
|
||||||
{
|
{
|
||||||
if ($name === NULL) {
|
if ($name === null) {
|
||||||
if (self::$connection === NULL) {
|
if (self::$connection === null) {
|
||||||
throw new Dibi\Exception('Dibi is not connected to database.');
|
throw new Dibi\Exception('Dibi is not connected to database.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ class dibi
|
|||||||
* Monostate for Dibi\Connection::getInsertId()
|
* Monostate for Dibi\Connection::getInsertId()
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function getInsertId(string $sequence = NULL): int
|
public static function getInsertId(string $sequence = null): int
|
||||||
{
|
{
|
||||||
return self::getConnection()->getInsertId($sequence);
|
return self::getConnection()->getInsertId($sequence);
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ class dibi
|
|||||||
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function insertId(string $sequence = NULL): int
|
public static function insertId(string $sequence = null): int
|
||||||
{
|
{
|
||||||
return self::getConnection()->getInsertId($sequence);
|
return self::getConnection()->getInsertId($sequence);
|
||||||
}
|
}
|
||||||
@@ -260,17 +260,17 @@ class dibi
|
|||||||
* Begins a transaction - Monostate for Dibi\Connection::begin().
|
* Begins a transaction - Monostate for Dibi\Connection::begin().
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function begin(string $savepoint = NULL): void
|
public static function begin(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
self::getConnection()->begin($savepoint);
|
self::getConnection()->begin($savepoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits statements in a transaction - Monostate for Dibi\Connection::commit($savepoint = NULL).
|
* Commits statements in a transaction - Monostate for Dibi\Connection::commit($savepoint = null).
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function commit(string $savepoint = NULL): void
|
public static function commit(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
self::getConnection()->commit($savepoint);
|
self::getConnection()->commit($savepoint);
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ class dibi
|
|||||||
* Rollback changes in a transaction - Monostate for Dibi\Connection::rollback().
|
* Rollback changes in a transaction - Monostate for Dibi\Connection::rollback().
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function rollback(string $savepoint = NULL): void
|
public static function rollback(string $savepoint = null): void
|
||||||
{
|
{
|
||||||
self::getConnection()->rollback($savepoint);
|
self::getConnection()->rollback($savepoint);
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ class dibi
|
|||||||
* @param string|Result
|
* @param string|Result
|
||||||
* @param bool return output instead of printing it?
|
* @param bool return output instead of printing it?
|
||||||
*/
|
*/
|
||||||
public static function dump($sql = NULL, bool $return = FALSE): string
|
public static function dump($sql = null, bool $return = false): string
|
||||||
{
|
{
|
||||||
return Dibi\Helpers::dump($sql, $return);
|
return Dibi\Helpers::dump($sql, $return);
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,14 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class Exception extends \Exception
|
class Exception extends \Exception
|
||||||
{
|
{
|
||||||
/** @var string|NULL */
|
/** @var string|null */
|
||||||
private $sql;
|
private $sql;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a dibi exception.
|
* Construct a dibi exception.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $message = '', $code = 0, string $sql = NULL)
|
public function __construct(string $message = '', $code = 0, string $sql = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message);
|
parent::__construct($message);
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
@@ -93,7 +93,7 @@ class ProcedureException extends Exception
|
|||||||
/**
|
/**
|
||||||
* Construct the exception.
|
* Construct the exception.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $message = NULL, int $code = 0, string $severity = NULL, $sql = NULL)
|
public function __construct(string $message = null, int $code = 0, string $severity = null, $sql = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message, $code, $sql);
|
parent::__construct($message, $code, $sql);
|
||||||
$this->severity = $severity;
|
$this->severity = $severity;
|
||||||
|
@@ -58,19 +58,19 @@ interface Driver
|
|||||||
* Begins a transaction (if supported).
|
* Begins a transaction (if supported).
|
||||||
* @throws DriverException
|
* @throws DriverException
|
||||||
*/
|
*/
|
||||||
function begin(string $savepoint = NULL): void;
|
function begin(string $savepoint = null): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits statements in a transaction.
|
* Commits statements in a transaction.
|
||||||
* @throws DriverException
|
* @throws DriverException
|
||||||
*/
|
*/
|
||||||
function commit(string $savepoint = NULL): void;
|
function commit(string $savepoint = null): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rollback changes in a transaction.
|
* Rollback changes in a transaction.
|
||||||
* @throws DriverException
|
* @throws DriverException
|
||||||
*/
|
*/
|
||||||
function rollback(string $savepoint = NULL): void;
|
function rollback(string $savepoint = null): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
@@ -129,14 +129,14 @@ interface ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves cursor position without fetching row.
|
* Moves cursor position without fetching row.
|
||||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
* @return bool true on success, false if unable to seek to specified record
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function seek(int $row): bool;
|
function seek(int $row): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
* @param bool TRUE for associative array, FALSE for numeric
|
* @param bool true for associative array, false for numeric
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
function fetch(bool $type): ?array;
|
function fetch(bool $type): ?array;
|
||||||
|
@@ -22,7 +22,7 @@ test(function () use ($config) {
|
|||||||
|
|
||||||
|
|
||||||
test(function () use ($config) { // lazy
|
test(function () use ($config) { // lazy
|
||||||
$conn = new Connection($config + ['lazy' => TRUE]);
|
$conn = new Connection($config + ['lazy' => true]);
|
||||||
Assert::false($conn->isConnected());
|
Assert::false($conn->isConnected());
|
||||||
|
|
||||||
$conn->query('SELECT 1');
|
$conn->query('SELECT 1');
|
||||||
|
@@ -31,7 +31,7 @@ Assert::same(
|
|||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
$fluent->setFlag('IGNORE', FALSE);
|
$fluent->setFlag('IGNORE', false);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('DELETE FROM [anotherTable] USING [thirdTable]'),
|
reformat('DELETE FROM [anotherTable] USING [thirdTable]'),
|
||||||
|
@@ -32,7 +32,7 @@ class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
|||||||
|
|
||||||
function fetch(bool $type): ?array
|
function fetch(bool $type): ?array
|
||||||
{
|
{
|
||||||
return NULL;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ $conn = new Dibi\Connection($config);
|
|||||||
$arr = [
|
$arr = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$fluent = $conn->insert('table', $arr)
|
$fluent = $conn->insert('table', $arr)
|
||||||
@@ -23,7 +23,7 @@ Assert::same(
|
|||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
$fluent->setFlag('IGNORE', FALSE);
|
$fluent->setFlag('IGNORE', false);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT DELAYED INTO [table] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL)'),
|
reformat('INSERT DELAYED INTO [table] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL)'),
|
||||||
|
@@ -12,7 +12,7 @@ $conn = new Dibi\Connection($config);
|
|||||||
$arr = [
|
$arr = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$fluent = $conn->update('table', $arr)
|
$fluent = $conn->update('table', $arr)
|
||||||
|
@@ -7,19 +7,19 @@ use Tester\Assert;
|
|||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
|
||||||
Assert::same(NULL, Helpers::getSuggestion([], ''));
|
Assert::same(null, Helpers::getSuggestion([], ''));
|
||||||
Assert::same(NULL, Helpers::getSuggestion([], 'a'));
|
Assert::same(null, Helpers::getSuggestion([], 'a'));
|
||||||
Assert::same(NULL, Helpers::getSuggestion(['a'], 'a'));
|
Assert::same(null, Helpers::getSuggestion(['a'], 'a'));
|
||||||
Assert::same('a', Helpers::getSuggestion(['a', 'b'], ''));
|
Assert::same('a', Helpers::getSuggestion(['a', 'b'], ''));
|
||||||
Assert::same('b', Helpers::getSuggestion(['a', 'b'], 'a')); // ignore 100% match
|
Assert::same('b', Helpers::getSuggestion(['a', 'b'], 'a')); // ignore 100% match
|
||||||
Assert::same('a1', Helpers::getSuggestion(['a1', 'a2'], 'a')); // take first
|
Assert::same('a1', Helpers::getSuggestion(['a1', 'a2'], 'a')); // take first
|
||||||
Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'a'));
|
Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'a'));
|
||||||
Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'ab'));
|
Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'ab'));
|
||||||
Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'abc'));
|
Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'abc'));
|
||||||
Assert::same('bar', Helpers::getSuggestion(['foo', 'bar', 'baz'], 'baz'));
|
Assert::same('bar', Helpers::getSuggestion(['foo', 'bar', 'baz'], 'baz'));
|
||||||
Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'acbd'));
|
Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'acbd'));
|
||||||
Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'axbd'));
|
Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'axbd'));
|
||||||
Assert::same(NULL, Helpers::getSuggestion(['abcd'], 'axyd'));
|
Assert::same(null, Helpers::getSuggestion(['abcd'], 'axyd'));
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -30,7 +30,7 @@ Assert::same(
|
|||||||
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
|
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
|
||||||
Assert::same(
|
Assert::same(
|
||||||
['products.product_id', 'orders.order_id', 'customers.name', 'xXx'],
|
['products.product_id', 'orders.order_id', 'customers.name', 'xXx'],
|
||||||
$info->getColumnNames(TRUE)
|
$info->getColumnNames(true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ class MockResult extends Dibi\Result
|
|||||||
function test($row)
|
function test($row)
|
||||||
{
|
{
|
||||||
$normalize = new ReflectionMethod(Dibi\Result::class, 'normalize');
|
$normalize = new ReflectionMethod(Dibi\Result::class, 'normalize');
|
||||||
$normalize->setAccessible(TRUE);
|
$normalize->setAccessible(true);
|
||||||
$normalize->invokeArgs($this, [&$row]);
|
$normalize->invokeArgs($this, [&$row]);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@@ -28,21 +28,21 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::BOOL);
|
$result->setType('col', Type::BOOL);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => TRUE]));
|
Assert::same(['col' => true], $result->test(['col' => true]));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => FALSE]));
|
Assert::same(['col' => false], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => '']));
|
Assert::same(['col' => false], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => '0']));
|
Assert::same(['col' => false], $result->test(['col' => '0']));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => '1']));
|
Assert::same(['col' => true], $result->test(['col' => '1']));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => 't']));
|
Assert::same(['col' => true], $result->test(['col' => 't']));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => 'f']));
|
Assert::same(['col' => false], $result->test(['col' => 'f']));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => 'T']));
|
Assert::same(['col' => true], $result->test(['col' => 'T']));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => 'F']));
|
Assert::same(['col' => false], $result->test(['col' => 'F']));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => 0]));
|
Assert::same(['col' => false], $result->test(['col' => 0]));
|
||||||
Assert::same(['col' => FALSE], $result->test(['col' => 0.0]));
|
Assert::same(['col' => false], $result->test(['col' => 0.0]));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => 1]));
|
Assert::same(['col' => true], $result->test(['col' => 1]));
|
||||||
Assert::same(['col' => TRUE], $result->test(['col' => 1.0]));
|
Assert::same(['col' => true], $result->test(['col' => 1.0]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -50,9 +50,9 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::TEXT);
|
$result->setType('col', Type::TEXT);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::same(['col' => '1'], $result->test(['col' => TRUE]));
|
Assert::same(['col' => '1'], $result->test(['col' => true]));
|
||||||
Assert::same(['col' => ''], $result->test(['col' => FALSE]));
|
Assert::same(['col' => ''], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => ''], $result->test(['col' => '']));
|
Assert::same(['col' => ''], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => '0'], $result->test(['col' => '0']));
|
Assert::same(['col' => '0'], $result->test(['col' => '0']));
|
||||||
@@ -66,9 +66,9 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::FLOAT);
|
$result->setType('col', Type::FLOAT);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::same(['col' => 1.0], $result->test(['col' => TRUE]));
|
Assert::same(['col' => 1.0], $result->test(['col' => true]));
|
||||||
Assert::same(['col' => 0.0], $result->test(['col' => FALSE]));
|
Assert::same(['col' => 0.0], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => 0.0], $result->test(['col' => '']));
|
Assert::same(['col' => 0.0], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => 0.0], $result->test(['col' => '0']));
|
Assert::same(['col' => 0.0], $result->test(['col' => '0']));
|
||||||
@@ -138,9 +138,9 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::INTEGER);
|
$result->setType('col', Type::INTEGER);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::same(['col' => 1], $result->test(['col' => TRUE]));
|
Assert::same(['col' => 1], $result->test(['col' => true]));
|
||||||
Assert::same(['col' => 0], $result->test(['col' => FALSE]));
|
Assert::same(['col' => 0], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => 0], @$result->test(['col' => ''])); // triggers warning in PHP 7.1
|
Assert::same(['col' => 0], @$result->test(['col' => ''])); // triggers warning in PHP 7.1
|
||||||
Assert::same(['col' => 0], $result->test(['col' => '0']));
|
Assert::same(['col' => 0], $result->test(['col' => '0']));
|
||||||
@@ -164,14 +164,14 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::DATETIME);
|
$result->setType('col', Type::DATETIME);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::exception(function () use ($result) {
|
Assert::exception(function () use ($result) {
|
||||||
$result->test(['col' => TRUE]);
|
$result->test(['col' => true]);
|
||||||
}, TypeError::class);
|
}, TypeError::class);
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
Assert::same(['col' => null], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
Assert::same(['col' => null], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
Assert::same(['col' => null], $result->test(['col' => '0000-00-00']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00']));
|
Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13']));
|
Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('2015-10-13 14:30')], $result->test(['col' => '2015-10-13 14:30']));
|
Assert::equal(['col' => new Dibi\DateTime('2015-10-13 14:30')], $result->test(['col' => '2015-10-13 14:30']));
|
||||||
@@ -183,14 +183,14 @@ test(function () {
|
|||||||
$result->setType('col', Type::DATETIME);
|
$result->setType('col', Type::DATETIME);
|
||||||
$result->setFormat(Type::DATETIME, 'Y-m-d H:i:s');
|
$result->setFormat(Type::DATETIME, 'Y-m-d H:i:s');
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::exception(function () use ($result) {
|
Assert::exception(function () use ($result) {
|
||||||
$result->test(['col' => TRUE]);
|
$result->test(['col' => true]);
|
||||||
}, TypeError::class);
|
}, TypeError::class);
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
Assert::same(['col' => null], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
Assert::same(['col' => null], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
Assert::same(['col' => null], $result->test(['col' => '0000-00-00']));
|
||||||
Assert::same(['col' => date('Y-m-d 00:00:00')], $result->test(['col' => '00:00:00']));
|
Assert::same(['col' => date('Y-m-d 00:00:00')], $result->test(['col' => '00:00:00']));
|
||||||
Assert::equal(['col' => '2015-10-13 00:00:00'], $result->test(['col' => '2015-10-13']));
|
Assert::equal(['col' => '2015-10-13 00:00:00'], $result->test(['col' => '2015-10-13']));
|
||||||
Assert::equal(['col' => '2015-10-13 14:30:00'], $result->test(['col' => '2015-10-13 14:30']));
|
Assert::equal(['col' => '2015-10-13 14:30:00'], $result->test(['col' => '2015-10-13 14:30']));
|
||||||
@@ -201,14 +201,14 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::DATE);
|
$result->setType('col', Type::DATE);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::exception(function () use ($result) {
|
Assert::exception(function () use ($result) {
|
||||||
$result->test(['col' => TRUE]);
|
$result->test(['col' => true]);
|
||||||
}, TypeError::class);
|
}, TypeError::class);
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
Assert::same(['col' => null], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
Assert::same(['col' => null], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
Assert::same(['col' => null], $result->test(['col' => '0000-00-00']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13']));
|
Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13']));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -217,14 +217,14 @@ test(function () {
|
|||||||
$result = new MockResult;
|
$result = new MockResult;
|
||||||
$result->setType('col', Type::TIME);
|
$result->setType('col', Type::TIME);
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
Assert::same(['col' => null], $result->test(['col' => null]));
|
||||||
Assert::exception(function () use ($result) {
|
Assert::exception(function () use ($result) {
|
||||||
$result->test(['col' => TRUE]);
|
$result->test(['col' => true]);
|
||||||
}, TypeError::class);
|
}, TypeError::class);
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
Assert::same(['col' => null], $result->test(['col' => false]));
|
||||||
|
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
Assert::same(['col' => null], $result->test(['col' => '']));
|
||||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
Assert::same(['col' => null], $result->test(['col' => '0000-00-00']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00']));
|
Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00']));
|
||||||
Assert::equal(['col' => new Dibi\DateTime('14:30')], $result->test(['col' => '14:30']));
|
Assert::equal(['col' => new Dibi\DateTime('14:30')], $result->test(['col' => '14:30']));
|
||||||
});
|
});
|
||||||
|
@@ -15,5 +15,5 @@ $translator = new Dibi\Translator($conn);
|
|||||||
|
|
||||||
$datetime = new DateTime('1978-01-23 00:00:00');
|
$datetime = new DateTime('1978-01-23 00:00:00');
|
||||||
|
|
||||||
Assert::equal($datetime->format('U'), $translator->formatValue(new DateTime($datetime->format('c')), NULL));
|
Assert::equal($datetime->format('U'), $translator->formatValue(new DateTime($datetime->format('c')), null));
|
||||||
Assert::equal($datetime->format('U'), $translator->formatValue(new DateTimeImmutable($datetime->format('c')), NULL));
|
Assert::equal($datetime->format('U'), $translator->formatValue(new DateTimeImmutable($datetime->format('c')), null));
|
||||||
|
@@ -35,7 +35,7 @@ FROM [customers] /* ... */'),
|
|||||||
|
|
||||||
$conn->translate('
|
$conn->translate('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM %if', TRUE, '[customers] %else [products]'
|
FROM %if', true, '[customers] %else [products]'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ WHERE [id] > 0
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM [people]
|
FROM [people]
|
||||||
WHERE [id] > 0
|
WHERE [id] > 0
|
||||||
%if', FALSE, 'AND [foo]=%i', 1, '
|
%if', false, 'AND [foo]=%i', 1, '
|
||||||
%else %if', TRUE, 'AND [bar]=%i', 1, '
|
%else %if', true, 'AND [bar]=%i', 1, '
|
||||||
'));
|
'));
|
||||||
|
|
||||||
|
|
||||||
@@ -72,8 +72,8 @@ WHERE
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM [customers]
|
FROM [customers]
|
||||||
WHERE
|
WHERE
|
||||||
%if', TRUE, '[name] LIKE %s', 'xxx', '
|
%if', true, '[name] LIKE %s', 'xxx', '
|
||||||
%if', FALSE, 'AND [admin]=1 %end
|
%if', false, 'AND [admin]=1 %end
|
||||||
%else 1 LIMIT 10 %end'
|
%else 1 LIMIT 10 %end'
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ Assert::same(
|
|||||||
'SELECT * FROM foo /* (limit 3) (offset 5) */',
|
'SELECT * FROM foo /* (limit 3) (offset 5) */',
|
||||||
$conn->translate(
|
$conn->translate(
|
||||||
'SELECT * FROM foo',
|
'SELECT * FROM foo',
|
||||||
'%if', FALSE,
|
'%if', false,
|
||||||
'%lmt', 3,
|
'%lmt', 3,
|
||||||
'%ofs', 5,
|
'%ofs', 5,
|
||||||
'%end'
|
'%end'
|
||||||
|
@@ -27,7 +27,7 @@ Assert::same(
|
|||||||
$array = [
|
$array = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => null,
|
||||||
];
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'),
|
reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'),
|
||||||
@@ -108,7 +108,7 @@ Assert::same(
|
|||||||
|
|
||||||
|
|
||||||
$where = [];
|
$where = [];
|
||||||
$where['age'] = NULL;
|
$where['age'] = null;
|
||||||
$where['email'] = 'ahoj';
|
$where['email'] = 'ahoj';
|
||||||
$where['id%l'] = [10, 20, 30];
|
$where['id%l'] = [10, 20, 30];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
@@ -130,8 +130,8 @@ $order = [
|
|||||||
'field2' => 'desc',
|
'field2' => 'desc',
|
||||||
'field3' => 1,
|
'field3' => 1,
|
||||||
'field4' => -1,
|
'field4' => -1,
|
||||||
'field5' => TRUE,
|
'field5' => true,
|
||||||
'field6' => FALSE,
|
'field6' => false,
|
||||||
];
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'),
|
reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'),
|
||||||
@@ -193,8 +193,8 @@ Assert::same(
|
|||||||
'b5' => new DateTime('1212-09-26'),
|
'b5' => new DateTime('1212-09-26'),
|
||||||
'b6%d' => new DateTime('1212-09-26'),
|
'b6%d' => new DateTime('1212-09-26'),
|
||||||
'b7%t' => new DateTime('1212-09-26'),
|
'b7%t' => new DateTime('1212-09-26'),
|
||||||
'b8%d' => NULL,
|
'b8%d' => null,
|
||||||
'b9%t' => NULL,
|
'b9%t' => null,
|
||||||
'c1%t' => new DateTime('1212-09-26 16:51:34.0124'),
|
'c1%t' => new DateTime('1212-09-26 16:51:34.0124'),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ $array3 = [
|
|||||||
];
|
];
|
||||||
$array4 = [
|
$array4 = [
|
||||||
'a' => 12,
|
'a' => 12,
|
||||||
'b' => NULL,
|
'b' => null,
|
||||||
'c' => new DateTime('12.3.2007'),
|
'c' => new DateTime('12.3.2007'),
|
||||||
'd' => 'any string',
|
'd' => 'any string',
|
||||||
];
|
];
|
||||||
@@ -398,9 +398,9 @@ WHERE ([test.a] LIKE %d', '1995-03-01', '
|
|||||||
OR [b10] IN (', [], ")
|
OR [b10] IN (', [], ")
|
||||||
AND [c] = 'embedded '' string'
|
AND [c] = 'embedded '' string'
|
||||||
OR [d]=%i", 10.3, '
|
OR [d]=%i", 10.3, '
|
||||||
OR [e]=%i', NULL, '
|
OR [e]=%i', null, '
|
||||||
OR [true]=', TRUE, '
|
OR [true]=', true, '
|
||||||
OR [false]=', FALSE, '
|
OR [false]=', false, '
|
||||||
OR [str_null]=%sn', '', '
|
OR [str_null]=%sn', '', '
|
||||||
OR [str_not_null]=%sn', 'hello', '
|
OR [str_not_null]=%sn', 'hello', '
|
||||||
LIMIT 10')
|
LIMIT 10')
|
||||||
@@ -452,7 +452,7 @@ Assert::same(
|
|||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT FROM ... '),
|
reformat('SELECT FROM ... '),
|
||||||
$conn->translate('SELECT FROM ... %lmt', NULL)
|
$conn->translate('SELECT FROM ... %lmt', null)
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
|
@@ -19,7 +19,7 @@ date_default_timezone_set('Europe/Prague');
|
|||||||
try {
|
try {
|
||||||
$config = Tester\Environment::loadData();
|
$config = Tester\Environment::loadData();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$config = parse_ini_file(__DIR__ . '/../databases.ini', TRUE);
|
$config = parse_ini_file(__DIR__ . '/../databases.ini', true);
|
||||||
$config = reset($config);
|
$config = reset($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,14 +24,14 @@ Assert::same('SELECT', $e->getSql());
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||||
}, Dibi\UniqueConstraintViolationException::class, NULL, 19);
|
}, Dibi\UniqueConstraintViolationException::class, null, 19);
|
||||||
|
|
||||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||||
|
|
||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||||
}, Dibi\NotNullConstraintViolationException::class, NULL, 19);
|
}, Dibi\NotNullConstraintViolationException::class, null, 19);
|
||||||
|
|
||||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||||
|
|
||||||
@@ -39,6 +39,6 @@ Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
|||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('PRAGMA foreign_keys=true');
|
$conn->query('PRAGMA foreign_keys=true');
|
||||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||||
}, Dibi\ForeignKeyConstraintViolationException::class, NULL, 19);
|
}, Dibi\ForeignKeyConstraintViolationException::class, null, 19);
|
||||||
|
|
||||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
||||||
|
Reference in New Issue
Block a user