/// <summary> /// Generates the SQL Where clause for the component used in this mapping /// and the condition value from SDMX Query which is transcoded /// </summary> /// <param name="conditionValue"> /// string with the conditional value from the SDMX query /// </param> /// <param name="operatorValue"> /// string with the operator value from the SDMX query, "=" by default /// </param> /// <returns> /// A SQL where clause for the columns of the mapping /// </returns> public string GenerateComponentWhere(string conditionValue, string operatorValue = "=") { var ret = new StringBuilder(); ret.Append(" ("); CodeSetCollection localCodesSet = this.Mapping.Transcoding.TranscodingRules.GetLocalCodes(new CodeCollection(new[] { conditionValue })); if (localCodesSet.Count > 0) { for (int i = 0; i < localCodesSet.Count; i++) { if (i != 0) { ret.Append(" OR "); } ret.Append(" ("); Collection <string> localCodes = localCodesSet[i]; // component to columns var mappedClause = new List <string>(); foreach (DataSetColumnEntity column in this.Mapping.Columns) { string mappedId = column.Name; string mappedValue = EscapeString(conditionValue); int columnPosition = this.Mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition[column.SysId]; if (localCodes != null && columnPosition < localCodes.Count) { mappedValue = localCodes[columnPosition]; } mappedClause.Add(SqlOperatorComponent(mappedId, mappedValue, operatorValue)); //mappedClause.Add( // string.Format(CultureInfo.InvariantCulture, "{0} " + operatorValue + " '{1}' ", mappedId, mappedValue)); } ret.Append(string.Join(" AND ", mappedClause.ToArray())); ret.Append(" ) "); } } else { var mappedClause = new List <string>(); foreach (DataSetColumnEntity column in this.Mapping.Columns) { string mappedId = column.Name; string mappedValue = EscapeString(conditionValue); mappedClause.Add(SqlOperatorComponent(mappedId, mappedValue, operatorValue)); //mappedClause.Add(string.Format(CultureInfo.InvariantCulture, "{0} " + operatorValue + " '{1}' ", mappedId, mappedValue)); } ret.Append(string.Join(" AND ", mappedClause.ToArray())); } ret.Append(" )"); return(ret.ToString()); }
/// <summary> /// Generates the SQL Where clause for the component used in this mapping /// and the condition value from SDMX Query which is transcoded /// </summary> /// <param name="conditionValue"> /// string with the conditional value from the sdmx query /// </param> /// <param name="operatorValue"> /// string with the operator value from the sdmx query, "=" by default /// </param> /// <returns> /// A SQL where clause for the columns of the mapping /// </returns> public string GenerateComponentWhere(string conditionValue, string operatorValue = "=") { var ret = new StringBuilder(); ret.Append(" ("); CodeSetCollection localCodesSet = this.Mapping.Transcoding.TranscodingRules.GetLocalCodes(new CodeCollection(new[] { conditionValue })); DataSetColumnEntity column = this.Mapping.Columns[0]; string mappedValue = EscapeString(conditionValue); // TODO check if columnIndex == 0 always int columnIndex = 0; // was this.Mapping.Transcoding.TranscodingRules.ColumnAsKeyPosition[column.Name]; if (localCodesSet.Count > 0) { for (int i = 0; i < localCodesSet.Count; i++) { Collection <string> localCodes = localCodesSet[i]; if (localCodes != null && localCodes.Count > 0) { mappedValue = localCodes[columnIndex]; } if (i != 0) { ret.Append(" or "); } ret.Append("( " + SqlOperatorComponent(column.Name, mappedValue, operatorValue) + ")"); //ret.AppendFormat("( {0} " + operatorValue + " '{1}' )", column.Name, mappedValue); } } else { ret.Append(" " + SqlOperatorComponent(column.Name, mappedValue, operatorValue)); //ret.AppendFormat(" {0} " + operatorValue + " '{1}' ", column.Name, mappedValue); } ret.Append(") "); return(ret.ToString()); }