Skip to content

Commit

Permalink
feat: Update SQL placeholder name [DHIS2-14429]
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mackessy committed Jan 22, 2025
1 parent c359142 commit ce814ad
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ -- loop through each record with a matching source id
and dv.categoryoptioncomboid = catOptCombo;
-- target duplicate found and target has latest lastUpdated value
if (target_duplicate.source_column is not null
if (target_duplicate.sourceColumn is not null
and target_duplicate.lastupdated >= source_dv.lastupdated)
then
-- delete source
Expand All @@ -877,7 +877,7 @@ -- loop through each record with a matching source id
and categoryoptioncomboid = source_dv.categoryoptioncomboid;
-- target duplicate found and source has latest lastUpdated value
elsif (target_duplicate.source_column is not null
elsif (target_duplicate.sourceColumn is not null
and target_duplicate.lastupdated < source_dv.lastupdated)
then
-- delete target
Expand All @@ -890,7 +890,7 @@ -- loop through each record with a matching source id
-- update source with target
update datavalue
set source_column = target_id
set sourceColumn = target_id
where dataelementid = source_dv.dataelementid
and periodid = source_dv.periodid
and sourceid = source_dv.sourceid
Expand All @@ -900,7 +900,7 @@ -- loop through each record with a matching source id
else
-- no target duplicate found, update source with target id
update datavalue
set source_column = target_id
set sourceColumn = target_id
where dataelementid = source_dv.dataelementid
and periodid = source_dv.periodid
and sourceid = source_dv.sourceid
Expand All @@ -918,17 +918,17 @@ -- loop through each record with a matching source id
targetId, sourceIds.stream().map(String::valueOf).collect(Collectors.joining(",")));

if (mergeType.equals(DataValueMergeType.DATA_ELEMENT)) {
return sql.replace("source_column", "dataelementid")
return sql.replace("sourceColumn", "dataelementid")
.replace("dataElement", "target_id")
.replace("catOptCombo", "source_dv.categoryoptioncomboid")
.replace("attrOptCombo", "source_dv.attributeoptioncomboid");
} else if (mergeType.equals(DataValueMergeType.CATEGORY_OPTION_COMBO)) {
return sql.replace("source_column", "categoryoptioncomboid")
return sql.replace("sourceColumn", "categoryoptioncomboid")
.replace("dataElement", "source_dv.dataelementid")
.replace("catOptCombo", "target_id")
.replace("attrOptCombo", "source_dv.attributeoptioncomboid");
} else if (mergeType.equals(DataValueMergeType.ATTRIBUTE_OPTION_COMBO)) {
return sql.replace("source_column", "attributeoptioncomboid")
return sql.replace("sourceColumn", "attributeoptioncomboid")
.replace("dataElement", "source_dv.dataelementid")
.replace("catOptCombo", "source_dv.categoryoptioncomboid")
.replace("attrOptCombo", "target_id");
Expand Down

0 comments on commit ce814ad

Please sign in to comment.