Skip to content
Snippets Groups Projects
Commit 60732113 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

use SqlBuilder

parent 8270458e
No related branches found
No related tags found
No related merge requests found
...@@ -341,12 +341,10 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondi ...@@ -341,12 +341,10 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondi
} }
CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pParticipantRowIds) CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pParticipantRowIds)
{ {
let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds);
return newSelect("CONTACT.CONTACTID") return newSelect("CONTACT.CONTACTID")
.from("CONTACT") .from("CONTACT")
.where("CONTACT.CONTACTID", rowIdsAsRay, SqlBuilder.IN()) .where("CONTACT.CONTACTID", pParticipantRowIds, SqlBuilder.IN())
.and("CONTACT.CONTACTID", .and("CONTACT.CONTACTID",
newSelect("CAMPAIGNPARTICIPANT.CONTACT_ID") newSelect("CAMPAIGNPARTICIPANT.CONTACT_ID")
.from("CAMPAIGNPARTICIPANT") .from("CAMPAIGNPARTICIPANT")
...@@ -507,17 +505,4 @@ _CampaignUtils._openAddParticipantContext = function(pContext, pTargetDataExpres ...@@ -507,17 +505,4 @@ _CampaignUtils._openAddParticipantContext = function(pContext, pTargetDataExpres
params["dataSourceTableName_param"] = pSourceTableName; params["dataSourceTableName_param"] = pSourceTableName;
neon.openContext(pContext, null, null, neon.OPERATINGSTATE_NEW, params); neon.openContext(pContext, null, null, neon.OPERATINGSTATE_NEW, params);
} }
\ No newline at end of file
_CampaignUtils._convertToSqlValuesList = function(pValuesArray)
{
let rowIds = "(";
for (i = 0; i < pValuesArray.length; i++)
{
rowIds += "'" + pValuesArray[i] + "'";
if(i < pValuesArray.length-1)
rowIds += ",";
}
rowIds += ")";
return rowIds;
}
...@@ -67,10 +67,11 @@ CommUtil.setStandardForCategory = function(pAffectedRowId, pNewStandardCommId, p ...@@ -67,10 +67,11 @@ CommUtil.setStandardForCategory = function(pAffectedRowId, pNewStandardCommId, p
if (pNewStandardCommId != "") if (pNewStandardCommId != "")
{ {
//set the new standard comm-record //set the new standard comm-record
cond = newWhere("COMMUNICATION.COMMUNICATIONID", pNewStandardCommId); cond = newWhere("COMMUNICATION.COMMUNICATIONID", pNewStandardCommId)
//check communicationid, contactId and medium to prevent data-inconsistency when bad function params are passed by (e.g communicationid of a different category) //check communicationid, contactId and medium to prevent data-inconsistency when bad function params are passed by (e.g communicationid of a different category)
cond.andPrepare().andPrepare("COMMUNICATION.CONTACT_ID", pAffectedRowId); .and("COMMUNICATION.CONTACT_ID", pAffectedRowId)
cond.and("MEDIUM_ID in ('" + mediumIds.join("', '") + "')"); .and("COMMUNICATION.MEDIUM_ID", mediumIds, SqlBuilder.IN());
statements.push(["COMMUNICATION", cols, types, ["1"], cond.build()]); statements.push(["COMMUNICATION", cols, types, ["1"], cond.build()]);
} }
......
...@@ -534,6 +534,8 @@ ContextUtils.getSelectMap = function() ...@@ -534,6 +534,8 @@ ContextUtils.getSelectMap = function()
*/ */
ContextUtils.getNameSubselectSql = function(pContextIdDbField, pRowIdDbField) ContextUtils.getNameSubselectSql = function(pContextIdDbField, pRowIdDbField)
{ {
// TODO: prepared?
var select = "(case " + pContextIdDbField + " "; var select = "(case " + pContextIdDbField + " ";
var selectMap = ContextUtils.getSelectMap () var selectMap = ContextUtils.getSelectMap ()
......
...@@ -32,11 +32,13 @@ function DuplicateScannerUtils() {} ...@@ -32,11 +32,13 @@ function DuplicateScannerUtils() {}
*/ */
DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity) DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity)
{ {
let query = "select FILTER_CONDITION, COUNT_CHARACTERS_TO_USE, MAX_RESULTS_THRESHOLD from DUPLICATESCANNERPREFILTERCONFIG" let query = newSelect("FILTER_CONDITION, COUNT_CHARACTERS_TO_USE, MAX_RESULTS_THRESHOLD")
+ " join DUPLICATESCANNER on DUPLICATESCANNER.ID = DUPLICATESCANNERPREFILTERCONFIG.DUPLICATESCANNER_ID" .from("DUPLICATESCANNERPREFILTERCONFIG")
+ " where FILTER_NAME = '" + pFilterName + "'" .join("DUPLICATESCANNER", "DUPLICATESCANNER.ID = DUPLICATESCANNERPREFILTERCONFIG.DUPLICATESCANNER_ID")
+ " and ENTITY_TO_SCAN_NAME = '" + pTargetEntity + "'"; .where("DUPLICATESCANNER.FILTER_NAME", pFilterName)
return db.table(query); .and("DUPLICATESCANNER.ENTITY_TO_SCAN_NAME", pFilterName);
return query.table();
} }
/* /*
...@@ -48,10 +50,14 @@ DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity) ...@@ -48,10 +50,14 @@ DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity)
*/ */
DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId)
{ {
let query = "select count(ID), CLUSTERID from DUPLICATECLUSTERS" let query = newSelect("count(ID), CLUSTERID from DUPLICATECLUSTERS")
+ " where CLUSTERID in (select CLUSTERID from DUPLICATECLUSTERS where DUPLICATEID = '"+ pDuplicateId +"')" .from("DUPLICATECLUSTERS")
+ " and DUPLICATEID != '"+ pDuplicateId +"'" .where("DUPLICATECLUSTERS.CLUSTERID", newSelect("CLUSTERID")
+ " group by CLUSTERID"; .from("DUPLICATECLUSTERS")
.where("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId),
SqlBuilder.IN())
.and("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId, "# != ?")
.groupBy("CLUSTERID");
let coundAndClusterId = db.array(db.ROW, query); let coundAndClusterId = db.array(db.ROW, query);
let countDuplicatesInClusterWithoutParameterId = coundAndClusterId[0]; let countDuplicatesInClusterWithoutParameterId = coundAndClusterId[0];
...@@ -64,14 +70,16 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) ...@@ -64,14 +70,16 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId)
if(countDuplicatesInClusterWithoutParameterId <= 1) if(countDuplicatesInClusterWithoutParameterId <= 1)
{ {
let deleteStatements = []; let deleteStatements = [];
deleteStatements.push(["DUPLICATECLUSTERS", "DUPLICATECLUSTERS.CLUSTERID = '"+ clusterId +"'"]); deleteStatements.push(["DUPLICATECLUSTERS", newWhere("DUPLICATECLUSTERS.CLUSTERID", clusterId).build()]);
deleteStatements.push(["UNRELATEDDUPLICATES", "UNRELATEDDUPLICATES.CLUSTERID = '"+ clusterId +"'"]); deleteStatements.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.CLUSTERID", clusterId).build()]);
db.deletes(deleteStatements); db.deletes(deleteStatements);
} }
else else
{ {
db.deleteData("DUPLICATECLUSTERS", "DUPLICATECLUSTERS.DUPLICATEID = '"+ pDuplicateId +"'"); newWhereIfSet("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId)
.deleteData(true, "DUPLICATECLUSTERS");
//Delete all records where this duplicateId is mentioned //Delete all records where this duplicateId is mentioned
DuplicateScannerUtils.DeleteAllUnrelatedDuplicateRelations(pDuplicateId); DuplicateScannerUtils.DeleteAllUnrelatedDuplicateRelations(pDuplicateId);
} }
...@@ -86,7 +94,8 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) ...@@ -86,7 +94,8 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId)
*/ */
DuplicateScannerUtils.DeleteDuplicateClustersByTargetEntity = function(pTargetEntity) DuplicateScannerUtils.DeleteDuplicateClustersByTargetEntity = function(pTargetEntity)
{ {
return db.deleteData("DUPLICATECLUSTERS", "DUPLICATECLUSTERS.TARGET_ENTITY = '"+ pTargetEntity +"'") return newWhereIfSet("DUPLICATECLUSTERS.TARGET_ENTITY", pTargetEntity)
.deleteData(true, "DUPLICATECLUSTERS");
} }
/* /*
...@@ -106,12 +115,13 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit ...@@ -106,12 +115,13 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit
let INDEX_NEW_CLUSTERID = 0; let INDEX_NEW_CLUSTERID = 0;
let INDEX_OLD_CLUSTERID = 1; let INDEX_OLD_CLUSTERID = 1;
let query = "select dc1.CLUSTERID, ud.CLUSTERID from UNRELATEDDUPLICATES ud" let query = newSelect("dc1.CLUSTERID, ud.CLUSTERID")
+ " join DUPLICATECLUSTERS dc1 on dc1.DUPLICATEID = ud.SOURCEDUPLICATEID" .from("UNRELATEDDUPLICATES", "ud")
+ " join DUPLICATECLUSTERS dc2 on dc2.DUPLICATEID = ud.UNRELATEDDUPLICATEID" .join("DUPLICATECLUSTERS", "dc1.DUPLICATEID = ud.SOURCEDUPLICATEID", "dc1")
+ " where dc1.TARGET_ENTITY = '" + pTargetEntity + "'"; .join("DUPLICATECLUSTERS", "dc2.DUPLICATEID = ud.UNRELATEDDUPLICATEID", "dc2")
.where(["DUPLICATECLUSTERS", "TARGET_ENTITY", "dc1"], pTargetEntity);
let newIdOldIdRay = db.table(query); let newIdOldIdRay = query.table();
let updateStatements = []; let updateStatements = [];
//Build update statements to set new clusterIds //Build update statements to set new clusterIds
...@@ -120,9 +130,8 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit ...@@ -120,9 +130,8 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit
let newClusterId = newIdOldIdRay[i][INDEX_NEW_CLUSTERID]; let newClusterId = newIdOldIdRay[i][INDEX_NEW_CLUSTERID];
let oldClusterId = newIdOldIdRay[i][INDEX_OLD_CLUSTERID]; let oldClusterId = newIdOldIdRay[i][INDEX_OLD_CLUSTERID];
let updateColumns = ["CLUSTERID"]; let updateColumns = ["CLUSTERID"];
let condition = "UNRELATEDDUPLICATES.CLUSTERID = '" + oldClusterId + "'";
let updateStatement = ["UNRELATEDDUPLICATES", updateColumns, null, [newClusterId], condition]; let updateStatement = ["UNRELATEDDUPLICATES", updateColumns, null, [newClusterId], newWhere("UNRELATEDDUPLICATES.CLUSTERID", oldClusterId).build()];
updateStatements.push(updateStatement); updateStatements.push(updateStatement);
} }
...@@ -132,8 +141,8 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit ...@@ -132,8 +141,8 @@ DuplicateScannerUtils.RefreshUnrelatedDuplicateRelations = function(pTargetEntit
* All unrelated duplicate ids that still exist in a cluster, have been updated with the new cluster id. * All unrelated duplicate ids that still exist in a cluster, have been updated with the new cluster id.
* All records with a nonexistend clusterid can now be deleted because they haven't been detected as a duplicate any more. * All records with a nonexistend clusterid can now be deleted because they haven't been detected as a duplicate any more.
*/ */
let deleteCondition = "CLUSTERID not in (select dc1.CLUSTERID from DUPLICATECLUSTERS dc1)"; newWhere("UNRELATEDDUPLICATES.CLUSTERID", newSelect("dc1.CLUSTERID").from("DUPLICATECLUSTERS", "dc1"), SqlBuilder.NOT_IN())
db.deleteData("UNRELATEDDUPLICATES", deleteCondition); .deleteData(true, "UNRELATEDDUPLICATES");
} }
/* /*
...@@ -232,7 +241,7 @@ DuplicateScannerUtils.GetCachedDuplicatesForClusterId = function(pClusterId) ...@@ -232,7 +241,7 @@ DuplicateScannerUtils.GetCachedDuplicatesForClusterId = function(pClusterId)
.from("DUPLICATECLUSTERS") .from("DUPLICATECLUSTERS")
.where("DUPLICATECLUSTERS.DUPLICATEID", newSelect("UNRELATEDDUPLICATEID").from("UNRELATEDDUPLICATES"), .where("DUPLICATECLUSTERS.DUPLICATEID", newSelect("UNRELATEDDUPLICATEID").from("UNRELATEDDUPLICATES"),
SqlBuilder.NOT_IN()) SqlBuilder.NOT_IN())
.and("DUPLICATECLUSTERS.CLUSTERID", clusterIdRay) .and("DUPLICATECLUSTERS.CLUSTERID", pClusterId)
.arrayColumn(); .arrayColumn();
} }
...@@ -330,7 +339,7 @@ DuplicateScannerUtils.ScanRecords = function(pTargetEntity, pTargetRecordsData, ...@@ -330,7 +339,7 @@ DuplicateScannerUtils.ScanRecords = function(pTargetEntity, pTargetRecordsData,
//If the contact id loading query has no results, stop. //If the contact id loading query has no results, stop.
//No ids should be deleted if an error has been made in this query. //No ids should be deleted if an error has been made in this query.
if(pTargetRecordsData.length <= 0) if(pTargetRecordsData.length <= 0)
return; return undefined;
//First it gets checked if the current id has already been identified. If that's the case it'll continue with the next. //First it gets checked if the current id has already been identified. If that's the case it'll continue with the next.
//Otherwise an object gets build in the form of ["FilterFieldName" = "FilterFieldValueFromQuery"] with which a scan for possible duplicates get's started //Otherwise an object gets build in the form of ["FilterFieldName" = "FilterFieldValueFromQuery"] with which a scan for possible duplicates get's started
...@@ -631,7 +640,10 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId) ...@@ -631,7 +640,10 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
let updateStatementsSystemAlias = []; let updateStatementsSystemAlias = [];
let deleteStatements = []; let deleteStatements = [];
var sourcePersonId = db.cell("select PERSON_ID from CONTACT where CONTACTID = '" + pSourceContactId + "'"); var sourcePersonId = newSelect("PERSON_ID")
.from("CONTACT")
.where("CONTACT.CONTACTID", pSourceContactId)
.cell();
var tableInfosCurrentAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosCurrentAlias(); var tableInfosCurrentAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosCurrentAlias();
var tableInfosSystemAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosSystemAlias(); var tableInfosSystemAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosSystemAlias();
...@@ -757,7 +769,7 @@ var INDEX_CONDITION = 2; ...@@ -757,7 +769,7 @@ var INDEX_CONDITION = 2;
_DuplicateScannerUtils._buildUpdateResetStandardCommunications = function(pSourceContactId) _DuplicateScannerUtils._buildUpdateResetStandardCommunications = function(pSourceContactId)
{ {
return [["COMMUNICATION", ["ISSTANDARD"], null, ["0"], "CONTACT_ID = '" + pSourceContactId + "'"]]; return [["COMMUNICATION", ["ISSTANDARD"], null, ["0"], newWhere("COMMUNICATION.CONTACT_ID", pSourceContactId).build()]];
} }
/* /*
...@@ -988,16 +1000,14 @@ _DuplicateScannerUtils._deleteDuplicateClusters = function () ...@@ -988,16 +1000,14 @@ _DuplicateScannerUtils._deleteDuplicateClusters = function ()
*/ */
_DuplicateScannerUtils._buildUpdateAttachParticipantsToNewContactQuery = function (pTableName, pContactIdColumn, pAssignableIdColumn, pSourceContactId, pTargetContactId, updateStatements) _DuplicateScannerUtils._buildUpdateAttachParticipantsToNewContactQuery = function (pTableName, pContactIdColumn, pAssignableIdColumn, pSourceContactId, pTargetContactId, updateStatements)
{ {
var selectAssignableIdsOfTargetContactQuery = "select " + pAssignableIdColumn var selectAssignableIdsOfTargetContactQuery = newSelect(pAssignableIdColumn)
+ " from " + pTableName .from(pTableName)
+ " where " + pContactIdColumn + " = '" + pTargetContactId + "'"; .where([pTableName, pContactIdColumn], pTargetContactId);
let updateCondition = pAssignableIdColumn let updateCondition = newWhere([pTableName, pAssignableIdColumn], selectAssignableIdsOfTargetContactQuery, SqlBuilder.NOT_IN())
+ " not in" .and([pTableName, pContactIdColumn], pSourceContactId)
+ " (" + selectAssignableIdsOfTargetContactQuery + ")"
+ " and " + pContactIdColumn + " = '" + pSourceContactId + "'";
return [[pTableName, [pContactIdColumn], null, [pTargetContactId], updateCondition]]; return [[pTableName, [pContactIdColumn], null, [pTargetContactId], updateCondition.build()]];
} }
...@@ -1007,15 +1017,15 @@ _DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery = func ...@@ -1007,15 +1017,15 @@ _DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery = func
//DELETE FROM CAMPAIGNPARTICIPANT //DELETE FROM CAMPAIGNPARTICIPANT
// WHERE ( CAMPAIGN_ID in (select ab.CAMPAIGN_ID from (select CAMPAIGN_ID, CONTACT_ID from CAMPAIGNPARTICIPANT) ab where ab.CONTACT_ID = '64a51ec3-e75d-4415-8aa2-a00a1e9be0b0') and CAMPAIGN_ID = '51960918-3b24-4bac-8f1c-3892bf210f6d') // WHERE ( CAMPAIGN_ID in (select ab.CAMPAIGN_ID from (select CAMPAIGN_ID, CONTACT_ID from CAMPAIGNPARTICIPANT) ab where ab.CONTACT_ID = '64a51ec3-e75d-4415-8aa2-a00a1e9be0b0') and CAMPAIGN_ID = '51960918-3b24-4bac-8f1c-3892bf210f6d')
var selectAssignableIdsOfTargetContactQuery = "select " + pAssignableIdColumn var selectAssignableIdsOfTargetContactQuery = newSelect(pAssignableIdColumn)
+ " from " + pTableName .from(pTableName)
+ " where " + pContactIdColumn + " = '" + pTargetContactId + "'"; .where([pTableName, pContactIdColumn], pTargetContactId);
let deleteCondition = pAssignableIdColumn + " in" let deleteCondition = newWhere([pTableName, pAssignableIdColumn], selectAssignableIdsOfTargetContactQuery, SqlBuilder.IN())
+ " (" + selectAssignableIdsOfTargetContactQuery + ")" .and([pTableName, pAssignableIdColumn], pSourceContactId)
+ " and " + pAssignableIdColumn + " = '" + pSourceContactId + "'";
let recordsToDelete = []; let recordsToDelete = [];
recordsToDelete.push([pTableName, deleteCondition]); recordsToDelete.push([pTableName, deleteCondition.build()]);
return recordsToDelete; return recordsToDelete;
} }
...@@ -1028,24 +1038,24 @@ _DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery = func ...@@ -1028,24 +1038,24 @@ _DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery = func
_DuplicateScannerUtils._buildDeletePersonAndContactQuery = function(pSourcePersonId, pSourceContactId) _DuplicateScannerUtils._buildDeletePersonAndContactQuery = function(pSourcePersonId, pSourceContactId)
{ {
let recordsToDelete = [] let recordsToDelete = []
recordsToDelete.push(["PERSON", "PERSONID = '" + pSourcePersonId + "'"]); recordsToDelete.push(["PERSON", newWhere("PERSON.PERSONID", pSourcePersonId).build()]);
recordsToDelete.push(["CONTACT", "CONTACTID = '" + pSourceContactId + "'"]); recordsToDelete.push(["CONTACT", newWhere("CONTACT.CONTACTID", pSourcePersonId).build()]);
return recordsToDelete; return recordsToDelete;
} }
_DuplicateScannerUtils._buildDeleteOrganisationAndContactQuery = function(pSourceOrganisationId, pSourceContactId) _DuplicateScannerUtils._buildDeleteOrganisationAndContactQuery = function(pSourceOrganisationId, pSourceContactId)
{ {
let recordsToDelete = [] let recordsToDelete = []
recordsToDelete.push(["ORGANISATION", "ORGANISATIONID = '" + pSourceOrganisationId + "'"]); recordsToDelete.push(["ORGANISATION", newWhere("ORGANISATION.ORGANISATIONID", pSourceOrganisationId).build()]);
recordsToDelete.push(["CONTACT", "CONTACTID = '" + pSourceContactId + "'"]); recordsToDelete.push(["CONTACT", newWhere("CONTACT.CONTACTID", pSourceContactId).build()]);
return recordsToDelete; return recordsToDelete;
} }
_DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery = function(pSourceContactId) _DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery = function(pSourceContactId)
{ {
let recordsToDelete = [] let recordsToDelete = []
recordsToDelete.push(["UNRELATEDDUPLICATES", "SOURCEDUPLICATEID = '" + pSourceContactId + "'"]); recordsToDelete.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.SOURCEDUPLICATEID", pSourceContactId).build()]);
recordsToDelete.push(["UNRELATEDDUPLICATES", "UNRELATEDDUPLICATEID = '" + pSourceContactId + "'"]); recordsToDelete.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.UNRELATEDDUPLICATEID", pSourceContactId).build()]);
return recordsToDelete; return recordsToDelete;
} }
...@@ -1080,12 +1090,12 @@ _DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId, ...@@ -1080,12 +1090,12 @@ _DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId,
let columnName = pTableinfos[INDEX_COLUMN_NAME]; let columnName = pTableinfos[INDEX_COLUMN_NAME];
let additionalCondition = pTableinfos[INDEX_CONDITION]; let additionalCondition = pTableinfos[INDEX_CONDITION];
let condition = columnName + " = '" + pSourceContactId + "'"; let condition = newWhere([tableName, columnName], pSourceContactId);
if(additionalCondition != "") if(additionalCondition != "")
condition += " and ( " + additionalCondition + ") "; condition.and(additionalCondition);
return [tableName, [columnName], null, [pTargetContactId], condition]; return [tableName, [columnName], null, [pTargetContactId], condition.build()];
} }
/* /*
......
...@@ -11,6 +11,8 @@ import("Attribute_lib"); ...@@ -11,6 +11,8 @@ import("Attribute_lib");
import("Sql_lib"); import("Sql_lib");
import("Importer_lib"); import("Importer_lib");
// TODO: use SqlBuilder
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
/// toolkit methods for the import handler /// /// toolkit methods for the import handler ///
/// DO NOT TOUCH - use lib_importerCustomMappingFunctions /// /// DO NOT TOUCH - use lib_importerCustomMappingFunctions ///
......
...@@ -10,6 +10,8 @@ import("system.text"); ...@@ -10,6 +10,8 @@ import("system.text");
import("ImporterCustomMappingFunctions_lib"); import("ImporterCustomMappingFunctions_lib");
import("ImporterMappingFunctions_lib"); import("ImporterMappingFunctions_lib");
// TODO: use SqlBuilder
/* /*
┌─────────────────────────────────────────────────────────────┐ ┌─────────────────────────────────────────────────────────────┐
│ importer module constructor function │ │ importer module constructor function │
......
...@@ -83,7 +83,7 @@ function ItemUtils(pOfferOrderId, pTableName) { ...@@ -83,7 +83,7 @@ function ItemUtils(pOfferOrderId, pTableName) {
//check if itemsort/pos has been changed //check if itemsort/pos has been changed
if (oiTree[oiid].itemsort != compTree[oiid].itemsort || oiTree[oiid].pos != compTree[oiid].pos) { if (oiTree[oiid].itemsort != compTree[oiid].itemsort || oiTree[oiid].pos != compTree[oiid].pos) {
var vals = [compTree[oiid].itemsort, compTree[oiid].pos]; var vals = [compTree[oiid].itemsort, compTree[oiid].pos];
statements.push([this.tableName + "ITEM", cols, colTypes, vals, this.tableName + "ITEM" + "ID = '" + oiid + "'"]); statements.push([this.tableName + "ITEM", cols, colTypes, vals, newWhere([this.tableName + "ITEM", this.tableName + "ITEMID"], oiid).build()]);
} }
} }
} }
......
...@@ -331,7 +331,7 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId) ...@@ -331,7 +331,7 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId)
{ {
var InputMapping = { var InputMapping = {
"OFFERITEM": { "OFFERITEM": {
condition: "OFFER_ID = '" + pSourceOfferId + "' order by ITEMSORT", condition: newWhere("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString(),
ValueMapping: { ValueMapping: {
"OFFER_ID" : pTargetOfferId "OFFER_ID" : pTargetOfferId
} }
......
...@@ -145,7 +145,7 @@ OrderUtils.copyOfferItemsToOrder = function (pOfferId, pOrderId) ...@@ -145,7 +145,7 @@ OrderUtils.copyOfferItemsToOrder = function (pOfferId, pOrderId)
"INFO" : "INFO", "INFO" : "INFO",
"VAT" : "VAT" "VAT" : "VAT"
}, },
condition: "OFFER_ID = '" + pOfferId + "' order by ITEMSORT", condition: newWhere("OFFERITEM.OFFER_ID", pSourceOfferId).orderBy("ITEMSORT").toString(),
ValueMapping: { ValueMapping: {
"OFFER_ID" : pOrderId "OFFER_ID" : pOrderId
} }
......
...@@ -49,7 +49,7 @@ function updateBlob (path, filename) ...@@ -49,7 +49,7 @@ function updateBlob (path, filename)
function readBlob (path, filename) function readBlob (path, filename)
{ {
var fullPath = path + filename; var fullPath = path + filename;
var fromWhereCond = " from ASYS_BINARIES where ID = '" + filename + "'"; var fromWhereCond = new SqlBuilder(SqlUtils.getBinariesAlias()).from("ASYS_BINARIES").where("ASYS_BINARIES.ASYS_BINARIES", filename);
sqlHelper = new SqlMaskingUtils(); sqlHelper = new SqlMaskingUtils();
...@@ -58,9 +58,10 @@ function readBlob (path, filename) ...@@ -58,9 +58,10 @@ function readBlob (path, filename)
var blob = fileIO.getData(fullPath, util.DATA_BINARY); var blob = fileIO.getData(fullPath, util.DATA_BINARY);
result.string(blob); result.string(blob);
} }
else if (db.cell("select " + sqlHelper.bindataLength("BINDATA") + fromWhereCond, SqlUtils.getBinariesAlias()) > 0) // copy to reuse it inside of the if with other select field
else if (fromWhereCond.copy().select(sqlHelper.bindataLength("BINDATA")).cell() > 0)
{ {
blob = db.cell("select BINDATA " + fromWhereCond, SqlUtils.getBinariesAlias() ); blob = fromWhereCond.select("BINDATA").cell();
result.string(blob); result.string(blob);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment