1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00
This commit is contained in:
David Grudl
2023-09-26 01:46:03 +02:00
parent 8564217bc1
commit e45638eab4
8 changed files with 41 additions and 44 deletions

View File

@@ -62,7 +62,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(), return: true),
]; ];
} }
@@ -118,7 +118,7 @@ class Panel implements Tracy\IBarPanel
? $this->explain ? $this->explain
: ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
try { try {
$explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), true); $explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), return: true);
} catch (Dibi\Exception $e) { } catch (Dibi\Exception $e) {
} }
@@ -132,7 +132,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, return: 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>";
} }

View File

@@ -119,7 +119,7 @@ class OdbcDriver implements Dibi\Driver
*/ */
public function begin(?string $savepoint = null): void public function begin(?string $savepoint = null): void
{ {
if (!odbc_autocommit($this->connection, false)) { if (!odbc_autocommit($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));
} }
} }

View File

@@ -94,22 +94,13 @@ class PdoDriver implements Dibi\Driver
[$sqlState, $code, $message] = $this->connection->errorInfo(); [$sqlState, $code, $message] = $this->connection->errorInfo();
$message = "SQLSTATE[$sqlState]: $message"; $message = "SQLSTATE[$sqlState]: $message";
switch ($this->driverName) { throw match ($this->driverName) {
case 'mysql': 'mysql' => MySqliDriver::createException($message, $code, $sql),
throw MySqliDriver::createException($message, $code, $sql); 'oci' => OracleDriver::createException($message, $code, $sql),
'pgsql' => PostgreDriver::createException($message, $sqlState, $sql),
case 'oci': 'sqlite' => SqliteDriver::createException($message, $code, $sql),
throw OracleDriver::createException($message, $code, $sql); default => new Dibi\DriverException($message, $code, $sql),
};
case 'pgsql':
throw PostgreDriver::createException($message, $sqlState, $sql);
case 'sqlite':
throw SqliteDriver::createException($message, $code, $sql);
default:
throw new Dibi\DriverException($message, $code, $sql);
}
} }

View File

@@ -285,14 +285,11 @@ class Fluent implements IDataSource
public function execute(?string $return = null): Result|int|null public function execute(?string $return = null): Result|int|null
{ {
$res = $this->query($this->_export()); $res = $this->query($this->_export());
switch ($return) { return match ($return) {
case \dibi::IDENTIFIER: \dibi::IDENTIFIER => $this->connection->getInsertId(),
return $this->connection->getInsertId(); \dibi::AFFECTED_ROWS => $this->connection->getAffectedRows(),
case \dibi::AFFECTED_ROWS: default => $res,
return $this->connection->getAffectedRows(); };
default:
return $res;
}
} }

View File

@@ -46,7 +46,7 @@ abstract class HashMapBase
*/ */
final class HashMap extends HashMapBase final class HashMap extends HashMapBase
{ {
public function __set(string $nm, $val) public function __set(string $nm, mixed $val): void
{ {
if ($nm === '') { if ($nm === '') {
$nm = "\xFF"; $nm = "\xFF";
@@ -56,7 +56,7 @@ final class HashMap extends HashMapBase
} }
public function __get(string $nm) public function __get(string $nm): mixed
{ {
if ($nm === '') { if ($nm === '') {
$nm = "\xFF"; $nm = "\xFF";

View File

@@ -48,10 +48,11 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
} }
public function __get(string $key) public function __get(string $key): mixed
{ {
$hint = Helpers::getSuggestion(array_keys((array) $this), $key); $hint = Helpers::getSuggestion(array_keys((array) $this), $key);
trigger_error("Attempt to read missing column '$key'" . ($hint ? ", did you mean '$hint'?" : '.'), E_USER_NOTICE); trigger_error("Attempt to read missing column '$key'" . ($hint ? ", did you mean '$hint'?" : '.'), E_USER_NOTICE);
return null;
} }

View File

@@ -24,13 +24,17 @@ Assert::true(isset($row['title']));
// missing // missing
Assert::error(function () use ($row) { Assert::error(
$x = $row->missing; fn() => $x = $row->missing,
}, E_USER_NOTICE, "Attempt to read missing column 'missing'."); E_USER_NOTICE,
"Attempt to read missing column 'missing'.",
);
Assert::error(function () use ($row) { Assert::error(
$x = $row['missing']; fn() => $x = $row['missing'],
}, E_USER_NOTICE, "Attempt to read missing column 'missing'."); E_USER_NOTICE,
"Attempt to read missing column 'missing'.",
);
Assert::false(isset($row->missing)); Assert::false(isset($row->missing));
Assert::false(isset($row['missing'])); Assert::false(isset($row['missing']));
@@ -41,13 +45,17 @@ Assert::same(123, $row['missing'] ?? 123);
// suggestions // suggestions
Assert::error(function () use ($row) { Assert::error(
$x = $row->tilte; fn() => $x = $row->tilte,
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?"); E_USER_NOTICE,
"Attempt to read missing column 'tilte', did you mean 'title'?",
);
Assert::error(function () use ($row) { Assert::error(
$x = $row['tilte']; fn() => $x = $row['tilte'],
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?"); E_USER_NOTICE,
"Attempt to read missing column 'tilte', did you mean 'title'?",
);
// to array // to array

View File

@@ -20,7 +20,7 @@ date_default_timezone_set('Europe/Prague');
try { try {
$config = Tester\Environment::loadData(); $config = Tester\Environment::loadData();
} catch (Throwable $e) { } catch (Throwable $e) {
$config = parse_ini_file(__DIR__ . '/../databases.ini', true); $config = parse_ini_file(__DIR__ . '/../databases.ini', process_sections: true);
$config = reset($config); $config = reset($config);
} }