From de8e0783d54cfa71d051e262805b36c7b669bdd0 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Tue, 31 Jan 2017 23:03:57 +0100
Subject: [PATCH] Database.php: In case of broken SQL queries, print them in
 ajax error message.

---
 extension/qfq/qfq/Database.php | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/extension/qfq/qfq/Database.php b/extension/qfq/qfq/Database.php
index 53e9e11d2..6294700ae 100644
--- a/extension/qfq/qfq/Database.php
+++ b/extension/qfq/qfq/Database.php
@@ -238,6 +238,7 @@ 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);
@@ -245,18 +246,26 @@ 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, ERROR_DB_PREPARE);
+            throw new DbException('[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error . $debugSql, ERROR_DB_PREPARE);
         }
 
         if (count($parameterArray) > 0) {
             if (false === $this->prepareBindParam($parameterArray)) {
-                throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error, ERROR_DB_BIND);
+                throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $debugSql, ERROR_DB_BIND);
             }
         }
 
         if (false === $this->mysqli_stmt->execute()) {
-            throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error, ERROR_DB_EXECUTE);
+            throw new DbException('[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $debugSql, ERROR_DB_EXECUTE);
         }
 
         $msg = '';
-- 
GitLab