Piotr Labudda 9 лет назад
Родитель
Сommit
2628019c42
3 измененных файлов с 18 добавлено и 5 удалено
  1. 7 0
      SE/se-lib/Core/Pdo.php
  2. 10 4
      SE/se-lib/DBG.php
  3. 1 1
      SE/se-lib/Route/Debug.php

+ 7 - 0
SE/se-lib/Core/Pdo.php

@@ -416,12 +416,14 @@ EOF_STRUCT_MYSQL;
 	// for sql like `select count() from ...`
 	public function fetchValue($sql) {
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		$sth = $this->query($sql);
 		return $sth->fetchColumn();
 	}
 
 	public function fetchFirst($sql) {// fetch only first row
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		$sth = $this->prepare($sql);
 		$sth->execute();
 		return $sth->fetch();
@@ -429,6 +431,7 @@ EOF_STRUCT_MYSQL;
 
 	public function fetchAll($sql) {
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		$sth = $this->prepare($sql);
 		$sth->execute();
 		return $sth->fetchAll();
@@ -436,6 +439,7 @@ EOF_STRUCT_MYSQL;
 
 	public function fetchAllByKey($sql, $key = 'ID') {
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		$rowsByKey = array();
 		$sth = $this->prepare($sql);
 		$sth->execute();
@@ -510,6 +514,7 @@ EOF_STRUCT_MYSQL;
 				values (" . implode(", ", $sqlValues) . ")
 		";
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		$this->exec($sql);
 		return $this->lastInsertId();
 	}
@@ -534,11 +539,13 @@ EOF_STRUCT_MYSQL;
 			where `{$primaryKeyName}` = {$sqlPrimaryKey}
 		";
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		return $this->exec($sql);
 	}
 
 	public function execSql($sql) {
 		DBG::_('DBG_SQL', '>3', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log($sql, 'sql');
 		return $this->exec($sql);
 	}
 

+ 10 - 4
SE/se-lib/DBG.php

@@ -128,7 +128,7 @@ class DBG {
 	/**
 	 * @param $mixedArg string or Exception
 	 */
-	public static function log($mixedArg) {
+	public static function log($mixedArg, $type = '') {
 		if (!self::isActive()) return;
 		// * TODO: debug to file based on session_id (/tmp/se-debug-{$date("Y-m-d")}-{$login}_{$ip}_{$session_id}.log)
 		$logInfo = [
@@ -148,9 +148,15 @@ class DBG {
 			];
 			$logInfo['trace'] = $mixedArg->getTraceAsString();// getTrace
 		} else if (is_string($mixedArg)) {
-			$logInfo['type'] = 'string';
-			$logInfo['msg'] = $mixedArg;
-			$logInfo['log'] = array();
+			if ('sql' == $type) {
+				$logInfo['type'] = 'sql';
+				$logInfo['msg'] = 'sql';
+				$logInfo['log'] = $mixedArg;
+			} else {
+				$logInfo['type'] = 'string';
+				$logInfo['msg'] = $mixedArg;
+				$logInfo['log'] = '';
+			}
 			ob_start();
 			debug_print_backtrace();
 			$logInfo['trace'] = ob_get_clean();

+ 1 - 1
SE/se-lib/Route/Debug.php

@@ -213,7 +213,7 @@ class Route_Debug extends RouteBase {
             'msg' => $dbg['msg'],
             // 'log' => (!empty($dbg['log'])) ? json_encode($dbg['log']) : '',
             'log' => UI::h('div', [
-                'title' => htmlspecialchars(var_export($dbg['log'], true)),
+                'title' => htmlspecialchars( ('sql' == $dbg['type'] && is_string($dbg['log'])) ? $dbg['log'] : var_export($dbg['log'], true) ),
                 'onClick' => "return p5DBG__showLogTrace(this, event)",
                 'style' => "cursor:pointer"
               ], substr(htmlspecialchars(json_encode($dbg['log'])), 0, 100) . ' ...'