mirror of
https://github.com/dg/dibi.git
synced 2025-08-30 01:09:50 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
997f5a98f8 | ||
|
e4b3cfb12c | ||
|
26082294b6 | ||
|
b3052b4ce2 | ||
|
efa3a48232 | ||
|
24511a1d96 | ||
|
a20ba29b13 | ||
|
a606be0efa |
16
composer.json
Normal file
16
composer.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "dg/dibi",
|
||||
"description": "Dibi is Database Abstraction Library for PHP 5.",
|
||||
"keywords": ["dibi", "database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "oracle", "access", "pdo", "odbc"],
|
||||
"homepage": "http://dibiphp.com/",
|
||||
"license": ["BSD-3", "GPLv2", "GPLv3"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Grudl",
|
||||
"homepage": "http://davidgrudl.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"classmap": ["dibi/"]
|
||||
}
|
||||
}
|
@@ -101,9 +101,13 @@ class DibiNettePanel extends DibiObject implements IBarPanel
|
||||
*/
|
||||
public function getTab()
|
||||
{
|
||||
$totalTime = 0;
|
||||
foreach ($this->events as $event) {
|
||||
$totalTime += $event->time;
|
||||
}
|
||||
return '<span title="dibi"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />'
|
||||
. dibi::$numOfQueries . ' queries'
|
||||
. (dibi::$totalTime ? ' / ' . sprintf('%0.1f', dibi::$totalTime * 1000) . 'ms' : '')
|
||||
. count($this->events) . ' queries'
|
||||
. ($totalTime ? ' / ' . sprintf('%0.1f', $totalTime * 1000) . 'ms' : '')
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
@@ -115,9 +119,10 @@ class DibiNettePanel extends DibiObject implements IBarPanel
|
||||
*/
|
||||
public function getPanel()
|
||||
{
|
||||
$s = NULL;
|
||||
$totalTime = $s = NULL;
|
||||
$h = 'htmlSpecialChars';
|
||||
foreach ($this->events as $event) {
|
||||
$totalTime += $event->time;
|
||||
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
||||
if ($this->explain && $event->type === DibiEvent::SELECT) {
|
||||
try {
|
||||
@@ -155,7 +160,7 @@ class DibiNettePanel extends DibiObject implements IBarPanel
|
||||
'<style> #nette-debug td.nette-DibiProfiler-sql { background: white !important }
|
||||
#nette-debug .nette-DibiProfiler-source { color: #999 !important }
|
||||
#nette-debug nette-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
||||
<h1>Queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>
|
||||
<h1>Queries: ' . count($this->events) . ($totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', $totalTime * 1000) . ' ms') . '</h1>
|
||||
<div class="nette-inner nette-DibiProfiler">
|
||||
<table>
|
||||
<tr><th>Time ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '
|
||||
|
@@ -80,7 +80,7 @@ class dibi
|
||||
FIELD_TIME = dibi::TIME;
|
||||
|
||||
/** version */
|
||||
const VERSION = '2.0',
|
||||
const VERSION = '2.0.1',
|
||||
REVISION = '$WCREV$ released on $WCDATE$';
|
||||
|
||||
/** sorting order */
|
||||
|
@@ -375,14 +375,12 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
|
||||
*/
|
||||
public function getResultColumns()
|
||||
{
|
||||
$count = sqlsrv_num_fields($this->resultSet);
|
||||
$columns = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$row = (array) sqlsrv_field_metadata($this->resultSet, $i);
|
||||
foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) {
|
||||
$columns[] = array(
|
||||
'name' => $row['Name'],
|
||||
'fullname' => $row['Name'],
|
||||
'nativetype' => $row['Type'],
|
||||
'name' => $fieldMetadata['Name'],
|
||||
'fullname' => $fieldMetadata['Name'],
|
||||
'nativetype' => $fieldMetadata['Type'],
|
||||
);
|
||||
}
|
||||
return $columns;
|
||||
|
@@ -339,8 +339,6 @@ class DibiConnection extends DibiObject
|
||||
$this->connected || $this->connect();
|
||||
|
||||
$event = $this->onEvent ? new DibiEvent($this, DibiEvent::QUERY, $sql) : NULL;
|
||||
dibi::$numOfQueries++;
|
||||
dibi::$sql = $sql;
|
||||
try {
|
||||
$res = $this->driver->query($sql);
|
||||
|
||||
|
@@ -80,6 +80,8 @@ class DibiEvent
|
||||
}
|
||||
|
||||
dibi::$elapsedTime = FALSE;
|
||||
dibi::$numOfQueries++;
|
||||
dibi::$sql = $sql;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -28,6 +28,12 @@ class DibiFirePhpLogger extends DibiObject
|
||||
/** @var int */
|
||||
public $filter;
|
||||
|
||||
/** @var int Elapsed time for all queries */
|
||||
public $totalTime = 0;
|
||||
|
||||
/** @var int Number of all queries */
|
||||
public $numOfQueries = 0;
|
||||
|
||||
/** @var array */
|
||||
private static $fireTable = array(array('Time', 'SQL Statement', 'Rows', 'Connection'));
|
||||
|
||||
@@ -60,10 +66,12 @@ class DibiFirePhpLogger extends DibiObject
|
||||
return;
|
||||
}
|
||||
|
||||
$this->totalTime += $event->time;
|
||||
$this->numOfQueries++;
|
||||
self::$fireTable[] = array(
|
||||
sprintf('%0.3f', $event->time * 1000),
|
||||
strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql,
|
||||
$event->result instanceof Exception ? 'ERROR' : $event->count,
|
||||
$event->result instanceof Exception ? 'ERROR' : (string) $event->count,
|
||||
$event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name')
|
||||
);
|
||||
|
||||
@@ -74,7 +82,7 @@ class DibiFirePhpLogger extends DibiObject
|
||||
$payload = json_encode(array(
|
||||
array(
|
||||
'Type' => 'TABLE',
|
||||
'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)',
|
||||
'Label' => 'dibi profiler (' . $this->numOfQueries . ' SQL queries took ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms)',
|
||||
),
|
||||
self::$fireTable,
|
||||
));
|
||||
|
@@ -364,7 +364,7 @@ final class DibiTranslator extends DibiObject
|
||||
if (is_string($value) && is_numeric($value) && strpos($value, 'x') === FALSE) {
|
||||
return $value; // something like -9E-005 is accepted by SQL, HEX values are not
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 5, '.', ''), '0'), '.');
|
||||
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 20, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
case 'd': // date
|
||||
@@ -436,7 +436,7 @@ final class DibiTranslator extends DibiObject
|
||||
return (string) $value;
|
||||
|
||||
} elseif (is_float($value)) {
|
||||
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
|
||||
return rtrim(rtrim(number_format($value, 20, '.', ''), '0'), '.');
|
||||
|
||||
} elseif (is_bool($value)) {
|
||||
return $this->driver->escape($value, dibi::BOOL);
|
||||
|
@@ -18,6 +18,20 @@ require_once '../dibi/dibi.php';
|
||||
ndebug();
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'data/sample.sdb',
|
||||
'profiler' => array(
|
||||
'run' => TRUE,
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// throws error because SQL is bad
|
||||
dibi::query('SELECT * FROM customers WHERE customer_id < ?', 38);
|
||||
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'data/sample.sdb',
|
||||
|
@@ -1 +1 @@
|
||||
Dibi 2.0 (revision $WCREV$ released on $WCDATE$)
|
||||
Dibi 2.0.1 (revision $WCREV$ released on $WCDATE$)
|
||||
|
Reference in New Issue
Block a user