diff --git a/entity/Activity_entity/recordcontainers/db/conditionProcess.js b/entity/Activity_entity/recordcontainers/db/conditionProcess.js index ee923b83f263327cc85adc8fa23f144ea350f3f0..e0906775187d80bbf874dc372e3a690ffae846f8 100644 --- a/entity/Activity_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Activity_entity/recordcontainers/db/conditionProcess.js @@ -23,7 +23,7 @@ if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars. .arrayColumn(); if (allPersonRelatedContactIds.length === 0) - condition.and("1=2"); + condition.noResult(); else { activityLinkSubselect.and("ACTIVITYLINK.OBJECT_ROWID", allPersonRelatedContactIds, SqlBuilder.IN()); @@ -40,11 +40,10 @@ if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars. if (vars.exists("$param.ActivityIDs_param") && vars.get("$param.ActivityIDs_param")) { var acticityIds = JSON.parse(vars.get("$param.ActivityIDs_param")); - if (acticityIds.length == 0) { - condition.and("ACTIVITY.ACTIVITYID", ""); // Bedingung um kein Ergebnis zu bekommen - } else { + if (acticityIds.length == 0) + condition.noResult(); + else condition.and("ACTIVITY.ACTIVITYID", acticityIds, SqlBuilder.IN()); - } } if (vars.getString("$param.OnlyInnate_param") == "true") @@ -53,7 +52,7 @@ if (vars.getString("$param.OnlyInnate_param") == "true") if (ownContactId) condition.and("ACTIVITY.RESPONSIBLE", ownContactId); else - condition.clearWhere().and("1=2"); + condition.noResult(); } //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 diff --git a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js index 68666406b4705e7e463034ccbce8d35400bae35f..6fcb81de353b15da6987c4a057a54535f2d1fcbb 100644 --- a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js +++ b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js @@ -20,7 +20,7 @@ if (vars.getString("$param.WhitelistIds_param")) if (whitelist.length > 0) cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN()); else - cond.and("1=2"); // force empty result if whitelist is empty + cond.noResult(); // force empty result if whitelist is empty } //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 diff --git a/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js b/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js index f20cd5000331d5b73514378d9389d8ea3c0ca9b4..0f8a38ee79cd0f0b93ce8e8a75bd1dbcb54c353d 100644 --- a/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js +++ b/entity/Organisation_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js @@ -1,3 +1,4 @@ +import("Sql_lib"); import("Context_lib"); import("system.result"); import("ObjectRelation_lib"); @@ -7,4 +8,4 @@ import("ObjectRelation_lib"); var mapping = {}; mapping[ContextUtils.getCurrentContextId()] = "CONTACT.CONTACTID"; -result.string(ObjectRelationUtils.getFilterCondition(mapping).toString("1=2")); \ No newline at end of file +result.string(ObjectRelationUtils.getFilterCondition(mapping).toString(SqlBuilder.NORESULT_CONDITION())); \ 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 96a93d2ddef53d2c42ac1e41124aeeb5987e0531..105cede4033ebdd5e3892b002dc5e2545ea28f7f 100644 --- a/entity/Person_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Person_entity/recordcontainers/db/conditionProcess.js @@ -24,15 +24,9 @@ if (vars.exists("$param.ExcludedContactIds_param") && vars.get("$param.ExcludedC var onlyShowContactIds = JSON.parse(vars.get("$param.OnlyShowContactIds_param")); -if(onlyShowContactIds != null && onlyShowContactIds.length > 0) +if (onlyShowContactIds != null && onlyShowContactIds.length > 0) { - let additionalCondition = newWhere(); - onlyShowContactIds.forEach(function(pContactId) - { - additionalCondition.or("CONTACT.CONTACTID", pContactId); - }); - cond.and(additionalCondition); - alternativeCondition = "1 = 2"; + cond.and("CONTACT.CONTACTID", onlyShowContactIds, SqlBuilder.IN()); } if (vars.exists("$param.OnlyOwnSupervised_param") && vars.get("$param.OnlyOwnSupervised_param") == "true") diff --git a/entity/Person_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js b/entity/Person_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js index 60242965b3b74a56854008a2ed0973bc8a6428e7..4516eb7b9b3f6d4413c3f214a644245db68fafbf 100644 --- a/entity/Person_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js +++ b/entity/Person_entity/recordcontainers/db/recordfieldmappings/objecttrees/filterConditionProcess.js @@ -1,3 +1,4 @@ +import("Sql_lib"); import("Context_lib"); import("system.result"); import("ObjectRelation_lib"); @@ -8,4 +9,4 @@ var mapping = {}; mapping[ContextUtils.getCurrentContextId()] = "CONTACT.CONTACTID"; mapping["PrivatePerson"] = "CONTACT.PERSON_ID"; -result.string(ObjectRelationUtils.getFilterCondition(mapping).toString("1=2")); \ No newline at end of file +result.string(ObjectRelationUtils.getFilterCondition(mapping).toString(SqlBuilder.NORESULT_CONDITION())); \ 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 05d2e05eca452c8c0739c7c39eaae157f6e37576..a3fb601aa08385a85a4370d783a55ea681ed90f6 100644 --- a/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js +++ b/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js @@ -9,15 +9,13 @@ var cond = newWhere() .and("TASK.KIND", $KeywordRegistry.taskType$ticket()) .andIfSet("TICKET.TICKETTYPE", "$param.TicketType_param") -var loadNothing = false; - if (vars.getString("$param.FilterOnlyOwnTicket_param") == "true") { var ownContactId = EmployeeUtils.getCurrentContactId(); if (ownContactId) cond.andIfSet("TASK.EDITOR_CONTACT_ID", ownContactId); else - loadNothing = true; + cond.noResult(); } if (vars.get("$param.RowId_param") && vars.get("$param.ObjectId_param")) @@ -30,12 +28,5 @@ if (vars.get("$param.RowId_param") && vars.get("$param.ObjectId_param")) , SqlBuilder.IN()); } -if (loadNothing) -{ - result.string("1=2"); -} -else -{ - //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026 - result.string(cond.toString()); -} \ 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 bf89d69810e24d611916e499974711d72c438654..aeaf998bec85dc61e32fafcbb7c2138486c7e21a 100644 --- a/entity/Task_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Task_entity/recordcontainers/db/conditionProcess.js @@ -29,7 +29,7 @@ if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars. if (loadNothing) { - result.string("1=2"); + result.string(SqlBuilder.NORESULT_CONDITION()); } else { diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js index b38ab24f96c87d6895583dcb9f2b787ea503fd34..2c9252dbe40607288e9d161bbc44f94a366b1f61 100644 --- a/process/Campaign_lib/process.js +++ b/process/Campaign_lib/process.js @@ -453,7 +453,7 @@ CampaignUtils.GetParticipantsCountByCondition = function(pWhereCondition) // If pWhereCondition would be used directly, // .cell() would return number of all participants and // .cell(true) would return an empty string "", not 0 - .where(pWhereCondition.build("1=2")) + .where(pWhereCondition.build(SqlBuilder.NORESULT_CONDITION())) .cell(); } @@ -484,7 +484,7 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondi // If pWhereCondition would be used directly, // .cell() would return number of all participants and // .cell(true) would return an empty string "", not 0 - .where(pWhereCondition.build("1=2")) + .where(pWhereCondition.build(SqlBuilder.NORESULT_CONDITION())) return select.cell(); } @@ -649,7 +649,7 @@ CampaignUtils.copyCampaignSteps = function(pSourceCampaignId, pTargetCampaignId) { var InputMapping = { "CAMPAIGNSTEP": { - condition: newWhereIfSet("CAMPAIGN.CAMPAIGN_ID", pSourceCampaignId).orderBy("SORTING").toString("1=2", true), + condition: newWhereIfSet("CAMPAIGN.CAMPAIGN_ID", pSourceCampaignId).orderBy("SORTING").toString(SqlBuilder.NORESULT_CONDITION(), true), ValueMapping: { "CAMPAIGN_ID" : pTargetCampaignId } diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js index 59bed651862041d08e72db34ad3256cab51d8acc..953330e3b3a74c6c6bf0af2b9a4bdeeaec4fd731 100644 --- a/process/Context_lib/process.js +++ b/process/Context_lib/process.js @@ -632,7 +632,7 @@ ContextUtils.getNameSql = function(pContextId, pRowId) return newSelect(selectMap[pContextId].titleExpression) .from(selectMap[pContextId].getFullFromClause()) .whereIfSet(selectMap[pContextId].getFullIdField(), pRowId) - .build("1=2"); + .build(SqlBuilder.NORESULT_CONDITION()); } else return "select 1 from person where 1=2"; diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js index 0c256379c13b6773e3ce47459b083c71a1177496..3ba48d7e1d7ddd87f6e07038e6601034abac295e 100644 --- a/process/Offer_lib/process.js +++ b/process/Offer_lib/process.js @@ -356,7 +356,7 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId) { var InputMapping = { "OFFERITEM": { - condition: newWhereIfSet("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString("1=2", true), + condition: newWhereIfSet("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString(SqlBuilder.NORESULT_CONDITION(), true), ValueMapping: { "OFFER_ID" : pTargetOfferId } diff --git a/process/Order_lib/process.js b/process/Order_lib/process.js index 22b0f95f8fefc6596f8bfb5cd9f66146a09610d4..d6938458c59687ef679f1d437661ec456e01f2e8 100644 --- a/process/Order_lib/process.js +++ b/process/Order_lib/process.js @@ -156,7 +156,7 @@ OrderUtils.copyOfferItemsToOrder = function (pSourceOfferId, pOrderId) "INFO" : "INFO", "VAT" : "VAT" }, - condition: newWhereIfSet("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString("1=2", true), + condition: newWhereIfSet("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString(SqlBuilder.NORESULT_CONDITION(), true), ValueMapping: { "OFFER_ID" : pOrderId } diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 3039c1cf1cbd1468351cd93493862d3d91fbd47c..93cf3bee053edf0291c9bde4df05e8199d3c7516 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -1825,13 +1825,23 @@ SqlBuilder.GREATER_OR_EQUAL = function () /** * Constant-like function which provides a value for pCondition if you need a "# <= ?" statement. * - * @return {String} + * @return {String} */ SqlBuilder.LESS_OR_EQUAL = function () { return "# <= ?"; } +/** + * Constant-like function which returns an impossible condition ("1 = 2"). + * + * @return {String} + */ +SqlBuilder.NORESULT_CONDITION = function () +{ + return "1 = 2"; +} + /** * Object providing constant-like functions for sql-any-conditions. */ @@ -2870,6 +2880,16 @@ SqlBuilder.prototype.forEachPage = function (pCallBackFn, pExecuteOnlyIfConditio run = pCallBackFn.call(null, this.nextTablePage(pExecuteOnlyIfConditionExists, pTimeout)) != false; } +/** + * Sets an impossible where-condition, so that the query won't return any rows. + * + * @return {SqlBuilder} current object + */ +SqlBuilder.prototype.noResult = function () +{ + return this.clearWhere().where(SqlBuilder.NORESULT_CONDITION()); +} + /** * checks if an update /delete statement should be called or not * @return {Boolean}