Skip to content
Snippets Groups Projects
Commit bb48638a authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractExceptioin.php: Added row 'Timestamp' - usefull to make correlations to SQL Logfiles.

Constants.php: Added SQL_LOG_MODE_ERROR - used to force logging of failed SQL queries.
Database.php: Removed temorary debugSql output in error messages. Added 'forced' logging of SQL queries if they failed.
parent f4930b0e
No related branches found
No related tags found
No related merge requests found
......@@ -379,6 +379,7 @@ const TOKEN_VALID_LIST = 'sql|head|althead|tail|rbeg|rend|renr|rsep|fbeg|fend|fs
// SQL logging Modes
const SQL_LOG_MODE_ALL = 'all';
const SQL_LOG_MODE_MODIFY = 'modify';
const SQL_LOG_MODE_ERROR = 'error'; // write log entry, independent of global setting (e.g. broken Query)
// api/save.php, api/delete.php, api/load.php
const API_DELETE_PHP = 'delete.php';
......
......@@ -238,7 +238,6 @@ class Database {
$sqlLogMode = $this->isSqlModify($sql) ? SQL_LOG_MODE_MODIFY : SQL_LOG_MODE_ALL;;
$result = 0;
$stat = array();
$debugSql = '';
$this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
$this->store->setVar(SYSTEM_SQL_PARAM_ARRAY, $parameterArray, STORE_SYSTEM);
......@@ -246,26 +245,21 @@ class Database {
// Logfile
$this->dbLog($sqlLogMode, $sql, $parameterArray);
// If BE User is logged in: report the broken SQL as well.
//TODO: im Fall von delete.php, save.php, kann hier der BE_USER nicht abgefragt werden (laeuft nicht durch T3) - Loesung finden.
if (true) {
$debugSql = '[' . $sql . ']';
}
if (false === ($this->mysqli_stmt = $this->mysqli->prepare($sql))) {
throw new DbException('[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error . $debugSql, ERROR_DB_PREPARE);
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
throw new DbException('[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error, ERROR_DB_PREPARE);
}
if (count($parameterArray) > 0) {
if (false === $this->prepareBindParam($parameterArray)) {
throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $debugSql, ERROR_DB_BIND);
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error, ERROR_DB_BIND);
}
}
if (false === $this->mysqli_stmt->execute()) {
throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $debugSql, ERROR_DB_EXECUTE);
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error, ERROR_DB_EXECUTE);
}
$msg = '';
......@@ -351,6 +345,8 @@ class Database {
*/
private function dbLog($mode = SQL_LOG_MODE_ALL, $sql = '', $parameterArray = array()) {
$status = '';
$sqlLogMode = $this->store->getVar(SYSTEM_SQL_LOG_MODE, STORE_SYSTEM);
switch ($mode) {
......@@ -363,6 +359,9 @@ class Database {
case SQL_LOG_MODE_MODIFY:
break;
case SQL_LOG_MODE_ERROR:
break;
default:
throw new UserFormException("Unknown SQL_LOG_MODE: $mode", ERROR_UNKNOWN_SQL_LOG_MODE);
}
......@@ -382,7 +381,10 @@ class Database {
}
if ($sql !== '') {
$msg .= '[' . $sql . ']';
if ($mode == SQL_LOG_MODE_ERROR) {
$status = 'FAILED: ';
}
$msg .= '[' . $status . $sql . ']';
}
Logger::logMessage($msg, $this->sqlLog);
......
......@@ -39,7 +39,7 @@ class AbstractException extends \Exception {
$this->messageArray['Line'] = $this->getLine();
$this->messageArray['Message'] = $this->getMessage();
$this->messageArray['Code'] = $this->getCode();
$this->messageArray['Timestamp'] = date('Y.m.d H:i:s O');
$this->messageArray['Stacktrace'] = '<pre>' . $this->getTraceAsString() . '</pre>';
if ($store !== null) {
$this->messageArray['Page Id'] = $store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment