Skip to content
Snippets Groups Projects
Commit 15f61c91 authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

SqlMaskingUtils.prototype.concatWithSeparator fix for oracle

parent ea54ab72
No related branches found
No related tags found
No related merge requests found
......@@ -3653,7 +3653,7 @@ SqlMaskingUtils.prototype.concatWithSeparator = function (pFields, pSeparator, p
else if (pSeparator || pSeparator === "")
pSeparator = "'" + db.quote(pSeparator, this.alias) + "'";
var doEmptyStringCheck = true;
var isEmptyStringNull = false;
switch (this.dbType)
{
......@@ -3666,7 +3666,7 @@ SqlMaskingUtils.prototype.concatWithSeparator = function (pFields, pSeparator, p
case db.DBTYPE_ORACLE10_CLUSTER:
case db.DBTYPE_ORACLE10_THIN:
case db.DBTYPE_ORACLE10_OCI:
doEmptyStringCheck = false; //empty strings are changed to DB-null-values internally in oracle; by specifing JS-null we disable this check
isEmptyStringNull = true; //empty strings are changed to DB-null-values internally in oracle
break;
case db.DBTYPE_SQLSERVER2000:
//MS SQL Server supports "concat_ws" (and ignoring null values) from version SQL Server 2017 and newer:
......@@ -3675,7 +3675,7 @@ SqlMaskingUtils.prototype.concatWithSeparator = function (pFields, pSeparator, p
case db.DBTYPE_DERBY10:
break;
default:
throw new Error(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.concat"]));
throw new Error(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.concatWithSeparator"]));
}
var concatCharacter = this.getConcatSymbol();
......@@ -3686,10 +3686,13 @@ SqlMaskingUtils.prototype.concatWithSeparator = function (pFields, pSeparator, p
let field = pFields[i];
let isLast = i + 1 === pFields.length;
if (!_isFixedValue(field))
concatSql += (pAutoTrimFields ? this.trim(this.isNull(field)) : this.isNull(field));
else
if (_isFixedValue(field))
concatSql += (pAutoTrimFields ? "'" + field.slice(1, -1).trim() + "'" : field);
else
{
let stringField = isEmptyStringNull ? field : this.isNull(field);
concatSql += (pAutoTrimFields ? this.trim(stringField) : this.isNull(stringField));
}
if (!isLast)
{
......@@ -3702,10 +3705,12 @@ SqlMaskingUtils.prototype.concatWithSeparator = function (pFields, pSeparator, p
}
else if (pSeparator)
{
let nextNotNullCondition;
let nextFieldTrimmed = pAutoTrimFields ? this.trim(nextField) : nextField;
let nextNotNullCondition = nextField + " is not null ";
if (doEmptyStringCheck || pAutoTrimFields)
nextNotNullCondition += " and " + nextFieldTrimmed + " != '' ";
if (isEmptyStringNull)
nextNotNullCondition = nextFieldTrimmed + " is not null";
else
nextNotNullCondition = nextField + " is not null and " + nextFieldTrimmed + " != ''";
concatSql += "case when " + nextNotNullCondition + " then " + pSeparator + " else '' end " + concatCharacter;
}
......
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