From 787d9f5d66a54776a90d307b9a26f8876e76fe7d Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Thu, 10 Oct 2019 14:55:41 +0200 Subject: [PATCH] use sqlbuilder in basic --- .../entityfields/info/valueProcess.js | 4 +- .../recordcontainers/jdito/onUpdate.js | 5 +- .../recordcontainers/jdito/contentProcess.js | 68 ++++++++++++------- entity/Person_entity/conditionProcess.js | 11 ++- .../gender/displayValueProcess.js | 12 +--- .../entityfields/gender/valueProcess.js | 14 ++-- .../children/contactid_param/valueProcess.js | 8 ++- .../recordcontainers/db/conditionProcess.js | 11 ++- .../recordcontainers/db/conditionProcess.js | 8 +-- .../excludedproducts_param/valueProcess.js | 2 +- .../recordcontainers/jdito/onDelete.js | 5 +- .../recordcontainers/db/conditionProcess.js | 12 ++-- .../pricelist/displayValueProcess.js | 9 ++- .../product_id/displayValueProcess.js | 7 +- .../recordcontainers/db/conditionProcess.js | 12 ++-- .../recordcontainers/jdito/onInsert.js | 7 +- .../entityfields/my_forecast/valueProcess.js | 21 +++--- .../entityfields/my_turnover/valueProcess.js | 15 ++-- .../overall_forecast/valueProcess.js | 7 +- .../overall_turnover/valueProcess.js | 13 ++-- .../conditionProcess.js | 9 +-- .../recordcontainers/db/conditionProcess.js | 12 ++-- .../conditionProcess.js | 8 +-- .../recordcontainers/db/conditionProcess.js | 7 +- .../entityfields/status/onValueChange.js | 7 +- .../recordcontainers/db/conditionProcess.js | 9 ++- .../recordcontainers/db/onDBDelete.js | 12 ++-- .../recordcontainers/db/onDBUpdate.js | 39 +++++++---- .../recordcontainers/jdito/contentProcess.js | 11 ++- .../recordcontainers/jdito/contentProcess.js | 11 ++- .../serialletter_id/displayValueProcess.js | 11 ++- .../recordcontainers/db/onDBDelete.js | 11 +-- .../recordcontainers/db/onDBUpdate.js | 7 +- .../recordcontainers/db/conditionProcess.js | 9 +-- .../recordcontainers/db/conditionProcess.js | 25 +++---- .../recordcontainers/db/onDBDelete.js | 5 +- .../recordcontainers/db/conditionProcess.js | 9 +-- .../recordcontainers/db/conditionProcess.js | 21 +++--- .../recordcontainers/db/onDBDelete.js | 6 +- .../recordcontainers/db/conditionProcess.js | 9 ++- .../mailastext_param/valueProcess.js | 8 +-- 41 files changed, 254 insertions(+), 243 deletions(-) diff --git a/entity/Classification_entity/entityfields/info/valueProcess.js b/entity/Classification_entity/entityfields/info/valueProcess.js index 3c3dbbfe3ba..681613e42af 100644 --- a/entity/Classification_entity/entityfields/info/valueProcess.js +++ b/entity/Classification_entity/entityfields/info/valueProcess.js @@ -8,8 +8,8 @@ import("Sql_lib"); var data = newSelect("TITLE, SCORE") .from("CLASSIFICATIONSCORE") .orderBy("SORT") - .and("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", "$field.CLASSIFICATIONTYPEID") - .table(); + .whereIfSet("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", "$field.CLASSIFICATIONTYPEID") + .table(true); var resultText = ""; diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js index 105a129772b..91704b45331 100644 --- a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js @@ -19,9 +19,10 @@ var diff = PermissionUtil.getActionDiff(permissionid, actionNew); if (diff.length > 0) { // delete all linked permission actions table = "ASYS_PERMISSIONACTION"; - cond = SqlCondition.begin().and("ASYS_PERMISSION_ID = '" + permissionid + "'").build(); - var dbDeletes = db.deleteData(table, cond, alias); + newWhere("ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID", permissionid, "# = ?", undefined, alias) + .deleteData(true, table); + // insert the different actions cols = db.getColumns(table, alias); for each (var action in actionNew) { diff --git a/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js b/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js index 3e15f2cfb64..ed60fbfacd3 100644 --- a/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("Sql_lib"); import("system.project"); import("system.vars"); @@ -8,8 +9,6 @@ import("Permission_lib"); var res = []; var roleTitle = ""; var entityTitle = ""; -var sqlCond = ""; -var sqlStr = ""; let alias = SqlUtils.getSystemAlias(); var roleInternalEveryone = "INTERNAL_EVERYONE"; @@ -28,40 +27,61 @@ for each (let entityMetaData in entitiesMetaData) { } } -var sqlCondEntityUsePermFlagSet = " and ENTITY_ID in ('" + entitiesUsePermFlagSet.join("','") + "')"; - -if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) { - roleTitle = vars.getString("$param.RoleTitle_param"); - sqlCond = " where ROLE_ID = '" + roleTitle + "'"; - sqlStr = "select distinct ENTITY_ID from ASYS_PERMISSIONSET" + sqlCond + sqlCondEntityUsePermFlagSet; -} else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) { - entityTitle = vars.getString("$param.EntityTitle_param"); - sqlCond = " where ENTITY_ID = '" + entityTitle + "'"; - sqlStr = "select distinct ROLE_ID from ASYS_PERMISSIONSET" + sqlCond + sqlCondEntityUsePermFlagSet; +var rolesOrEntitiesSelect = new SqlBuilder(alias); +var rolesOrEntities = []; +// select nothing if no entities have the perm flag set +if (entitiesUsePermFlagSet.length > 0) +{ + if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) { + roleTitle = vars.getString("$param.RoleTitle_param"); + rolesOrEntitiesSelect.select("distinct ENTITY_ID") + .from("ASYS_PERMISSIONSET") + .where("ASYS_PERMISSIONSET.ROLE_ID", roleTitle) + } + else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) + { + entityTitle = vars.getString("$param.EntityTitle_param"); + rolesOrEntitiesSelect.select("distinct ROLE_ID") + .from("ASYS_PERMISSIONSET") + .where("ASYS_PERMISSIONSET.ENTITY_ID", entityTitle) + } + + rolesOrEntities = rolesOrEntitiesSelect + .and("ASYS_PERMISSIONSET.ENTITY_ID", entitiesUsePermFlagSet, SqlBuilder.IN()) + .arrayColumn(); } -var rolesOrEntities = db.array(db.COLUMN, sqlStr); -var entityPermSetId = ""; + + for each (var entry in rolesOrEntities) { // entry contains either a role or an entity, depending on which param exists if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) { entityPermSetId = PermissionUtil.getSetRoot(roleTitle, entry); } else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) { entityPermSetId = PermissionUtil.getSetRoot(entry, entityTitle); } - var recordPermSetId = db.array(db.COLUMN, SqlCondition.begin().and("ASYS_PERMISSIONSET_ID = '" + entityPermSetId + "'").and("ACCESSTYPE = 'R'") - .buildSql("select ASYS_PERMISSIONSETID from ASYS_PERMISSIONSET"), alias); - var currOverview = [entityPermSetId, entry, "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE"]; - // default entity permissions - currOverview = prepareOverview(entityPermSetId, currOverview, "default"); + if (entityPermSetId) + { + var recordPermSetId = new SqlBuilder(alias) + .select("ASYS_PERMISSIONSETID") + .from("ASYS_PERMISSIONSET") + .where("ASYS_PERMISSIONSET.ASYS_PERMISSIONSET_ID", entityPermSetId) + .and("ACCESSTYPE = 'R'") + .arrayColumn(); + + var currOverview = [entityPermSetId, entry, "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE"]; - // conditional record permissions - currOverview = prepareOverview(recordPermSetId, currOverview, "conditional"); + // default entity permissions + currOverview = prepareOverview(entityPermSetId, currOverview, "default"); - // default record permissions - currOverview = prepareOverview(recordPermSetId, currOverview, "default"); + // conditional record permissions + currOverview = prepareOverview(recordPermSetId, currOverview, "conditional"); - res.push(currOverview); + // default record permissions + currOverview = prepareOverview(recordPermSetId, currOverview, "default"); + + res.push(currOverview); + } } result.object(res); diff --git a/entity/Person_entity/conditionProcess.js b/entity/Person_entity/conditionProcess.js index 61b7bebcb93..788e9d56818 100644 --- a/entity/Person_entity/conditionProcess.js +++ b/entity/Person_entity/conditionProcess.js @@ -1,11 +1,10 @@ -import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("CONTACT.ORGANISATION_ID", "$param.OrgId_param"); -cond.andPrepareVars("PERSON.CONTACT_ID", "$param.ContactId_param"); +var cond = newWhere() + .andIfSet("CONTACT.ORGANISATION_ID", "$param.OrgId_param") + .andIfSet("PERSON.CONTACT_ID", "$param.ContactId_param"); //TODO; add OBJECT_ID (probably another param) -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/Person_entity/entityfields/gender/displayValueProcess.js b/entity/Person_entity/entityfields/gender/displayValueProcess.js index d2680b57571..734a0b1410d 100644 --- a/entity/Person_entity/entityfields/gender/displayValueProcess.js +++ b/entity/Person_entity/entityfields/gender/displayValueProcess.js @@ -1,16 +1,10 @@ import("system.vars"); -import("Keyword_lib"); -import("system.result"); -import("system.db"); -import("system.vars"); -import("system.neon"); -import("Sql_lib"); import("KeywordRegistry_basic"); +import("system.result"); import("Keyword_lib"); +import("Sql_lib"); - -var cond = SqlCondition.begin() -var sex = db.cell(cond.andPrepareVars("SALUTATION.SALUTATION", "$field.SALUTATION").buildSql("select SEX from SALUTATION", "1=2")) +var sex = vars.get("$field.GENDER"); if (sex) { diff --git a/entity/Person_entity/entityfields/gender/valueProcess.js b/entity/Person_entity/entityfields/gender/valueProcess.js index 9d763fea86f..503d28b8f35 100644 --- a/entity/Person_entity/entityfields/gender/valueProcess.js +++ b/entity/Person_entity/entityfields/gender/valueProcess.js @@ -1,11 +1,9 @@ import("system.result"); -import("system.db"); -import("system.vars"); -import("system.neon"); import("Sql_lib"); -var cond = SqlCondition.begin() - -var sex = db.cell(cond.andPrepareVars("SALUTATION.SALUTATION", "$field.SALUTATION").buildSql("select SEX from SALUTATION", "1=2")) - -result.string(sex) \ No newline at end of file +var sex = newSelect("SEX") + .from("SALUTATION") + .whereIfSet("SALUTATION.SALUTATION", "$field.SALUTATION") + .cell(true); +if (sex) + result.string(sex); \ No newline at end of file diff --git a/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js b/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js index 0af516898e0..86fcb7fe922 100644 --- a/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js +++ b/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js @@ -6,7 +6,11 @@ import("Sql_lib"); var orgId = vars.get("$field.ORGANISATION_ID"); if (orgId) { - var cond = SqlCondition.begin().and("CONTACT.PERSON_ID is null").andPrepare("CONTACT.ORGANISATION_ID", orgId); - var orgRelId = db.cell(cond.buildSql("select CONTACT.CONTACTID from CONTACT", "1 = 1")); + var orgRelId = newSelect("CONTACT.CONTACTID") + .from("CONTACT") + .where("CONTACT.PERSON_ID is null") + .and("CONTACT.ORGANISATION_ID", orgId) + .cell(); + result.string(orgRelId); } \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/conditionProcess.js b/entity/Person_entity/recordcontainers/db/conditionProcess.js index 15b9975dc38..8bd62f913cf 100644 --- a/entity/Person_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Person_entity/recordcontainers/db/conditionProcess.js @@ -3,15 +3,14 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("CONTACT.ORGANISATION_ID", "$param.OrgId_param") - .andPrepareVars("PERSON.CONTACT_ID", "$param.ContactId_param"); +var cond = newWhereIfSet("CONTACT.ORGANISATION_ID", "$param.OrgId_param") + .andIfSet("PERSON.CONTACT_ID", "$param.ContactId_param"); if (vars.exists("$param.ExcludedContactIds_param") && vars.get("$param.ExcludedContactIds_param")) { var excludedContacts = JSON.parse(vars.getString("$param.ExcludedContactIds_param")); - cond.andIn("CONTACT.CONTACTID", excludedContacts, undefined, true); + cond.andIfSet("CONTACT.CONTACTID", excludedContacts, SqlBuilder.NOT_IN()); } -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js b/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js index 9164618bf9b..d7230024504 100644 --- a/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js +++ b/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js @@ -3,13 +3,13 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); +var cond = newWhere(); if (vars.get("$param.ExcludedPersonIds_param")) { var excludedPersons = JSON.parse(vars.getString("$param.ExcludedPersonIds_param")); - cond.andIn("PERSON.PERSONID", excludedPersons, undefined, true); + cond.andIfSet("PERSON.PERSONID", excludedPersons, SqlBuilder.NOT_IN()); } -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js index cc6b35783c6..61d089f5dbb 100644 --- a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js +++ b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js @@ -30,7 +30,7 @@ else result.object(excludeIDs); -// TODO: remove code duplication, better param naming and using SqlCondition +// TODO: remove code duplication, better param naming and using SqlBuilder function _getParentID(pID, pIDs) { //Ermitteln welche Produkte ausgeschlossen werden müssen. diff --git a/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js b/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js index 3f5b37d8a09..1c5bf91de89 100644 --- a/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js +++ b/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js @@ -3,9 +3,8 @@ import("system.neon"); import("system.db"); import("Sql_lib"); -db.deleteData("PROD2PROD", SqlCondition.begin() - .andPrepareVars("PROD2PROD.PROD2PRODID", "$field.PROD2PRODID") - .build("1=2")); +newWhereIfSet("PROD2PROD.PROD2PRODID", "$field.PROD2PRODID") + .deleteData(true, "PROD2PROD"); // Refresh otherwise the children of the deleted node would be moved to the root. neon.refresh(); \ No newline at end of file diff --git a/entity/Product_entity/recordcontainers/db/conditionProcess.js b/entity/Product_entity/recordcontainers/db/conditionProcess.js index b0cb4c15622..3602fca8eb0 100644 --- a/entity/Product_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Product_entity/recordcontainers/db/conditionProcess.js @@ -3,17 +3,13 @@ import("system.vars"); import("system.db"); import("Sql_lib"); -var productCond = SqlCondition.begin() +var productCond = newWhere(); if (vars.exists("$param.ExcludedProducts_param") && vars.get("$param.ExcludedProducts_param")) { var excludedIds = JSON.parse(vars.getString("$param.ExcludedProducts_param")); - - excludedIds.forEach(function(pId) - { - this.andPrepare("PRODUCT.PRODUCTID", pId, "# <> ?"); - }, productCond); + productCond.andIfSet("PRODUCT.PRODUCTID", excludedIds, SqlBuilder.NOT_IN()); } -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(productCond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(productCond.toString()); \ No newline at end of file diff --git a/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js b/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js index 7a3a89b39d2..34d03f93063 100644 --- a/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js +++ b/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js @@ -10,9 +10,12 @@ import("KeywordRegistry_basic"); var pricelistname = vars.get("$field.PRICELIST"); if (!pricelistname) { - var preparedStatement = SqlCondition.begin().andPrepare("CONTACT.CONTACTID", vars.get("$field.CONTACT_ID")); - var dbresult = preparedStatement.buildSql("select ORGANISATION.NAME from CONTACT inner join ORGANISATION on CONTACT.ORGANISATION_ID=ORGANISATION.ORGANISATIONID", "1=2", "order by NAME"); - var orgname = db.cell(dbresult); + var orgname = newSelect("ORGANISATION.NAME") + .from("CONTACT") + .join("ORGANISATION", "CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID", undefined, "inner") + .orderBy("NAME") + .where("CONTACT.CONTACTID", "$field.CONTACT_ID") + .cell(true); result.string(orgname); } diff --git a/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js b/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js index 02c9bf53af0..902d8b81e59 100644 --- a/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js +++ b/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js @@ -8,7 +8,8 @@ import("Sql_lib"); if((vars.exists("$param.ProductId_param") && vars.get("$param.ProductId_param") && vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW) { - result.string(db.cell(SqlCondition.begin() - .andPrepareVars("PRODUCT.PRODUCTID", "$field.PRODUCT_ID") - .buildSql("select PRODUCTNAME from PRODUCT", "1=2"))); + result.string(newSelect("PRODUCTNAME") + .from("PRODUCT") + .whereIfSet("$field.PRODUCT_ID") + .cell(true)); } \ No newline at end of file diff --git a/entity/Productprice_entity/recordcontainers/db/conditionProcess.js b/entity/Productprice_entity/recordcontainers/db/conditionProcess.js index 5fce6b87cf7..a68cf9891b4 100644 --- a/entity/Productprice_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Productprice_entity/recordcontainers/db/conditionProcess.js @@ -1,11 +1,9 @@ -import("system.db"); import("system.result"); -import("system.vars"); import("Sql_lib"); -var cond = SqlCondition.begin() - .andPrepareVars("PRODUCTPRICE.PRODUCT_ID", "$param.ProductId_param") - .andPrepareVars("PRODUCTPRICE.CONTACT_ID", "$param.ContactId_param"); +var cond = newWhere() + .andIfSet("PRODUCTPRICE.PRODUCT_ID", "$param.ProductId_param") + .andIfSet("PRODUCTPRICE.CONTACT_ID", "$param.ContactId_param"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js index 15b53f0df14..e0891f1fe60 100644 --- a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js +++ b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js @@ -67,9 +67,10 @@ if (rowdata["LASTNAME.value"]) "USER_NEW", "DATE_NEW" ]; - var gender = db.cell(SqlCondition.begin() - .andPrepareIfSet("SALUTATION.SALUTATION", rowdata["PERSON_SALUTATION.value"]) - .buildSql("select SEX from SALUTATION", "1=2")); + var gender = newSelect("SEX") + .from("SALUTATION") + .whereIfSet("SALUTATION.SALUTATION", rowdata["PERSON_SALUTATION.value"]) + .cell(true); var personVals = [ rowdata["PERSON_ID.value"], diff --git a/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js index 3c50ff040b6..b42db4e92b2 100644 --- a/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js +++ b/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js @@ -1,19 +1,18 @@ -import("Employee_lib"); -import("system.datetime"); -import("system.db"); import("system.result"); +import("system.SQLTYPES"); import("system.vars"); -import("Date_lib"); +import("system.datetime"); import("Sql_lib"); -import("system.SQLTYPES") +import("Employee_lib"); var myContactId = EmployeeUtils.getCurrentContactId(); -var forecast = db.cell(SqlCondition.begin() - .andPrepare("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) - .andPrepare("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject') - .andPrepare("OBJECTMEMBER.CONTACT_ID", myContactId) - .buildSql("select SUM(VOLUME) from OBJECTMEMBER \n\ - left join FORECAST on FORECAST.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and FORECAST.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID", "1=2")); +var forecast = newSelect("SUM(VOLUME)") + .from("OBJECTMEMBER") + .leftJoin("FORECAST", "FORECAST.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and FORECAST.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID") + .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) + .and("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject') + .and("OBJECTMEMBER.CONTACT_ID", myContactId) + .cell(); result.string(forecast); \ No newline at end of file diff --git a/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js index a3c62683acd..46cd9ba9e68 100644 --- a/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js +++ b/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js @@ -11,12 +11,13 @@ import("system.SQLTYPES") var myContactId = EmployeeUtils.getCurrentContactId(); -var turnover = db.cell(SqlCondition.begin() - .andPrepare("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) - .andPrepare("SALESORDER.ORDERTYPE", "ORDTYPEINVO") - .andPrepare("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject') - .andPrepare("OBJECTMEMBER.CONTACT_ID", myContactId) - .buildSql("select sum(NET + VAT) from OBJECTMEMBER \n\ - left join SALESORDER on SALESORDER.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and SALESORDER.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID", "1=2")); +var turnover = newSelect("sum(NET + VAT)") + .from("OBJECTMEMBER") + .leftJoin("SALESORDER", "SALESORDER.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and SALESORDER.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID") + .where("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) + .and("SALESORDER.ORDERTYPE", "ORDTYPEINVO") + .and("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject') + .and("OBJECTMEMBER.CONTACT_ID", myContactId) + .cell(); result.string(turnover); \ No newline at end of file diff --git a/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js index d6f89d038de..11bf47828e5 100644 --- a/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js +++ b/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js @@ -6,8 +6,9 @@ import("Date_lib"); import("Sql_lib"); import("system.SQLTYPES") -var forecast = db.cell(SqlCondition.begin() - .andPrepare("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) - .buildSql("select sum(VOLUME) from FORECAST", "1=2")); +var forecast = newSelect("sum(VOLUME)") + .from("FORECAST") + .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) + .cell(); result.string(forecast); \ No newline at end of file diff --git a/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js index 9c8e5ea68dc..fb9181d479d 100644 --- a/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js +++ b/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js @@ -1,13 +1,12 @@ -import("system.datetime"); -import("system.db"); import("system.result"); +import("system.SQLTYPES"); import("system.vars"); -import("Date_lib"); +import("system.datetime"); import("Sql_lib"); -import("system.SQLTYPES") -var turnover = db.cell(SqlCondition.begin() - .andPrepare("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) - .buildSql("select sum(NET + VAT) from SALESORDER", "1=2")); +var turnover = newSelect("sum(NET + VAT)") + .from("SALESORDER") + .where("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER) + .cell(); result.string(turnover); \ No newline at end of file diff --git a/entity/SalesprojectMilestone_entity/conditionProcess.js b/entity/SalesprojectMilestone_entity/conditionProcess.js index 1d1cfabadaf..300b91638bc 100644 --- a/entity/SalesprojectMilestone_entity/conditionProcess.js +++ b/entity/SalesprojectMilestone_entity/conditionProcess.js @@ -1,10 +1,7 @@ -import("system.db"); import("system.result"); -import("system.vars"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param"); +var cond = newWhereIfSet("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param") -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js b/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js index 66767400e5d..9a21e39ea75 100644 --- a/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js +++ b/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js @@ -1,11 +1,9 @@ -import("system.db"); import("system.result"); -import("system.vars"); import("Sql_lib"); -var cond = SqlCondition.begin() - .andPrepareVars("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param") - .andPrepareVars("SALESPROJECT_MILESTONE.KIND", "$param.Kind_param"); +var cond = newWhere() + .andIfSet("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param") + .andIfSet("SALESPROJECT_MILESTONE.KIND", "$param.Kind_param"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/SalesprojectSource_entity/conditionProcess.js b/entity/SalesprojectSource_entity/conditionProcess.js index 51b6dcc323e..679d08965b0 100644 --- a/entity/SalesprojectSource_entity/conditionProcess.js +++ b/entity/SalesprojectSource_entity/conditionProcess.js @@ -1,9 +1,7 @@ -import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param"); +var cond = newWhereIfSet("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js b/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js index 51b6dcc323e..bad867525a1 100644 --- a/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js +++ b/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js @@ -2,8 +2,7 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param"); +var cond = newWhereIfSet("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/Salesproject_entity/entityfields/status/onValueChange.js b/entity/Salesproject_entity/entityfields/status/onValueChange.js index 28c14cc18d4..732eca9b0e2 100644 --- a/entity/Salesproject_entity/entityfields/status/onValueChange.js +++ b/entity/Salesproject_entity/entityfields/status/onValueChange.js @@ -5,7 +5,8 @@ import("system.db"); if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT) { - vars.set("$context.statusBefore", db.cell(SqlCondition.begin() - .andPrepareVars("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID") - .buildSql("select STATUS from SALESPROJECT", "1=2"))); + vars.set("$context.statusBefore", newSelect("STATUS") + .from("SALESPROJECT") + .whereIfSet("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID") + .cell(true)); } diff --git a/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js b/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js index 758fb672773..507cd54e83a 100644 --- a/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js @@ -3,8 +3,7 @@ import("system.result"); import("system.vars"); import("Sql_lib"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(SqlCondition.begin() - .andPrepareVars("SALESPROJECT.CONTACT_ID", "$param.ContactId_param") - .andPrepareVars("SALESPROJECT.STATUS", "$param.Status_param") - .translate("1 = 1")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(newWhereIfSet("SALESPROJECT.CONTACT_ID", "$param.ContactId_param") + .andIfSet("SALESPROJECT.STATUS", "$param.Status_param") + .toString()); \ No newline at end of file diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js b/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js index 805d98d50d9..081b794d83a 100644 --- a/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js +++ b/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js @@ -12,10 +12,10 @@ if (currentId) "SALESPROJECT_TOUCHPOINT" ]; - toDelete = toDelete.map(function(pTable) { - return [pTable, SqlCondition.equals(pTable + ".SALESPROJECT_ID", currentId, "1=2")]; + var cond = newWhere(pTable + ".SALESPROJECT_ID", currentId) + return [pTable, cond.build()]; }); @@ -29,10 +29,10 @@ if (currentId) toDelete = toDelete.concat(modulesToDelete.map(function(pTableComp) { - return [pTableComp, SqlCondition.begin() - .andPrepare(pTableComp + ".OBJECT_TYPE", ContextUtils.getCurrentContextId()) - .andPrepare(pTableComp + ".OBJECT_ROWID", currentId) - .build("1=2")]; + var cond = newWhere(pTableComp + ".OBJECT_TYPE", ContextUtils.getCurrentContextId()) + .and(pTableComp + ".OBJECT_ROWID", currentId) + + return [pTableComp, cond.build()]; })); diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js index 5cd8bb054ee..062568e3106 100644 --- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js @@ -32,10 +32,10 @@ vars.get("$local.changed").forEach(function(fieldName) { if (state == $KeywordRegistry.salesprojectState$lost()) { // set all offers of the salesproject to lost - db.updateData("OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], SqlCondition.begin() - .andPrepare("OFFER.OBJECT_ROWID", vars.getString("$local.uid")) - .andPrepare("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId()) - .build("1=2")); + newWhere("OFFER.OBJECT_ROWID", "$local.uid") + .and("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId()) + .updateData(true, ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], "OFFER"); + _updateReasons(); clearReason = false; } @@ -43,10 +43,10 @@ vars.get("$local.changed").forEach(function(fieldName) { else if (state == $KeywordRegistry.salesprojectState$order()) { // set all competitions of the salesproject to lost - db.updateData("COMPETITION", ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], SqlCondition.begin() - .andPrepare("COMPETITION.OBJECT_ROWID", vars.getString("$local.uid")) - .andPrepare("COMPETITION.OBJECT_TYPE", ContextUtils.getCurrentContextId()) - .build("1=2")); + newWhere("OFFER.OBJECT_ROWID", "$local.uid") + .and("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId()) + .updateData(true, ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], "COMPETITION"); + _updateReasons(); clearReason = false; } @@ -60,13 +60,16 @@ vars.get("$local.changed").forEach(function(fieldName) { if (!clearForecast) { // reset to value from db - db.updateData("SALESPROJECT", ["STATUS"], null, [vars.get("$context.statusBefore")], SqlCondition.begin() - .andPrepare("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid")) - .build("1=2")); - } else { + newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid")) + .updateData(true, ["STATUS"], null, [vars.get("$context.statusBefore")], "SALESPROJECT"); + } + else + { // do not notify as the user just got a question, if he really would like to clear the forecast + newWhere("FORECAST.OBJECT_ROWID", vars.getString("$local.uid")) + .deleteData(true, "FORECAST"); + needToUpdateForecast = false; - db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"), "1=2")); } } // if state changed, but not to one of the above states @@ -102,11 +105,17 @@ function _updateReasons() { var reasons = rowdata["SALESPROJECT.REASONS"]; if(reasons) - db.updateData("SALESPROJECT", ["REASONS"], null, [reasons], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2")); + { + newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid")) + .updateData(true, ["REASONS"], null, [reasons], "SALESPROJECT"); + } } function _clearReasons(pReallyClear) { if (pReallyClear) - db.updateData("SALESPROJECT", ["REASONS"], null, [""], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2")); + { + newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid")) + .updateData(true, ["REASONS"], null, [""], "SALESPROJECT"); + } } \ No newline at end of file diff --git a/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js b/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js index 2f0c02c1d19..74bdbab553d 100644 --- a/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js @@ -1,9 +1,8 @@ -import("system.vars"); import("system.result"); -import("system.db"); import("Sql_lib"); -result.object(db.table(SqlCondition.begin() - .and("SALUTATION is not NULL") - .andPrepareVars("SALUTATION.ISOLANGUAGE", "$param.Language_param") - .buildSql("select distinct SALUTATION from SALUTATION", "1=1"))); \ No newline at end of file +result.object(newSelect("distinct SALUTATION") + .from("SALUTATION") + .whereIfSet("SALUTATION.ISOLANGUAGE", "$param.Language_param") + .and("SALUTATION is not NULL") + .table()); \ No newline at end of file diff --git a/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js b/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js index 7ed68ef0baa..4ed5169cb77 100644 --- a/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js @@ -1,10 +1,9 @@ -import("system.vars"); import("system.result"); -import("system.db"); import("Sql_lib"); -result.object(db.table(SqlCondition.begin() +result.object(newSelect("distinct TITLE") + .from("SALUTATION") + .whereIfSet("SALUTATION.SALUTATION", "$param.Salutation_param") + .andIfSet("SALUTATION.ISOLANGUAGE", "$param.Language_param") .and("TITLE is not NULL") - .andPrepareVars("SALUTATION.SALUTATION", "$param.Salutation_param") - .andPrepareVars("SALUTATION.ISOLANGUAGE", "$param.Language_param") - .buildSql("select distinct TITLE from SALUTATION", "1=1"))); \ No newline at end of file + .table()); \ No newline at end of file diff --git a/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js b/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js index 5e4cef21d24..a173e1fb24c 100644 --- a/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js +++ b/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js @@ -1,9 +1,14 @@ +import("system.result"); +import("system.result"); import("system.vars"); import("Sql_lib"); -import("system.db"); -import("system.result"); if (vars.get("$this.value")) - result.string(db.cell(SqlCondition.begin().andPrepare("SERIALLETTER.SERIALLETTERID", vars.get("$this.value")).buildSql("select TITLE from SERIALLETTER"))); +{ + result.string(newSelect("TITLE") + .from("SERIALLETTER") + .where("SERIALLETTER.SERIALLETTERID", "$this.value") + .cell()); +} else result.string(""); \ No newline at end of file diff --git a/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js b/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js index d2afc219ad5..f9dfc05aaee 100644 --- a/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js +++ b/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js @@ -2,11 +2,14 @@ import("system.vars"); import("Sql_lib"); import("system.db"); -db.deleteData("LETTERRECIPIENT", SqlCondition.equals("LETTERRECIPIENT.SERIALLETTER_ID", vars.get("$local.uid"), "1=2")); +newWhere("LETTERRECIPIENT.SERIALLETTER_ID", vars.get("$local.uid")) + .deleteData(true, "LETTERRECIPIENT"); + var SYSALIAS = SqlUtils.getBinariesAlias(); -var binaryId = db.cell(SqlCondition.begin(SYSALIAS) - .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid") - .buildSql("select ID from ASYS_BINARIES"), SYSALIAS); +var binaryId = newSelect("ID", SYSALIAS) + .from("ASYS_BINARIES") + .where("ASYS_BINARIES.ROW_ID", "$local.uid") + .cell(true); if (binaryId) db.deleteBinary(binaryId, SYSALIAS); \ No newline at end of file diff --git a/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js b/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js index ca3f5562f8a..ea692573379 100644 --- a/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js @@ -16,9 +16,10 @@ var template = DocumentTemplate.fromUpload(bindata); if (template.content) { let sysAlias = SqlUtils.getBinariesAlias(); - var binaryId = db.cell(SqlCondition.begin(sysAlias) - .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid") - .buildSql("select ID from ASYS_BINARIES", "1=2"), sysAlias); + var binaryId = newSelect("ID", sysAlias) + .from("ASYS_BINARIES") + .where("ASYS_BINARIES.ROW_ID", "$local.uid") + .cell(true); if (binaryId) db.updateBinary(binaryId, "", template.content, template.filename, "", "", sysAlias); diff --git a/entity/Stock_entity/recordcontainers/db/conditionProcess.js b/entity/Stock_entity/recordcontainers/db/conditionProcess.js index c14c6b016ba..eb881a660fe 100644 --- a/entity/Stock_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Stock_entity/recordcontainers/db/conditionProcess.js @@ -1,9 +1,6 @@ import("system.result"); -import("system.vars"); -import("system.db"); import("Sql_lib"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(SqlCondition.begin() - .andPrepareVars("STOCK.PRODUCT_ID", "$param.ProductId_param") - .translate("1 = 0")); +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(newWhereIfSet("STOCK.PRODUCT_ID", "$param.ProductId_param") + .toString()); \ No newline at end of file diff --git a/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js b/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js index 01cc59b4278..05d2e05eca4 100644 --- a/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js +++ b/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js @@ -5,9 +5,9 @@ import("system.result"); import("Sql_lib"); import("KeywordRegistry_basic"); -var cond = new SqlCondition(); -cond.andPrepare("TASK.KIND", $KeywordRegistry.taskType$ticket()) - .andPrepareVars("TICKET.TICKETTYPE", "$param.TicketType_param") +var cond = newWhere() + .and("TASK.KIND", $KeywordRegistry.taskType$ticket()) + .andIfSet("TICKET.TICKETTYPE", "$param.TicketType_param") var loadNothing = false; @@ -15,18 +15,19 @@ if (vars.getString("$param.FilterOnlyOwnTicket_param") == "true") { var ownContactId = EmployeeUtils.getCurrentContactId(); if (ownContactId) - cond.andPrepareIfSet("TASK.EDITOR_CONTACT_ID", ownContactId); + cond.andIfSet("TASK.EDITOR_CONTACT_ID", ownContactId); else loadNothing = true; } -if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param")) +if (vars.get("$param.RowId_param") && vars.get("$param.ObjectId_param")) { - var taskLinkCond = SqlCondition.begin().andPrepareVars("TASKLINK.OBJECT_ROWID", "$param.RowId_param") - .andPrepareVars("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param"); - - // TODO: more performant way than IN. Maybe a join? - cond.and(SqlUtils.translateStatementWithQuotes(taskLinkCond.buildSql("TASK.TASKID in (select TASKLINK.TASK_ID from TASKLINK", "1=2", ")"))) + // TODO: more performant way than IN. Maybe a join? + cond.and("TASK.TASKID", newSelect("TASKLINK.TASK_ID") + .from("TASKLINK") + .where("TASKLINK.OBJECT_ROWID", "$param.RowId_param") + .and("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param") + , SqlBuilder.IN()); } if (loadNothing) @@ -35,6 +36,6 @@ if (loadNothing) } else { - //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 - result.string(cond.translate("1=1")); + //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 + result.string(cond.toString()); } \ No newline at end of file diff --git a/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js b/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js index 0245f4ad4d0..4365c0bbb83 100644 --- a/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js +++ b/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js @@ -2,6 +2,5 @@ import("system.vars"); import("system.db"); import("Sql_lib"); -var condition = SqlCondition.begin() - .andPrepareVars("TASKLINK.TASK_ID", "$field.TASK_TASKID"); -db.deleteData("TASKLINK", condition.build("1=2")); \ No newline at end of file +newWhereIfSet("TASKLINK.TASK_ID", "$field.TASK_TASKID") + .deleteData(true, "TASKLINK"); \ No newline at end of file diff --git a/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js b/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js index 4e718f44637..1b4535c9556 100644 --- a/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js +++ b/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js @@ -1,10 +1,7 @@ -import("system.vars"); -import("system.db"); import("system.result"); import("Sql_lib"); -var cond = SqlCondition.begin() - .andPrepareVars("TASKLINK.TASK_ID", "$param.TaskId_param"); +var cond = newWhereIfSet("TASKLINK.TASK_ID", "$param.TaskId_param"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(cond.translate("1 = 0")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(cond.toString()); \ No newline at end of file diff --git a/entity/Task_entity/recordcontainers/db/conditionProcess.js b/entity/Task_entity/recordcontainers/db/conditionProcess.js index d19dececad6..53cd0f2efc9 100644 --- a/entity/Task_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Task_entity/recordcontainers/db/conditionProcess.js @@ -5,8 +5,7 @@ import("system.result"); import("Sql_lib"); import("KeywordRegistry_basic"); -var cond = new SqlCondition(); -cond.andPrepare("TASK.KIND", $KeywordRegistry.taskType$task()) +var cond = newWhere("TASK.KIND", $KeywordRegistry.taskType$task()) var loadNothing = false; @@ -14,17 +13,18 @@ if (vars.getString("$param.FilterOnlyOwnTask_param") == "true") { var ownContactId = EmployeeUtils.getCurrentContactId(); if (ownContactId) - cond.andPrepareIfSet("TASK.EDITOR_CONTACT_ID", ownContactId); + cond.andIfSet("TASK.EDITOR_CONTACT_ID", ownContactId); else loadNothing = true; } if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param")) { - var activityLinkCond = SqlCondition.begin().andPrepareVars("TASKLINK.OBJECT_ROWID", "$param.RowId_param") - .andPrepareVars("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param"); - - // TODO: more performant way than IN. Maybe a join? - cond.and(SqlUtils.translateStatementWithQuotes(activityLinkCond.buildSql("TASK.TASKID in (select TASKLINK.TASK_ID from TASKLINK", "1=2", ")"))) + // TODO: more performant way than IN. Maybe a join? + cond.and("TASK.TASKID", newSelect("TASKLINK.TASK_ID") + .from("TASKLINK") + .where("TASKLINK.OBJECT_ROWID", "$param.RowId_param") + .and("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param") + , SqlBuilder.IN()); } if (loadNothing) @@ -33,7 +33,6 @@ if (loadNothing) } else { - //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 - var resCond = cond.translate("1=1"); - result.string(resCond); + //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 + result.string(cond.toString()); } \ No newline at end of file diff --git a/entity/Task_entity/recordcontainers/db/onDBDelete.js b/entity/Task_entity/recordcontainers/db/onDBDelete.js index d19d38f6e97..84e02e77b17 100644 --- a/entity/Task_entity/recordcontainers/db/onDBDelete.js +++ b/entity/Task_entity/recordcontainers/db/onDBDelete.js @@ -2,7 +2,5 @@ import("system.vars"); import("system.db"); import("Sql_lib"); -var condition = SqlCondition.begin() - .andPrepareVars("TASKLINK.TASK_ID", "$field.TASKID"); - -db.deleteData("TASKLINK", condition.build("1=2")); \ No newline at end of file +newWhere("TASKLINK.TASK_ID", "$field.TASKID") + .deleteData(true, "TASKLINK"); \ No newline at end of file diff --git a/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js b/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js index 79f47c2f3e1..187f4a3f604 100644 --- a/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js @@ -3,8 +3,7 @@ import("system.db"); import("system.result"); import("Sql_lib"); -//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026 -result.string(SqlCondition.begin() - .andPrepareVars("TIMETRACKING.OBJECT_ID", "$param.ObjectId_param") - .andPrepareVars("TIMETRACKING.ROW_ID", "$param.RowId_param") - .translate("1 = 2")); \ No newline at end of file +//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 +result.string(newWhereIfSet("TIMETRACKING.OBJECT_ID", "$param.ObjectId_param") + .andIfSet("TIMETRACKING.ROW_ID", "$param.RowId_param") + .toString()); \ No newline at end of file diff --git a/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js b/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js index 036eb71d8f5..1e60e708982 100644 --- a/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js +++ b/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js @@ -7,9 +7,9 @@ var res = ""; var unlinkedMailId = vars.get("$param.UnlinkedMailId_param"); if (unlinkedMailId) { - var mailDataSql = SqlCondition.begin() - .andPrepare("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", unlinkedMailId) - .buildSql("select AB_UNLINKEDMAIL.MAIL from AB_UNLINKEDMAIL"); - res = db.cell(mailDataSql); + res = newSelect("AB_UNLINKEDMAIL.MAIL") + .from("AB_UNLINKEDMAIL") + .and("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", unlinkedMailId) + .cell(); } result.string(res); \ No newline at end of file -- GitLab