From a66e7706bfdc489dfcad73222bf6e9f5bd7ffcb6 Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Thu, 10 Oct 2019 11:48:37 +0200 Subject: [PATCH] use sql builder in basic --- .../recordcontainers/db/conditionProcess.js | 2 +- .../recordcontainers/db/conditionProcess.js | 5 +- .../children/removeusage/onActionProcess.js | 7 +-- .../usagecount_param/valueProcess.js | 11 +++-- .../recordcontainers/jdito/onDelete.js | 10 ++-- .../recordcontainers/jdito/onUpdate.js | 11 +++-- .../excludedobjectids_param/valueProcess.js | 27 ++++++----- .../recordcontainers/jdito/contentProcess.js | 47 ++++++++++--------- .../recordcontainers/jdito/onDelete.js | 5 +- .../recordcontainers/jdito/onUpdate.js | 6 +-- entity/Offer_entity/conditionProcess.js | 7 ++- .../entityfields/contact_id/onValueChange.js | 7 +-- .../entityfields/contact_id/valueProcess.js | 7 +-- .../entityfields/footer/valueProcess.js | 10 ++-- .../entityfields/header/valueProcess.js | 11 +++-- .../isolanguage/displayValueProcess.js | 12 ++--- .../entityfields/printoffer/stateProcess.js | 7 +-- entity/Offer_entity/onDBDelete.js | 3 +- .../recordcontainers/db/conditionProcess.js | 14 +++--- .../recordcontainers/db/onDBDelete.js | 3 +- .../entityfields/price/displayValueProcess.js | 7 +-- .../entityfields/product_id/onValueChange.js | 11 +++-- .../totalprice/displayValueProcess.js | 7 +-- .../recordcontainers/db/conditionProcess.js | 7 ++- .../recordcontainers/db/onDBDelete.js | 5 +- .../recordcontainers/db/onDBInsert.js | 4 +- .../recordcontainers/db/onDBUpdate.js | 3 +- .../entityfields/cancel/onActionProcess.js | 6 +-- .../entityfields/cancel/stateProcess.js | 7 +-- process/Sql_lib/process.js | 4 +- 30 files changed, 148 insertions(+), 125 deletions(-) diff --git a/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js b/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js index 88680ac2a0..174ad7f6d1 100644 --- a/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js +++ b/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js @@ -3,7 +3,7 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = newWhere("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param"); +var cond = newWhereIfSet("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param"); //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/KeywordEntry_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js index bc4bb6f2e2..ba9d5cc9a9 100644 --- a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js +++ b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js @@ -10,7 +10,10 @@ if (vars.get("$param.OnlyActives_param") == "true") cond.and("AB_KEYWORD_ENTRY.ISACTIVE", "1"); } -cond.andIfSet("AB_KEYWORD_ENTRY.KEYID", newWhere(vars.get("$param.ExcludedKeyIdsSubquery_param")), SqlBuilder.NOT_IN()) +if (vars.get("$param.ExcludedKeyIdsSubquery_param")) +{ + cond.and("AB_KEYWORD_ENTRY.KEYID not in ( " + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")"); +} if (vars.getString("$param.WhitelistIds_param")) cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN()); diff --git a/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js b/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js index 7de1f5f6cb..95f3d3d8c2 100644 --- a/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js +++ b/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js @@ -6,9 +6,10 @@ import("Sql_lib"); if (vars.get("$field.UID") && vars.get("$field.DEST_OBJECTRELATIONTYPEID")) { - db.deleteData("AB_OBJECTRELATION", SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID") - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID").build("1=2")); + newWhere("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID") + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID") + .deleteData(true, "AB_OBJECTRELATION"); + question.showMessage(translate.withArguments("Deleted all usages of \"%0\".", [translate.text(vars.get("$field.SOURCE_RELATION_TITLE")) + " -> " + translate.text(vars.get("$field.DEST_RELATION_TITLE"))]), question.INFORMATION, translate.text("Successful")) } diff --git a/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js b/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js index 2ea7aca898..6887bcbe34 100644 --- a/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js +++ b/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js @@ -1,8 +1,11 @@ +import("system.vars"); +import("system.logging"); import("Sql_lib"); import("system.db"); import("system.result"); -result.object(db.cell(SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID") - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID") - .buildSql("select count(*) from AB_OBJECTRELATION", "1=2"))); \ No newline at end of file +result.object(newSelect("count(*)") + .from("AB_OBJECTRELATION") + .whereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID") + .andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID") + .cell(true, "0")); \ No newline at end of file diff --git a/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js b/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js index 19d5361663..1a417b248a 100644 --- a/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js +++ b/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js @@ -4,16 +4,12 @@ import("system.translate"); import("system.question"); import("Sql_lib"); -var usageCount = db.cell(SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID") - .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID") - .buildSql("select count(*) from AB_OBJECTRELATION", "1=2")) +var usageCount = vars.get("$param.UsageCount_param"); if (usageCount <= 0) { - db.deleteData("AB_OBJECTRELATIONTYPE", SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE") - .build("1=2")); + newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE") + .deleteData(true, "AB_OBJECTRELATIONTYPE"); } else { diff --git a/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js b/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js index 7aa7d08ec6..2ebed77387 100644 --- a/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js @@ -30,10 +30,13 @@ vars.get("local.changed").forEach(function(pChange) }); var updates = []; -var type1Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE")) - .andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "1").build("1=2"); -var type2Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE")) - .andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "2").build("1=2"); +var type1Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE")) + .and("AB_OBJECTRELATIONTYPE.SIDE", "1") + .build(); + +var type2Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE")) + .and("AB_OBJECTRELATIONTYPE.SIDE", "2") + .build(); for (let field in type1Fields) { updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type1Fields[field]], type1Cond]); diff --git a/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js b/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js index afff3a5327..e5bc0159b0 100644 --- a/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js +++ b/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("Sql_lib"); import("system.vars"); import("system.result"); @@ -6,16 +7,16 @@ import("ObjectRelation_lib"); var relationTypeData = ObjectRelationUtils.getRelationType(vars.get("$field.OBJECTRELATIONTYPEID")); -var sql1 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID") - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7]) - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8]) - .buildSql("select OBJECT2_ROWID from AB_OBJECTRELATION", "1=2")); - -var sql2 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin() - .andPrepareVars("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID") - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7]) - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8]) - .buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2")); - -result.object([vars.get("$field.PARENT_ID")].concat(db.array(db.COLUMN, sql1 + " union " + sql2))); \ No newline at end of file +var ids = newSelect("OBJECT2_ROWID") + .from("AB_OBJECTRELATION") + .whereIfSet("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID") + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7]) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8]) + .union(newSelect("OBJECT1_ROWID") + .from("AB_OBJECTRELATION") + .whereIfSet("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID") + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7]) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])) + .arrayColumn(); + +result.object([vars.get("$field.PARENT_ID")].concat(ids)); \ No newline at end of file diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js index 19ada03287..f916905b88 100644 --- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js @@ -1,3 +1,4 @@ +import("system.logging"); import("system.db"); import("system.translate"); import("system.result"); @@ -276,10 +277,10 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP { if (pRelationType1 == undefined || pRelationType2 == undefined) return []; - + var myNum; var otherNum; - + if (pDirection == "normal") { otherNum = 1; @@ -291,27 +292,30 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP myNum = 1; } - var cond = SqlCondition.begin() - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1) - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2) - .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId) - .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId); + onConditionForRelationTypeJoin = newWhere("AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2) + .and("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId) + // set id to null, as only null works with .andIfSet + .andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", (pObjectRelationId ? pObjectRelationId : null)); // exclude previous node if (!pPrevId) - cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null"); + onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null"); else { - cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?"); + onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?"); } - + // TODO: BINDATA? // var image = getImageObject("Beziehung"); - var data = db.table(cond.buildSql( - "select OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID \n\ - from AB_OBJECTRELATION \n\ - join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false)); - + var data = newSelect("OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID") + .from("AB_OBJECTRELATION") + .join("AB_OBJECTRELATIONTYPE", onConditionForRelationTypeJoin) + .table(); + + + // try again with other side for "same" if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][ENTRY_DATA.objectId]) { @@ -379,13 +383,14 @@ function _getRootID(pObjectId, pObjectRelationTypeData) { var rootid = sourceid; max--; - sourceid = db.cell(SqlCondition.begin() - .andPrepare("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid) - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7]) - .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8]) - .buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2")) + sourceid = newSelect("OBJECT1_ROWID") + .from("AB_OBJECTRELATION") + .where("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7]) + .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8]) + .cell() } - while( sourceid != "" && max > 0 ); + while(sourceid != "" && max > 0); return rootid; return currentObjectId; } \ No newline at end of file diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js index fc1ca5187e..0271d85e78 100644 --- a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js +++ b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js @@ -10,9 +10,8 @@ var isObjectRelationNode = typeof uid[2] == "string"; if (isObjectRelationNode) { var objectRelationId = uid[6]; - db.deleteData("AB_OBJECTRELATION", SqlCondition.begin() - .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId) - .build("1=2")); + newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId) + .deleteData(true, "AB_OBJECTRELATION"); // Refresh otherwise the children of the deleted node would be moved to the root. neon.refresh(); diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js index c62d01d48d..9356ec327a 100644 --- a/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js @@ -11,8 +11,6 @@ if (isObjectRelationNode) { var objectRelationId = uid[6]; - db.updateData("AB_OBJECTRELATION", ["INFO"], null, [vars.get("$field.INFO")], - SqlCondition.begin() - .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId) - .build("1=2")); + newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId) + .updateData(true, ["INFO"], null, [vars.get("$field.INFO")], "AB_OBJECTRELATION"); } diff --git a/entity/Offer_entity/conditionProcess.js b/entity/Offer_entity/conditionProcess.js index 06d75b37a1..1fb5c50e9a 100644 --- a/entity/Offer_entity/conditionProcess.js +++ b/entity/Offer_entity/conditionProcess.js @@ -2,8 +2,7 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); -cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param"); +var cond = newWhereIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_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/Offer_entity/entityfields/contact_id/onValueChange.js b/entity/Offer_entity/entityfields/contact_id/onValueChange.js index 15006677e0..4d3ecbb18e 100644 --- a/entity/Offer_entity/entityfields/contact_id/onValueChange.js +++ b/entity/Offer_entity/entityfields/contact_id/onValueChange.js @@ -10,9 +10,10 @@ var contactid = vars.get("local.value"); if(contactid != "") { //Language Preset - var lang = db.cell(SqlCondition.begin() - .andPrepare("CONTACT.CONTACTID", contactid) - .buildSql("select ISOLANGUAGE from CONTACT")); + var lang = newSelect("ISOLANGUAGE") + .from("CONTACT") + .where("CONTACT.CONTACTID", contactid) + .cell(); if(lang != "") neon.setFieldValue("field.ISOLANGUAGE", lang); diff --git a/entity/Offer_entity/entityfields/contact_id/valueProcess.js b/entity/Offer_entity/entityfields/contact_id/valueProcess.js index de0433be91..c50907d05b 100644 --- a/entity/Offer_entity/entityfields/contact_id/valueProcess.js +++ b/entity/Offer_entity/entityfields/contact_id/valueProcess.js @@ -20,9 +20,10 @@ if ((!vars.exists("$param.ContactId_param") || !vars.get("$param.ContactId_param if (contactId) { - var lang = db.cell(SqlCondition.begin() - .andPrepare("CONTACT.CONTACTID", contactId) - .buildSql("select ISOLANGUAGE from CONTACT")); + var lang = newSelect("ISOLANGUAGE") + .from("CONTACT") + .where("CONTACT.CONTACTID", contactId) + .cell(); if(lang != "") neon.setFieldValue("field.ISOLANGUAGE", lang); diff --git a/entity/Offer_entity/entityfields/footer/valueProcess.js b/entity/Offer_entity/entityfields/footer/valueProcess.js index 15f63197dc..c7d13ea380 100644 --- a/entity/Offer_entity/entityfields/footer/valueProcess.js +++ b/entity/Offer_entity/entityfields/footer/valueProcess.js @@ -16,8 +16,10 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) if (vars.get("$field.ChoosenTEXFooter") != "") { - var binaryId = db.cell(SqlCondition.begin() - .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter") - .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias()); - result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias()))); + var binaryId = newSelect("ID", SqlUtils.getBinariesAlias()) + .from("ASYS_BINARIES") + .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter") + .cell(true); + if (binaryId) + result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias()))); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/header/valueProcess.js b/entity/Offer_entity/entityfields/header/valueProcess.js index a06ff095b1..65ab407aa9 100644 --- a/entity/Offer_entity/entityfields/header/valueProcess.js +++ b/entity/Offer_entity/entityfields/header/valueProcess.js @@ -16,8 +16,11 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) if (vars.get("$field.ChoosenTEXHeader") != "") { - var binaryId = db.cell(SqlCondition.begin() - .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader") - .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias()); - result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias()))); + var binaryId = newSelect("ID", SqlUtils.getBinariesAlias()) + .from("ASYS_BINARIES") + .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader") + .cell(true); + + if (binaryId) + result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias()))); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js b/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js index 0a2a0ee65d..bb31cb49de 100644 --- a/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js +++ b/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js @@ -4,9 +4,9 @@ import("system.result"); import("system.vars"); import("Sql_lib"); -var iso3 = vars.get("$field.ISOLANGUAGE"); -var latinName = db.cell(SqlCondition.begin() - .andPrepare("AB_LANGUAGE.ISO3", iso3) - .buildSql("select NAME_LATIN from AB_LANGUAGE", "1=0")); -latinName = translate.text(latinName); -result.string(latinName); +var latinName = newSelect("NAME_LATIN") + .from("AB_LANGUAGE") + .where("AB_LANGUAGE.ISO3", "$field.ISOLANGUAGE") + .cell(); + +result.string(translate.text(latinName)); diff --git a/entity/Offer_entity/entityfields/printoffer/stateProcess.js b/entity/Offer_entity/entityfields/printoffer/stateProcess.js index bb8a76fc63..bf47a920e1 100644 --- a/entity/Offer_entity/entityfields/printoffer/stateProcess.js +++ b/entity/Offer_entity/entityfields/printoffer/stateProcess.js @@ -3,9 +3,10 @@ import("system.db"); import("Sql_lib"); import("system.neon"); -var itemcount = db.cell(SqlCondition.begin() - .andPrepareVars("OFFERITEM.OFFER_ID", "$field.OFFERID") - .buildSql("select count(*) from OFFERITEM", "1=2")); +var itemcount = newSelect("count(*)") + .from("OFFERITEM") + .whereIfSet("OFFERITEM.OFFER_ID", "$field.OFFERID") + .cell(true, "0"); if(itemcount == "0") result.string(neon.COMPONENTSTATE_DISABLED); diff --git a/entity/Offer_entity/onDBDelete.js b/entity/Offer_entity/onDBDelete.js index 5c36082b96..066cc33ad0 100644 --- a/entity/Offer_entity/onDBDelete.js +++ b/entity/Offer_entity/onDBDelete.js @@ -2,4 +2,5 @@ import("Sql_lib"); import("system.vars"); import("system.db"); -db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2")); \ No newline at end of file +newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID") + .deleteData(true, "OFFERITEM"); \ No newline at end of file diff --git a/entity/Offer_entity/recordcontainers/db/conditionProcess.js b/entity/Offer_entity/recordcontainers/db/conditionProcess.js index e9466d0d8a..001612ec19 100644 --- a/entity/Offer_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Offer_entity/recordcontainers/db/conditionProcess.js @@ -3,16 +3,16 @@ import("system.db"); import("system.result"); import("Sql_lib"); -var cond = new SqlCondition(); +var cond = newWhere() if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param")) - cond.andPrepareVars("OFFER.CONTACT_ID", "$param.ContactId_param"); + cond.andIfSet("OFFER.CONTACT_ID", "$param.ContactId_param"); else { - cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param"); - cond.andPrepareVars("OFFER.OBJECT_TYPE", "$param.ObjectType_param"); + cond.andIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param"); + cond.andIfSet("OFFER.OBJECT_TYPE", "$param.ObjectType_param"); } -cond.andPrepareVars("OFFER.STATUS", "$param.OfferStatus_param") +cond.andIfSet("OFFER.STATUS", "$param.OfferStatus_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/Offer_entity/recordcontainers/db/onDBDelete.js b/entity/Offer_entity/recordcontainers/db/onDBDelete.js index 5c36082b96..066cc33ad0 100644 --- a/entity/Offer_entity/recordcontainers/db/onDBDelete.js +++ b/entity/Offer_entity/recordcontainers/db/onDBDelete.js @@ -2,4 +2,5 @@ import("Sql_lib"); import("system.vars"); import("system.db"); -db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2")); \ No newline at end of file +newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID") + .deleteData(true, "OFFERITEM"); \ No newline at end of file diff --git a/entity/Offeritem_entity/entityfields/price/displayValueProcess.js b/entity/Offeritem_entity/entityfields/price/displayValueProcess.js index 7937b0dc6c..e637f9b6ad 100644 --- a/entity/Offeritem_entity/entityfields/price/displayValueProcess.js +++ b/entity/Offeritem_entity/entityfields/price/displayValueProcess.js @@ -13,9 +13,10 @@ var curr = vars.get("$param.Currency_param") } else { - curr = db.cell(SqlCondition.begin() - .andPrepareVars("OFFER.OFFERID", "$field.OFFER_ID") - .buildSql("select CURRENCY from OFFER", "1=2")); + curr = newSelect("CURRENCY") + .from("OFFER") + .whereIfSet("OFFER.OFFERID", "$field.OFFER_ID") + .cell(true); } result.string(NumberUtils.formatWithCurrency(vars.get("$field.PRICE"), translate.text("#,##0.00"), curr)); \ No newline at end of file diff --git a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js index 5870914adc..3bad73db28 100644 --- a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js +++ b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js @@ -19,11 +19,12 @@ if(pid != "") //TODO: loading from db until loading from Consumer is possible. var ProductDetails = ProductUtils.getProductDetails(pid, PriceListFilter, - [["info", SqlUtils.translateStatementWithQuotes(SqlCondition.begin() - .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "local.value") - .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'") - .andPrepareVars("DESCRIPTIONTRANSLATION.LANG", "$param.Language_param") - .buildSql("(select DESCRIPTION from DESCRIPTIONTRANSLATION", "1=2", ")"))] + [["info", "(" + newSelect("DESCRIPTION") + .from("DESCRIPTIONTRANSLATION") + .whereIfSet("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "local.value") + .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'") + .andIfSet("DESCRIPTIONTRANSLATION.LANG", "$param.Language_param") + .toString() + ")"] ]); if(ProductDetails.productId != undefined) diff --git a/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js b/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js index 106a609bee..f23c116341 100644 --- a/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js +++ b/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js @@ -13,9 +13,10 @@ var curr = vars.get("$param.Currency_param") } else { - curr = db.cell(SqlCondition.begin() - .andPrepareVars("OFFER.OFFERID", "$field.OFFER_ID") - .buildSql("select CURRENCY from OFFER", "1=2")); + curr = newSelect("CURRENCY") + .from("OFFER") + .whereIfSet("OFFER.OFFERID", "$field.OFFER_ID") + .cell(true); } result.string(NumberUtils.formatWithCurrency(vars.get("$field.TotalPrice"), translate.text("#,##0.00"), curr)); \ No newline at end of file diff --git a/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js b/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js index 935c6d7b06..82c536561a 100644 --- a/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js @@ -3,8 +3,7 @@ import("Sql_lib"); import("system.result"); import("system.vars"); -var cond = SqlCondition.begin() - .andPrepareVars("OFFERITEM.OFFER_ID", "$param.OfferId_param") +var cond = newWhereIfSet("OFFERITEM.OFFER_ID", "$param.OfferId_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/Offeritem_entity/recordcontainers/db/onDBDelete.js b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js index 568700b215..b57a000dc5 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js @@ -16,8 +16,9 @@ if(oid != "") var cols = ["NET", "VAT"]; var vals = oiUtils.getNetAndVat(deletedIds); - - db.updateData("OFFER", cols, null, vals, SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2")); + + newWhere("OFFER.OFFERID", oid) + .updateData(true, cols, null, vals, "OFFER") neon.refresh(); } \ No newline at end of file diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js index 317fce086c..04e755228f 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js @@ -22,6 +22,6 @@ if(oid != "") var vals = oiUtils.getNetAndVat(); var cols = ["NET", "VAT"]; - db.updateData("OFFER", cols, null, vals, SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2")); - + newWhere("OFFER.OFFERID", oid) + .updateData(true, cols, null, vals, "OFFER"); } \ No newline at end of file diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js index 01bec1734b..604a63f14f 100644 --- a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js @@ -10,5 +10,6 @@ if(oid != "") var cols = ["NET", "VAT"]; var oiUtils = new OfferItemUtils(oid); - db.updateData("OFFER", cols, null, oiUtils.getNetAndVat(), SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2")); + newWhere("OFFER.OFFERID", oid) + .updateData(true, cols, null, oiUtils.getNetAndVat(), "OFFER"); } \ No newline at end of file diff --git a/entity/Order_entity/entityfields/cancel/onActionProcess.js b/entity/Order_entity/entityfields/cancel/onActionProcess.js index f138c6f577..fa3f5510b5 100644 --- a/entity/Order_entity/entityfields/cancel/onActionProcess.js +++ b/entity/Order_entity/entityfields/cancel/onActionProcess.js @@ -8,9 +8,9 @@ import("KeywordRegistry_basic"); var id = vars.get("$field.SALESORDERID"); -db.updateData("SALESORDER", ["CANCELLATION"], null, ["1"], SqlCondition.begin() - .andPrepareVars("SALESORDER.SALESORDERID", "$field.SALESORDERID") - .build("1=2")); +newWhereIfSet("SALESORDER.SALESORDERID", "$field.SALESORDERID") + .updateData(true, ["CANCELLATION"], null, ["1"], "SALESORDER") + neon.refreshAll(); var contactId = vars.getString("$field.CONTACT_ID"); diff --git a/entity/Order_entity/entityfields/cancel/stateProcess.js b/entity/Order_entity/entityfields/cancel/stateProcess.js index 64b25ea3d5..ec7809f90e 100644 --- a/entity/Order_entity/entityfields/cancel/stateProcess.js +++ b/entity/Order_entity/entityfields/cancel/stateProcess.js @@ -6,9 +6,10 @@ import("system.neon"); import("Keyword_lib"); import("KeywordRegistry_basic"); -var itemcount = db.cell(SqlCondition.begin() - .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID") - .buildSql("select count(*) from SALESORDERITEM", "1=2")); +var itemcount = newSelect("count(*)") + .from("SALESORDERITEM") + .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID") + .cell(true, "0"); if(itemcount == "0") result.string(neon.COMPONENTSTATE_DISABLED); diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 1b774c9486..8daa0c113d 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -1757,7 +1757,7 @@ SqlBuilder.prototype.deleteData = function(pExecuteOnlyIfConditionExists, pTable * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, "" is returned * @return {String} the result of the query */ -SqlBuilder.prototype.cell = function(pExecuteOnlyIfConditionExists) +SqlBuilder.prototype.cell = function(pExecuteOnlyIfConditionExists, pFallbackValue) { if (this._checkForSelect(pExecuteOnlyIfConditionExists)) { @@ -1766,7 +1766,7 @@ SqlBuilder.prototype.cell = function(pExecuteOnlyIfConditionExists) } else { - return ""; + return (pFallbackValue ? pFallbackValue : ""); } } -- GitLab