Compare commits

...

18 Commits
1.1.0 ... 1.2.0

Author SHA1 Message Date
Daniel Seifert 07fcca498d
remove Query Status Monitor, complete implementation 2020-05-01 01:08:23 +02:00
Daniel Seifert c3aa93e543
disable linking smarty plugin 2020-05-01 00:29:56 +02:00
Daniel Seifert 054ccd8419
Merge remote-tracking branch 'upstream/master' 2020-05-01 00:13:59 +02:00
Daniel Seifert 8df59407d9
add SQL formatter 2020-04-30 20:45:41 +02:00
Tobias Matthaiou 40012ba334 Suitable screenshot 2019-11-06 15:10:45 +01:00
Tobias Matthaiou b606986b86
Update CHANGELOG.md 2019-11-06 15:05:36 +01:00
Tobias Matthaiou e57e3fe934
Merge pull request #2 from TumTum/feature/sql-status
Feature/sql status
2019-11-06 15:03:02 +01:00
Tobias Matthaiou e0bd400107 Documentation to SQL Status Query Monitor 2019-11-06 15:00:55 +01:00
Tobias Matthaiou 7e6687132c Status display of the DB how many queries were processed. (SHOW STATUS) 2019-11-06 14:44:58 +01:00
Tobias Matthaiou 2410dc3203
Update README.md 2019-10-04 10:15:41 +02:00
Tobias Matthaiou e3623e4bd4
Update CHANGELOG.md 2019-10-01 16:17:07 +02:00
Tobias Matthaiou 466bb61afc
Merge pull request #1 from TumTum/feature/measures_time
Feature/measures time
2019-10-01 12:58:50 +02:00
Tobias Matthaiou 5fd1cf0b81 Updated documentation 2019-10-01 12:55:33 +02:00
Tobias Matthaiou 2488b19301 Activate Travis 2019-10-01 12:30:25 +02:00
Tobias Matthaiou 9c3206ee73 New Featuer: "Measures the sql execution time" 2019-10-01 12:23:02 +02:00
Tobias Matthaiou 5de9a138f8 Insert PHPSpec Framework 2019-10-01 12:22:43 +02:00
Daniel Seifert b58b674c3a add credits 2019-09-23 08:45:00 +02:00
Daniel Seifert 7da3397db4 fix README images url 2019-09-23 08:38:19 +02:00
5 changed files with 304 additions and 19 deletions

View File

@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
---
## [1.2.0] - 2020-04-30
### Added
- Format SQL query
- Measures the SQL execution time
---
## [1.1.0] - 2019-09-20
### Added
@ -13,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add log message
- add position specifications of the calling source code
---
## [1.0.0] - 2019-07-21
available in tumtum/oxid-sql-logger package only

View File

@ -24,9 +24,12 @@ $list = $db->getAll('SELECT * FROM oxarticles WHERE oxprice < ? LIMIT 100', [49.
Browser:
![Example all sqls](https://raw.githubusercontent.com/TumTum/oxid-sql-logger/master/img/screenshot-a.jpg)
![Example all sqls](https://raw.githubusercontent.com/d3datadevelopment/oxid-sql-logger/master/img/screenshot-a.jpg)
CLI:
![Example CLI](https://raw.githubusercontent.com/TumTum/oxid-sql-logger/master/img/screenshot-cli.jpg)
![Example CLI](https://raw.githubusercontent.com/d3datadevelopment/oxid-sql-logger/master/img/screenshot-cli.jpg)
## Credits
Many thanks to [Tobias Matthaiou](https://github.com/TumTum/oxid-sql-logger) for his inspiration.

View File

@ -3,16 +3,14 @@
"description": "Returns all SQL queries in the browser.",
"type": "library",
"require": {
"monolog/monolog": "^1"
"monolog/monolog": "^1",
"nilportugues/sql-query-formatter": "^1.2.2"
},
"license": "GPL-3.0",
"autoload": {
"psr-4": {
"D3\\OxidSqlLogger\\": "./src"
},
"files": [
"./src/functions.php"
]
}
},
"authors": [
{

View File

@ -9,6 +9,7 @@ namespace D3\OxidSqlLogger;
use Doctrine\DBAL\Logging\SQLLogger;
use Monolog;
use NilPortugues\Sql\QueryFormatter\Formatter;
/**
* Class OxidSQLLogger
@ -21,6 +22,11 @@ class OxidSQLLogger implements SQLLogger
public $logStartingClass;
public $logStartingFunction;
/**
* @var SQLQuery
*/
private $SQLQuery = null;
/**
* @inheritDoc
*/
@ -42,19 +48,18 @@ class OxidSQLLogger implements SQLLogger
*/
public function startQuery($sql, array $params = null, array $types = null)
{
Monolog\Registry::sql()->addDebug(
$this->message ? $this->message : $sql,
[
'query' => $sql,
'params' => $params,
'types' => $types,
'logStartingFile' => $this->logStartingFile,
'logStartingLine' => $this->logStartingLine,
'logStartingClass' => $this->logStartingClass,
'logStartingFunction' => $this->logStartingFunction,
if ($this->SQLQuery) {
$this->SQLQuery->setCanceled();
$this->stopQuery();
}
]
);
$this->SQLQuery = (new SQLQuery()) ->setSql($sql)
->setParams($params)
->setTypes($types)
->setLogStartingFile($this->logStartingFile)
->setLogStartingLine($this->logStartingLine)
->setLogStartingClass($this->logStartingClass)
->setLogStartingFunction($this->logStartingFunction);
}
/**
@ -62,5 +67,24 @@ class OxidSQLLogger implements SQLLogger
*/
public function stopQuery()
{
if ($this->SQLQuery) {
$formatter = new Formatter();
Monolog\Registry::sql()->addDebug(
'['.$this->SQLQuery->getReadableElapsedTime().'] ' . ( $this->message ? $this->message : $this->SQLQuery->getSql() ),
[
'query' => $formatter->format($this->SQLQuery->getSql()),
'params' => $this->SQLQuery->getParams(),
'time' => $this->SQLQuery->getElapsedTime(),
'types' => $this->SQLQuery->getTypes(),
'logStartingFile' => $this->SQLQuery->getLogStartingFile(),
'logStartingLine' => $this->SQLQuery->getLogStartingLine(),
'logStartingClass' => $this->SQLQuery->getLogStartingClass(),
'logStartingFunction' => $this->SQLQuery->getLogStartingFunction(),
]
);
}
$this->SQLQuery = null;
}
}

247
src/SQLQuery.php Normal file
View File

@ -0,0 +1,247 @@
<?php
/**
* Autor: Tobias Matthaiou <developer@tobimat.eu>
* Date: 2019-08-20
* Time: 21:56
*/
namespace D3\OxidSqlLogger;
/**
* Class SQLQuery
* @package tm\oxid\sql\logger
*/
class SQLQuery
{
/**
* @var float|null
*/
private $start_time = null;
/**
* @var float|null
*/
private $stop_time = null;
/**
* @var string
*/
private $sql = '';
/**
* @var null
*/
private $params = null;
/**
* @var null
*/
private $types = null;
private $logStartingFile;
private $logStartingLine;
private $logStartingClass;
private $logStartingFunction;
/**
* @inheritDoc
*/
public function __construct()
{
$this->start_time = microtime(true);
}
/**
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* @param string $sql
* @return SQLQuery
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* @return null
*/
public function getParams()
{
return $this->params;
}
/**
* @param null $params
* @return SQLQuery
*/
public function setParams($params)
{
$this->params = $params;
return $this;
}
/**
* @return null
*/
public function getTypes()
{
return $this->types;
}
/**
* @param null $types
* @return SQLQuery
*/
public function setTypes($types)
{
$this->types = $types;
return $this;
}
/**
* @return string
*/
public function getLogStartingFile()
{
return $this->logStartingFile;
}
/**
* @param $file
* @return SQLQuery
*/
public function setLogStartingFile($file)
{
$this->logStartingFile = $file;
return $this;
}
/**
* @return string
*/
public function getLogStartingLine()
{
return $this->logStartingLine;
}
/**
* @param $line
* @return SQLQuery
*/
public function setLogStartingLine($line)
{
$this->logStartingLine = $line;
return $this;
}
/**
* @return string
*/
public function getLogStartingClass()
{
return $this->logStartingClass;
}
/**
* @param $classname
* @return SQLQuery
*/
public function setLogStartingClass($classname)
{
$this->logStartingClass = $classname;
return $this;
}
/**
* @return string
*/
public function getLogStartingFunction()
{
return $this->logStartingFunction;
}
/**
* @param $functionname
* @return SQLQuery
*/
public function setLogStartingFunction($functionname)
{
$this->logStartingFunction = $functionname;
return $this;
}
/**
* Statement was cancelled prematurely, an error was thrown.
*
* @return $this
*/
public function setCanceled()
{
$this->start_time = null;
return $this;
}
/**
* Returns elapsed time
* @return float|string
*/
public function getElapsedTime()
{
if ($this->start_time === null) {
return 'Statement canceled';
}
if ($this->stop_time === null) {
$end_time = microtime(true);
$this->stop_time = $end_time - $this->start_time;
}
return (float)$this->stop_time;
}
/**
* Returns a human readable elapsed time
*
* @return string
*/
public function getReadableElapsedTime()
{
return $this->readableElapsedTime($this->getElapsedTime());
}
/**
* Returns a human readable elapsed time
*
* @param float $microtime
* @param string $format The format to display (printf format)
* @return string
*/
private function readableElapsedTime($microtime, $format = '%.3f%s', $round = 3)
{
if (is_string($microtime)) {
return $microtime;
}
if ($microtime >= 1) {
$unit = 's';
$time = round($microtime, $round);
} else {
$unit = 'ms';
$time = round($microtime*1000);
$format = preg_replace('/(%.[\d]+f)/', '%d', $format);
}
return sprintf($format, $time, $unit);
}
}