From d01d408a72b024f3ba08dcbd3320893dea946166 Mon Sep 17 00:00:00 2001
From: Sebastian Listl <s.listl@adito.de>
Date: Fri, 4 Dec 2020 11:35:23 +0100
Subject: [PATCH] SqlBuilder only add 'from' when there is a select-part

---
 process/Sql_lib/process.js | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js
index d4d8afdaa40..52a7aac39ba 100644
--- a/process/Sql_lib/process.js
+++ b/process/Sql_lib/process.js
@@ -1054,7 +1054,7 @@ SqlBuilder.prototype.tableName = function (pTable)
  */
 SqlBuilder.prototype.from = function(pTable, pTableAlias)
 {
-    this._from = SqlBuilder._getStatement(pTable, "from", pTableAlias, false, (pTableAlias ? false : true));
+    this._from = SqlBuilder._getStatement(pTable, "", pTableAlias, false, (pTableAlias ? false : true));
     if (typeof(pTable) === "string")
         this._tableName = pTable;
     return this;
@@ -2193,10 +2193,7 @@ SqlBuilder.prototype.whereWasCalled = function() {
  */
 SqlBuilder.prototype.isFullSelect = function() 
 {
-    if (!this._select || !this._from)
-        return false;
-    
-    return true;
+    return !(!this._select || !this._from);
 }
 
 /**
@@ -2375,9 +2372,14 @@ SqlBuilder.prototype.buildCondition = function()
 SqlBuilder.prototype.build = function(pDefaultConditionIfNone)
 {
     var wherePrefix = "";
+    var fromObj = this._from;
     
     if (this.isFullSelect())
     {
+        fromObj = {
+            sqlStorage: "from " + this._from.sqlStorage,
+            preparedValues: this._from.preparedValues
+        };
         if (this._where.sqlStorage)
             wherePrefix = "where ";
     }
@@ -2390,11 +2392,11 @@ SqlBuilder.prototype.build = function(pDefaultConditionIfNone)
     var whereObj = {
         sqlStorage : wherePrefix + whereSql,
         preparedValues : this._where.preparedValues
-    }
+    };
     
     var allParts = [
         this._select,
-        this._from,
+        fromObj
         ].concat(this._joins).concat([
         whereObj,
         this._groupBy,
-- 
GitLab