mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 12:47:33 +02:00
used PHP 7.1 features
- ::class - ... argument unpacking - removed call_user_func - operator ?? - list() - short <?=
This commit is contained in:
@@ -25,13 +25,13 @@ for ($i = 0; $i < 20; $i++) {
|
|||||||
|
|
||||||
// display output
|
// display output
|
||||||
?>
|
?>
|
||||||
<p>Last query: <strong><?php echo dibi::$sql; ?></strong></p>
|
<p>Last query: <strong><?= dibi::$sql; ?></strong></p>
|
||||||
|
|
||||||
<p>Number of queries: <strong><?php echo dibi::$numOfQueries; ?></strong></p>
|
<p>Number of queries: <strong><?= dibi::$numOfQueries; ?></strong></p>
|
||||||
|
|
||||||
<p>Elapsed time for last query: <strong><?php echo sprintf('%0.3f', dibi::$elapsedTime * 1000); ?> ms</strong></p>
|
<p>Elapsed time for last query: <strong><?= sprintf('%0.3f', dibi::$elapsedTime * 1000); ?> ms</strong></p>
|
||||||
|
|
||||||
<p>Total elapsed time: <strong><?php echo sprintf('%0.3f', dibi::$totalTime * 1000); ?> ms</strong></p>
|
<p>Total elapsed time: <strong><?= sprintf('%0.3f', dibi::$totalTime * 1000); ?> ms</strong></p>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ namespace Dibi\Bridges\Nette;
|
|||||||
|
|
||||||
use Dibi;
|
use Dibi;
|
||||||
use Nette;
|
use Nette;
|
||||||
|
use Tracy;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,9 +36,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
$this->debugMode = $container->parameters['debugMode'];
|
$this->debugMode = $container->parameters['debugMode'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$useProfiler = isset($config['profiler'])
|
$useProfiler = $config['profiler'] ?? (class_exists(Tracy\Debugger::class) && $this->debugMode);
|
||||||
? $config['profiler']
|
|
||||||
: class_exists('Tracy\Debugger') && $this->debugMode;
|
|
||||||
|
|
||||||
unset($config['profiler']);
|
unset($config['profiler']);
|
||||||
|
|
||||||
@@ -50,19 +49,19 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
$connection = $container->addDefinition($this->prefix('connection'))
|
$connection = $container->addDefinition($this->prefix('connection'))
|
||||||
->setClass('Dibi\Connection', [$config])
|
->setClass(Dibi\Connection::class, [$config])
|
||||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
->setAutowired($config['autowired'] ?? TRUE);
|
||||||
|
|
||||||
if (class_exists('Tracy\Debugger')) {
|
if (class_exists(Tracy\Debugger::class)) {
|
||||||
$connection->addSetup(
|
$connection->addSetup(
|
||||||
[new Nette\DI\Statement('Tracy\Debugger::getBlueScreen'), 'addPanel'],
|
[new Nette\DI\Statement('Tracy\Debugger::getBlueScreen'), 'addPanel'],
|
||||||
[['Dibi\Bridges\Tracy\Panel', 'renderException']]
|
[[Dibi\Bridges\Tracy\Panel::class, 'renderException']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($useProfiler) {
|
if ($useProfiler) {
|
||||||
$panel = $container->addDefinition($this->prefix('panel'))
|
$panel = $container->addDefinition($this->prefix('panel'))
|
||||||
->setClass('Dibi\Bridges\Tracy\Panel', [
|
->setClass(Dibi\Bridges\Tracy\Panel::class, [
|
||||||
isset($config['explain']) ? $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]);
|
||||||
|
@@ -117,7 +117,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
$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) {
|
||||||
}
|
}
|
||||||
list($connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup;
|
[$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime] = $backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
$s .= '<tr><td>' . number_format($event->time * 1000, 3, '.', ' ');
|
$s .= '<tr><td>' . number_format($event->time * 1000, 3, '.', ' ');
|
||||||
|
@@ -82,7 +82,7 @@ class Connection
|
|||||||
if ($config['driver'] instanceof Driver) {
|
if ($config['driver'] instanceof Driver) {
|
||||||
$this->driver = $config['driver'];
|
$this->driver = $config['driver'];
|
||||||
$config['driver'] = get_class($this->driver);
|
$config['driver'] = get_class($this->driver);
|
||||||
} elseif (is_subclass_of($config['driver'], 'Dibi\Driver')) {
|
} elseif (is_subclass_of($config['driver'], Driver::class)) {
|
||||||
$this->driver = new $config['driver'];
|
$this->driver = new $config['driver'];
|
||||||
} else {
|
} else {
|
||||||
$class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
|
$class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
|
||||||
@@ -102,7 +102,7 @@ class Connection
|
|||||||
$profilerCfg = ['run' => (bool) $profilerCfg];
|
$profilerCfg = ['run' => (bool) $profilerCfg];
|
||||||
}
|
}
|
||||||
if (!empty($profilerCfg['run'])) {
|
if (!empty($profilerCfg['run'])) {
|
||||||
$filter = isset($profilerCfg['filter']) ? $profilerCfg['filter'] : Event::QUERY;
|
$filter = $profilerCfg['filter'] ?? Event::QUERY;
|
||||||
|
|
||||||
if (isset($profilerCfg['file'])) {
|
if (isset($profilerCfg['file'])) {
|
||||||
$this->onEvent[] = [new Loggers\FileLogger($profilerCfg['file'], $filter), 'logEvent'];
|
$this->onEvent[] = [new Loggers\FileLogger($profilerCfg['file'], $filter), 'logEvent'];
|
||||||
@@ -186,15 +186,9 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
final public function getConfig($key = NULL, $default = NULL)
|
final public function getConfig($key = NULL, $default = NULL)
|
||||||
{
|
{
|
||||||
if ($key === NULL) {
|
return $key === NULL
|
||||||
return $this->config;
|
? $this->config
|
||||||
|
: ($this->config[$key] ?? $default);
|
||||||
} elseif (isset($this->config[$key])) {
|
|
||||||
return $this->config[$key];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -622,7 +616,7 @@ class Connection
|
|||||||
public function getDatabaseInfo()
|
public function getDatabaseInfo()
|
||||||
{
|
{
|
||||||
$this->connected || $this->connect();
|
$this->connected || $this->connect();
|
||||||
return new Reflection\Database($this->driver->getReflector(), isset($this->config['database']) ? $this->config['database'] : NULL);
|
return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -647,7 +641,7 @@ class Connection
|
|||||||
protected function onEvent($arg)
|
protected function onEvent($arg)
|
||||||
{
|
{
|
||||||
foreach ($this->onEvent ?: [] as $handler) {
|
foreach ($this->onEvent ?: [] as $handler) {
|
||||||
call_user_func($handler, $arg);
|
$handler($arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -476,7 +476,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if ($types === NULL) {
|
if ($types === NULL) {
|
||||||
$consts = get_defined_constants(TRUE);
|
$consts = get_defined_constants(TRUE);
|
||||||
$types = [];
|
$types = [];
|
||||||
foreach (isset($consts['mysqli']) ? $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) {
|
||||||
$types[$value] = substr($key, 12);
|
$types[$value] = substr($key, 12);
|
||||||
}
|
}
|
||||||
@@ -492,7 +492,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'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' => isset($types[$row['type']]) ? $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,
|
||||||
];
|
];
|
||||||
|
@@ -68,8 +68,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
$foo = &$config['charset'];
|
$foo = &$config['charset'];
|
||||||
|
|
||||||
if (empty($config['nativeDate'])) {
|
if (empty($config['nativeDate'])) {
|
||||||
$this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
|
$this->fmtDate = $config['formatDate'] ?? 'U';
|
||||||
$this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
|
$this->fmtDateTime = $config['formatDateTime'] ?? 'U';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['resource'])) {
|
if (isset($config['resource'])) {
|
||||||
@@ -495,7 +495,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
'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' => isset($row['DATA_LENGTH']) ? $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,
|
||||||
|
@@ -80,9 +80,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
|
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||||
$this->serverVersion = isset($config['version'])
|
$this->serverVersion = $config['version']
|
||||||
? $config['version']
|
?? @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); // @ - may be not supported
|
||||||
: @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); // @ - may be not supported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list($sqlState, $code, $message) = $this->connection->errorInfo();
|
[$sqlState, $code, $message] = $this->connection->errorInfo();
|
||||||
$message = "SQLSTATE[$sqlState]: $message";
|
$message = "SQLSTATE[$sqlState]: $message";
|
||||||
switch ($this->driverName) {
|
switch ($this->driverName) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
|
@@ -62,8 +62,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
public function connect(array &$config)
|
public function connect(array &$config)
|
||||||
{
|
{
|
||||||
Dibi\Helpers::alias($config, 'database', 'file');
|
Dibi\Helpers::alias($config, 'database', 'file');
|
||||||
$this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
|
$this->fmtDate = $config['formatDate'] ?? 'U';
|
||||||
$this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
|
$this->fmtDateTime = $config['formatDateTime'] ?? 'U';
|
||||||
|
|
||||||
if (isset($config['resource']) && $config['resource'] instanceof SQLite3) {
|
if (isset($config['resource']) && $config['resource'] instanceof SQLite3) {
|
||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
|
@@ -75,9 +75,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$options = $config['options'];
|
$options = $config['options'];
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
if (!isset($options['CharacterSet'])) {
|
$options['CharacterSet'] = $options['CharacterSet'] ?? 'UTF-8';
|
||||||
$options['CharacterSet'] = 'UTF-8';
|
|
||||||
}
|
|
||||||
$options['PWD'] = (string) $options['PWD'];
|
$options['PWD'] = (string) $options['PWD'];
|
||||||
$options['UID'] = (string) $options['UID'];
|
$options['UID'] = (string) $options['UID'];
|
||||||
$options['Database'] = (string) $options['Database'];
|
$options['Database'] = (string) $options['Database'];
|
||||||
|
@@ -117,7 +117,7 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
$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;
|
||||||
$indexes[$row['name']]['columns'] = isset($keyUsages[$row['name']]) ? $keyUsages[$row['name']] : [];
|
$indexes[$row['name']]['columns'] = $keyUsages[$row['name']] ?? [];
|
||||||
}
|
}
|
||||||
return array_values($indexes);
|
return array_values($indexes);
|
||||||
}
|
}
|
||||||
|
@@ -421,7 +421,8 @@ class Fluent implements IDataSource
|
|||||||
{
|
{
|
||||||
$res = $this->connection->query($args);
|
$res = $this->connection->query($args);
|
||||||
foreach ($this->setups as $setup) {
|
foreach ($this->setups as $setup) {
|
||||||
call_user_func_array([$res, array_shift($setup)], $setup);
|
$method = array_shift($setup);
|
||||||
|
$res->$method(...$setup);
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
@@ -58,9 +58,9 @@ final class HashMap extends HashMapBase
|
|||||||
{
|
{
|
||||||
if ($nm == '') {
|
if ($nm == '') {
|
||||||
$nm = "\xFF";
|
$nm = "\xFF";
|
||||||
return isset($this->$nm) ? $this->$nm : $this->$nm = call_user_func($this->getCallback(), '');
|
return $this->$nm = $this->$nm ?? $this->getCallback()('');
|
||||||
} else {
|
} else {
|
||||||
return $this->$nm = call_user_func($this->getCallback(), $nm);
|
return $this->$nm = $this->getCallback()($nm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -263,7 +263,7 @@ class Helpers
|
|||||||
$sql = '';
|
$sql = '';
|
||||||
$count++;
|
$count++;
|
||||||
if ($onProgress) {
|
if ($onProgress) {
|
||||||
call_user_func($onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL);
|
$onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -275,7 +275,7 @@ class Helpers
|
|||||||
$driver->query($sql);
|
$driver->query($sql);
|
||||||
$count++;
|
$count++;
|
||||||
if ($onProgress) {
|
if ($onProgress) {
|
||||||
call_user_func($onProgress, $count, isset($stat['size']) ? 100 : NULL);
|
$onProgress($count, isset($stat['size']) ? 100 : NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
@@ -57,7 +57,7 @@ class Column
|
|||||||
*/
|
*/
|
||||||
public function getFullName()
|
public function getFullName()
|
||||||
{
|
{
|
||||||
return isset($this->info['fullname']) ? $this->info['fullname'] : NULL;
|
return $this->info['fullname'] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ class Column
|
|||||||
*/
|
*/
|
||||||
public function getDefault()
|
public function getDefault()
|
||||||
{
|
{
|
||||||
return isset($this->info['default']) ? $this->info['default'] : NULL;
|
return $this->info['default'] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ class Column
|
|||||||
*/
|
*/
|
||||||
public function getVendorInfo($key)
|
public function getVendorInfo($key)
|
||||||
{
|
{
|
||||||
return isset($this->info['vendor'][$key]) ? $this->info['vendor'][$key] : NULL;
|
return $this->info['vendor'][$key] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ class Result implements IDataSource
|
|||||||
private $fetched = FALSE;
|
private $fetched = FALSE;
|
||||||
|
|
||||||
/** @var string returned object class */
|
/** @var string returned object class */
|
||||||
private $rowClass = 'Dibi\Row';
|
private $rowClass = Row::class;
|
||||||
|
|
||||||
/** @var callable returned object factory*/
|
/** @var callable returned object factory*/
|
||||||
private $rowFactory;
|
private $rowFactory;
|
||||||
@@ -185,7 +185,7 @@ class Result implements IDataSource
|
|||||||
$this->fetched = TRUE;
|
$this->fetched = TRUE;
|
||||||
$this->normalize($row);
|
$this->normalize($row);
|
||||||
if ($this->rowFactory) {
|
if ($this->rowFactory) {
|
||||||
return call_user_func($this->rowFactory, $row);
|
return ($this->rowFactory)($row);
|
||||||
} elseif ($this->rowClass) {
|
} elseif ($this->rowClass) {
|
||||||
$row = new $this->rowClass($row);
|
$row = new $this->rowClass($row);
|
||||||
}
|
}
|
||||||
@@ -461,7 +461,7 @@ class Result implements IDataSource
|
|||||||
$cache = Helpers::getTypeCache();
|
$cache = Helpers::getTypeCache();
|
||||||
try {
|
try {
|
||||||
foreach ($this->getResultDriver()->getResultColumns() as $col) {
|
foreach ($this->getResultDriver()->getResultColumns() as $col) {
|
||||||
$this->types[$col['name']] = isset($col['type']) ? $col['type'] : $cache->{$col['nativetype']};
|
$this->types[$col['name']] = $col['type'] ?? $cache->{$col['nativetype']};
|
||||||
}
|
}
|
||||||
} catch (NotSupportedException $e) {
|
} catch (NotSupportedException $e) {
|
||||||
}
|
}
|
||||||
@@ -543,7 +543,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function getType($col)
|
final public function getType($col)
|
||||||
{
|
{
|
||||||
return isset($this->types[$col]) ? $this->types[$col] : NULL;
|
return $this->types[$col] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -566,7 +566,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
final public function getFormat($type)
|
final public function getFormat($type)
|
||||||
{
|
{
|
||||||
return isset($this->formats[$type]) ? $this->formats[$type] : NULL;
|
return $this->formats[$type] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ trait Strict
|
|||||||
{
|
{
|
||||||
if ($cb = self::extensionMethod(get_class($this) . '::' . $name)) { // back compatiblity
|
if ($cb = self::extensionMethod(get_class($this) . '::' . $name)) { // back compatiblity
|
||||||
array_unshift($args, $this);
|
array_unshift($args, $this);
|
||||||
return call_user_func_array($cb, $args);
|
return $cb(...$args);
|
||||||
}
|
}
|
||||||
$class = method_exists($this, $name) ? 'parent' : get_class($this);
|
$class = method_exists($this, $name) ? 'parent' : get_class($this);
|
||||||
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
|
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||||
@@ -113,7 +113,7 @@ trait Strict
|
|||||||
if (strpos($name, '::') === FALSE) {
|
if (strpos($name, '::') === FALSE) {
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
} else {
|
} else {
|
||||||
list($class, $name) = explode('::', $name);
|
[$class, $name] = explode('::', $name);
|
||||||
$class = (new ReflectionClass($class))->getName();
|
$class = (new ReflectionClass($class))->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -238,7 +238,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
. $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
|
||||||
}
|
}
|
||||||
return implode(', ', $vx);
|
return implode(', ', $vx);
|
||||||
|
|
||||||
@@ -247,7 +247,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
|
||||||
}
|
}
|
||||||
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
||||||
|
|
||||||
@@ -256,7 +256,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
$vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
|
||||||
}
|
}
|
||||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||||
|
|
||||||
@@ -277,7 +277,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, isset($pair[1]) ? $pair[1] : (is_array($v2) ? 'ex' : FALSE));
|
$vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : FALSE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($vx as $k => $v) {
|
foreach ($vx as $k => $v) {
|
||||||
@@ -300,7 +300,7 @@ final class Translator
|
|||||||
|
|
||||||
case 'ex':
|
case 'ex':
|
||||||
case 'sql':
|
case 'sql':
|
||||||
return call_user_func_array([$this->connection, 'translate'], $value);
|
return $this->connection->translate(...$value);
|
||||||
|
|
||||||
default: // value, value, value - all with the same modifier
|
default: // value, value, value - all with the same modifier
|
||||||
foreach ($value as $v) {
|
foreach ($value as $v) {
|
||||||
|
@@ -75,7 +75,7 @@ class PcreException extends Exception
|
|||||||
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
|
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
|
||||||
];
|
];
|
||||||
$code = preg_last_error();
|
$code = preg_last_error();
|
||||||
parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
|
parent::__construct(str_replace('%msg', $messages[$code] ?? 'Unknown error', $message), $code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ test(function () use ($config) { // query string
|
|||||||
|
|
||||||
Assert::null($conn->getConfig('lazy'));
|
Assert::null($conn->getConfig('lazy'));
|
||||||
Assert::same($config['driver'], $conn->getConfig('driver'));
|
Assert::same($config['driver'], $conn->getConfig('driver'));
|
||||||
Assert::type('Dibi\Driver', $conn->getDriver());
|
Assert::type(Dibi\Driver::class, $conn->getDriver());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,16 +15,16 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|||||||
|
|
||||||
/*Assert::exception(function () use ($conn) {
|
/*Assert::exception(function () use ($conn) {
|
||||||
$conn->rollback();
|
$conn->rollback();
|
||||||
}, 'Dibi\Exception');
|
}, Dibi\Exception::class);
|
||||||
|
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
$conn->commit();
|
$conn->commit();
|
||||||
}, 'Dibi\Exception');
|
}, Dibi\Exception::class);
|
||||||
|
|
||||||
$conn->begin();
|
$conn->begin();
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
$conn->begin();
|
$conn->begin();
|
||||||
}, 'Dibi\Exception');
|
}, Dibi\Exception::class);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ class MockResult extends Dibi\Result
|
|||||||
|
|
||||||
function test($row)
|
function test($row)
|
||||||
{
|
{
|
||||||
$normalize = new ReflectionMethod('Dibi\Result', '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;
|
||||||
@@ -164,7 +164,7 @@ test(function () {
|
|||||||
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]);
|
||||||
}, 'Exception');
|
}, Exception::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' => '']));
|
||||||
@@ -183,7 +183,7 @@ test(function () {
|
|||||||
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]);
|
||||||
}, 'Exception');
|
}, Exception::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' => '']));
|
||||||
@@ -201,7 +201,7 @@ test(function () {
|
|||||||
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]);
|
||||||
}, 'Exception');
|
}, Exception::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' => '']));
|
||||||
@@ -217,7 +217,7 @@ test(function () {
|
|||||||
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]);
|
||||||
}, 'Exception');
|
}, Exception::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' => '']));
|
||||||
|
@@ -39,7 +39,7 @@ $tests = function ($conn) {
|
|||||||
function () use ($conn) {
|
function () use ($conn) {
|
||||||
$conn->translate('SELECT 1 %ofs', -10);
|
$conn->translate('SELECT 1 %ofs', -10);
|
||||||
},
|
},
|
||||||
'Dibi\NotSupportedException',
|
Dibi\NotSupportedException::class,
|
||||||
'Negative offset or limit.'
|
'Negative offset or limit.'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ $tests = function ($conn) {
|
|||||||
function () use ($conn) {
|
function () use ($conn) {
|
||||||
$conn->translate('SELECT 1 %lmt', -10);
|
$conn->translate('SELECT 1 %lmt', -10);
|
||||||
},
|
},
|
||||||
'Dibi\NotSupportedException',
|
Dibi\NotSupportedException::class,
|
||||||
'Negative offset or limit.'
|
'Negative offset or limit.'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ $tests = function ($conn) {
|
|||||||
function () use ($conn) {
|
function () use ($conn) {
|
||||||
$conn->translate('SELECT 1 %ofs %lmt', 10, -10);
|
$conn->translate('SELECT 1 %ofs %lmt', 10, -10);
|
||||||
},
|
},
|
||||||
'Dibi\NotSupportedException',
|
Dibi\NotSupportedException::class,
|
||||||
'Negative offset or limit.'
|
'Negative offset or limit.'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ $tests = function ($conn) {
|
|||||||
function () use ($conn) {
|
function () use ($conn) {
|
||||||
$conn->translate('SELECT 1 %ofs %lmt', -10, 10);
|
$conn->translate('SELECT 1 %ofs %lmt', -10, 10);
|
||||||
},
|
},
|
||||||
'Dibi\NotSupportedException',
|
Dibi\NotSupportedException::class,
|
||||||
'Negative offset or limit.'
|
'Negative offset or limit.'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +82,7 @@ $tests = function ($conn) {
|
|||||||
|
|
||||||
Assert::exception(
|
Assert::exception(
|
||||||
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
|
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
|
||||||
'DibiNotSupportedException'
|
Dibi\NotSupportedException::class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -51,53 +51,53 @@ class TestChild extends TestClass
|
|||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->undeclared();
|
$obj->undeclared();
|
||||||
}, 'LogicException', 'Call to undefined method TestClass::undeclared().');
|
}, LogicException::class, 'Call to undefined method TestClass::undeclared().');
|
||||||
|
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
TestClass::undeclared();
|
TestClass::undeclared();
|
||||||
}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');
|
}, LogicException::class, 'Call to undefined static method TestClass::undeclared().');
|
||||||
|
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestChild;
|
$obj = new TestChild;
|
||||||
$obj->callParent();
|
$obj->callParent();
|
||||||
}, 'LogicException', 'Call to undefined method parent::callParent().');
|
}, LogicException::class, 'Call to undefined method parent::callParent().');
|
||||||
|
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->publicMethodX();
|
$obj->publicMethodX();
|
||||||
}, 'LogicException', 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
|
}, LogicException::class, 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest static method
|
Assert::exception(function () { // suggest static method
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->publicMethodStaticX();
|
$obj->publicMethodStaticX();
|
||||||
}, 'LogicException', 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
|
}, LogicException::class, 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest only public method
|
Assert::exception(function () { // suggest only public method
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->protectedMethodX();
|
$obj->protectedMethodX();
|
||||||
}, 'LogicException', 'Call to undefined method TestClass::protectedMethodX().');
|
}, LogicException::class, 'Call to undefined method TestClass::protectedMethodX().');
|
||||||
|
|
||||||
|
|
||||||
// writing
|
// writing
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->undeclared = 'value';
|
$obj->undeclared = 'value';
|
||||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');
|
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$undeclared.');
|
||||||
|
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->publicX = 'value';
|
$obj->publicX = 'value';
|
||||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
|
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest only non-static property
|
Assert::exception(function () { // suggest only non-static property
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->publicStaticX = 'value';
|
$obj->publicStaticX = 'value';
|
||||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicStaticX.');
|
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicStaticX.');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest only public property
|
Assert::exception(function () { // suggest only public property
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$obj->protectedX = 'value';
|
$obj->protectedX = 'value';
|
||||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$protectedX.');
|
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$protectedX.');
|
||||||
|
|
||||||
|
|
||||||
// property getter
|
// property getter
|
||||||
@@ -112,29 +112,29 @@ Assert::same(456, $obj->foo);
|
|||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$val = $obj->undeclared;
|
$val = $obj->undeclared;
|
||||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');
|
}, LogicException::class, 'Attempt to read undeclared property TestClass::$undeclared.');
|
||||||
|
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$val = $obj->publicX;
|
$val = $obj->publicX;
|
||||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
|
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest only non-static property
|
Assert::exception(function () { // suggest only non-static property
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$val = $obj->publicStaticX;
|
$val = $obj->publicStaticX;
|
||||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicStaticX.');
|
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicStaticX.');
|
||||||
|
|
||||||
Assert::exception(function () { // suggest only public property
|
Assert::exception(function () { // suggest only public property
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
$val = $obj->protectedX;
|
$val = $obj->protectedX;
|
||||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$protectedX.');
|
}, LogicException::class, 'Attempt to read undeclared property TestClass::$protectedX.');
|
||||||
|
|
||||||
|
|
||||||
// unset/isset
|
// unset/isset
|
||||||
Assert::exception(function () {
|
Assert::exception(function () {
|
||||||
$obj = new TestClass;
|
$obj = new TestClass;
|
||||||
unset($obj->undeclared);
|
unset($obj->undeclared);
|
||||||
}, 'LogicException', 'Attempt to unset undeclared property TestClass::$undeclared.');
|
}, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.');
|
||||||
|
|
||||||
Assert::false(isset($obj->undeclared));
|
Assert::false(isset($obj->undeclared));
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ Assert::same(
|
|||||||
// invalid input
|
// invalid input
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
|
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
|
||||||
}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type stdClass and modifier %s');
|
}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type stdClass and modifier %s');
|
||||||
Assert::same('SELECT **Invalid combination of type stdClass and modifier %s** , **Unknown or unexpected modifier %m**', $e->getSql());
|
Assert::same('SELECT **Invalid combination of type stdClass and modifier %s** , **Unknown or unexpected modifier %m**', $e->getSql());
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
@@ -150,7 +150,7 @@ Assert::same(
|
|||||||
if ($config['system'] === 'odbc') {
|
if ($config['system'] === 'odbc') {
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1);
|
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1);
|
||||||
}, 'Dibi\Exception');
|
}, Dibi\Exception::class);
|
||||||
} else {
|
} else {
|
||||||
// with limit = 2, offset = 1
|
// with limit = 2, offset = 1
|
||||||
Assert::same(
|
Assert::same(
|
||||||
@@ -198,7 +198,7 @@ Assert::same(
|
|||||||
|
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
$conn->translate('SELECT %s', new DateTime('1212-09-26'));
|
$conn->translate('SELECT %s', new DateTime('1212-09-26'));
|
||||||
}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
|
}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ if ($config['system'] === 'postgre') {
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->translate("SELECT '");
|
$conn->translate("SELECT '");
|
||||||
}, 'Dibi\Exception', 'SQL translate error: Alone quote');
|
}, Dibi\Exception::class, 'SQL translate error: Alone quote');
|
||||||
Assert::same('SELECT **Alone quote**', $e->getSql());
|
Assert::same('SELECT **Alone quote**', $e->getSql());
|
||||||
|
|
||||||
Assert::match(
|
Assert::match(
|
||||||
@@ -491,7 +491,7 @@ $e = Assert::exception(function () use ($conn) {
|
|||||||
'num%i' => ['1', ''],
|
'num%i' => ['1', ''],
|
||||||
];
|
];
|
||||||
$conn->translate('INSERT INTO test %m', $array6);
|
$conn->translate('INSERT INTO test %m', $array6);
|
||||||
}, 'Dibi\Exception', 'SQL translate error: Multi-insert array "num%i" is different');
|
}, Dibi\Exception::class, 'SQL translate error: Multi-insert array "num%i" is different');
|
||||||
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different**', $e->getSql());
|
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different**', $e->getSql());
|
||||||
|
|
||||||
$array6 = [
|
$array6 = [
|
||||||
|
@@ -15,27 +15,27 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('SELECT');
|
$conn->query('SELECT');
|
||||||
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
|
}, Dibi\DriverException::class, "%a% error in your SQL syntax;%a%", 1064);
|
||||||
|
|
||||||
Assert::same('SELECT', $e->getSql());
|
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', "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
|
}, Dibi\UniqueConstraintViolationException::class, "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||||
|
|
||||||
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', "%a?%Column 'title' cannot be null", 1048);
|
}, Dibi\NotNullConstraintViolationException::class, "%a?%Column 'title' cannot be null", 1048);
|
||||||
|
|
||||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||||
|
|
||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$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', '%a% a foreign key constraint fails %a%', 1452);
|
}, Dibi\ForeignKeyConstraintViolationException::class, '%a% a foreign key constraint fails %a%', 1452);
|
||||||
|
|
||||||
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());
|
||||||
|
@@ -15,27 +15,27 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('SELECT INTO');
|
$conn->query('SELECT INTO');
|
||||||
}, 'Dibi\DriverException', '%a?%syntax error %A%');
|
}, Dibi\DriverException::class, '%a?%syntax error %A%');
|
||||||
|
|
||||||
Assert::same('SELECT INTO', $e->getSql());
|
Assert::same('SELECT INTO', $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', '%a% violates unique constraint %A%', '23505');
|
}, Dibi\UniqueConstraintViolationException::class, '%a% violates unique constraint %A%', '23505');
|
||||||
|
|
||||||
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', '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
|
}, Dibi\NotNullConstraintViolationException::class, '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
|
||||||
|
|
||||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||||
|
|
||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$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', '%a% violates foreign key constraint %A%', '23503');
|
}, Dibi\ForeignKeyConstraintViolationException::class, '%a% violates foreign key constraint %A%', '23503');
|
||||||
|
|
||||||
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());
|
||||||
|
@@ -15,21 +15,21 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('SELECT');
|
$conn->query('SELECT');
|
||||||
}, 'Dibi\DriverException', '%a% syntax error', 1);
|
}, Dibi\DriverException::class, '%a% syntax error', 1);
|
||||||
|
|
||||||
Assert::same('SELECT', $e->getSql());
|
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', 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', 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());
|
||||||
|
|
||||||
@@ -37,6 +37,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', 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