mirror of
https://github.com/dg/dibi.git
synced 2025-08-13 01:24:06 +02:00
* update DibiVariableInterface
* some bugs fixed
This commit is contained in:
@@ -106,7 +106,7 @@ class DibiConnection extends NObject
|
||||
{
|
||||
$this->driver->connect($this->config);
|
||||
$this->connected = TRUE;
|
||||
dibi::notify('connected');
|
||||
dibi::notify($this, 'connected');
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class DibiConnection extends NObject
|
||||
if ($this->connected) {
|
||||
$this->driver->disconnect();
|
||||
$this->connected = FALSE;
|
||||
dibi::notify('disconnected');
|
||||
dibi::notify($this, 'disconnected');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,12 +234,19 @@ class DibiConnection extends NObject
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
|
||||
dibi::notify('beforeQuery', $this, $sql);
|
||||
dibi::$numOfQueries++;
|
||||
dibi::$sql = $sql;
|
||||
dibi::$elapsedTime = FALSE;
|
||||
$time = -microtime(TRUE);
|
||||
dibi::notify($this, 'beforeQuery', $sql);
|
||||
|
||||
$res = $this->driver->query($sql);
|
||||
$res = $res ? new DibiResult(clone $this->driver) : TRUE; // backward compatibility - will be changed to NULL
|
||||
|
||||
dibi::notify('afterQuery', $this, $res);
|
||||
$time += microtime(TRUE);
|
||||
dibi::$elapsedTime = $time;
|
||||
dibi::$totalTime += $time;
|
||||
dibi::notify($this, 'afterQuery', $res);
|
||||
|
||||
return $res;
|
||||
}
|
||||
@@ -280,7 +287,7 @@ class DibiConnection extends NObject
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
$this->driver->begin();
|
||||
dibi::notify('begin', $this);
|
||||
dibi::notify($this, 'begin');
|
||||
}
|
||||
|
||||
|
||||
@@ -293,7 +300,7 @@ class DibiConnection extends NObject
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
$this->driver->commit();
|
||||
dibi::notify('commit', $this);
|
||||
dibi::notify($this, 'commit');
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +313,7 @@ class DibiConnection extends NObject
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
$this->driver->rollback();
|
||||
dibi::notify('rollback', $this);
|
||||
dibi::notify($this, 'rollback');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -209,5 +209,5 @@ interface DibiVariableInterface
|
||||
* @param string optional modifier
|
||||
* @return string SQL code
|
||||
*/
|
||||
public function toSQL($driver, $modifier = NULL);
|
||||
public function toSql(DibiDriverInterface $driver, $modifier);
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ class DibiDatabaseException extends DibiException
|
||||
{
|
||||
parent::__construct($message);
|
||||
$this->sql = $sql;
|
||||
dibi::notify('exception', NULL, $this);
|
||||
dibi::notify(NULL, 'exception', $this);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -53,17 +53,17 @@ final class DibiLogger extends NObject
|
||||
/**
|
||||
* Event handler (events: exception, connected, beforeQuery, afterQuery, begin, commit, rollback)
|
||||
*
|
||||
* @param DibiConnection
|
||||
* @param string event name
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
public function handler($event, $connection, $arg)
|
||||
public function handler($connection, $event, $arg)
|
||||
{
|
||||
if ($event === 'afterQuery' && $this->logQueries) {
|
||||
$this->write(
|
||||
"OK: " . dibi::$sql
|
||||
. ($arg instanceof DibiResult ? ";\n-- rows: " . $arg->rowCount() : '')
|
||||
. ($arg instanceof DibiResult ? ";\n-- rows: " . count($arg) : '')
|
||||
. "\n-- takes: " . sprintf('%0.3f', dibi::$elapsedTime * 1000) . ' ms'
|
||||
. "\n-- driver: " . $connection->getConfig('driver')
|
||||
. "\n-- " . date('Y-m-d H:i:s')
|
||||
|
@@ -312,7 +312,7 @@ final class DibiTranslator extends NObject
|
||||
return 'NULL';
|
||||
|
||||
if ($value instanceof DibiVariableInterface)
|
||||
return $value->toSql($this->driver);
|
||||
return $value->toSql($this->driver, NULL);
|
||||
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected ' . gettype($value) . '**';
|
||||
|
Reference in New Issue
Block a user