mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-28 15:49:57 +09:00
Reorganize query logging and add detailed comments
This commit is contained in:
parent
8a3afa03cc
commit
6e7049234e
2 changed files with 53 additions and 22 deletions
|
|
@ -8,6 +8,10 @@ use Rhymix\Framework\Exceptions\DBError;
|
|||
|
||||
/**
|
||||
* DB Statement helper class.
|
||||
*
|
||||
* We use instances of this class instead of raw PDOStatement in order to log
|
||||
* individual execute() calls of prepared statements. This is controlled by
|
||||
* the PDO::ATTR_STATEMENT_CLASS attribute set in the DB class.
|
||||
*/
|
||||
class DBStmtHelper extends \PDOStatement
|
||||
{
|
||||
|
|
@ -27,6 +31,10 @@ class DBStmtHelper extends \PDOStatement
|
|||
/**
|
||||
* Execute a prepared statement.
|
||||
*
|
||||
* We don't set a type for $input_parameters because the original
|
||||
* PDOStatement class accepts both arrays and null. Actually, the null
|
||||
* value must be omitted altogether or it will throw an error.
|
||||
*
|
||||
* @param array $input_parameters
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -39,19 +47,17 @@ class DBStmtHelper extends \PDOStatement
|
|||
{
|
||||
$result = parent::execute($input_parameters);
|
||||
$db_class->clearError();
|
||||
|
||||
$elapsed_time = microtime(true) - $start_time;
|
||||
$db_class->addElapsedTime($elapsed_time);
|
||||
Debug::addQuery($db_class->getQueryLog($this->queryString, $elapsed_time));
|
||||
}
|
||||
catch (\PDOException $e)
|
||||
{
|
||||
$db_class->setError(-1, $e->getMessage());
|
||||
|
||||
throw new DBError($e->getMessage(), 0, $e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
$elapsed_time = microtime(true) - $start_time;
|
||||
$db_class->addElapsedTime($elapsed_time);
|
||||
Debug::addQuery($db_class->getQueryLog($this->queryString, $elapsed_time));
|
||||
throw new DBError($e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue