|
@@ -1722,45 +1722,51 @@ public class SQLiteProvider : IProvider
|
|
|
if (attribute.Operator == FormulaOperator.Constant)
|
|
|
return EscapeValue(attribute.Value);
|
|
|
|
|
|
- if (!fieldmap.ContainsKey(attribute.Value))
|
|
|
- throw new Exception(string.Format("{0}.{1} -> {2} does not exist", columnname, attribute.GetType().Name, attribute.Value));
|
|
|
+// Crashes when value is a constant, and therefore not a field in the table
|
|
|
+// if (!fieldmap.ContainsKey(attribute.Value))
|
|
|
+// throw new Exception(string.Format("{0}.{1} -> {2} does not exist", columnname, attribute.GetType().Name, attribute.Value));
|
|
|
+
|
|
|
+// Crashes when modifier is a constant, and therefore not a field in the table
|
|
|
+// foreach (var modifier in attribute.Modifiers)
|
|
|
+// if (!fieldmap.ContainsKey(modifier))
|
|
|
+// throw new Exception(string.Format("{0}.{1} -> {2} does not exist", columnname, attribute.GetType().Name, modifier));
|
|
|
|
|
|
- foreach (var modifier in attribute.Modifiers)
|
|
|
- if (!fieldmap.ContainsKey(modifier))
|
|
|
- throw new Exception(string.Format("{0}.{1} -> {2} does not exist", columnname, attribute.GetType().Name, modifier));
|
|
|
-
|
|
|
-
|
|
|
if (attribute.Operator == FormulaOperator.Add)
|
|
|
- return string.Format("(IFNULL({0},0.00) + {1})", fieldmap[attribute.Value],
|
|
|
- string.Join(" + ", attribute.Modifiers.Select(x => string.Format("IFNULL({0},0.00)", fieldmap[x]))));
|
|
|
+ return string.Format("(IFNULL({0},0.00) + {1})",
|
|
|
+ fieldmap.TryGetValue(attribute.Value, out var _value) ? _value : attribute.Value,
|
|
|
+ string.Join(" + ", attribute.Modifiers.Select(x => fieldmap.TryGetValue(x, out var _value) ? $"IFNULL({_value},0.00)" : $"{x}")));
|
|
|
|
|
|
if (attribute.Operator == FormulaOperator.Subtract)
|
|
|
- return string.Format("(IFNULL({0},0.00) - ({1}))", fieldmap[attribute.Value],
|
|
|
- string.Join(" + ", attribute.Modifiers.Select(x => string.Format("IFNULL({0},0.00)", fieldmap[x]))));
|
|
|
+ return string.Format("(IFNULL({0},0.00) - ({1}))",
|
|
|
+ fieldmap.TryGetValue(attribute.Value, out var _value) ? _value : attribute.Value,
|
|
|
+ string.Join(" + ", attribute.Modifiers.Select(x => fieldmap.TryGetValue(x, out var _value) ? $"IFNULL({_value},0.00)" : $"{x}")));
|
|
|
|
|
|
if (attribute.Operator == FormulaOperator.Multiply)
|
|
|
- return string.Format("(IFNULL({0},0.00) * {1})", fieldmap[attribute.Value],
|
|
|
- string.Join(" * ", attribute.Modifiers.Select(x => string.Format("IFNULL({0},0.00)", fieldmap[x]))));
|
|
|
+ return string.Format("(IFNULL({0},0.00) * {1})",
|
|
|
+ fieldmap.TryGetValue(attribute.Value, out var _value) ? _value : attribute.Value,
|
|
|
+ string.Join(" * ", attribute.Modifiers.Select(x => fieldmap.TryGetValue(x, out var _value) ? $"IFNULL({_value},0.00)" : $"{x}")));
|
|
|
|
|
|
if (attribute.Operator == FormulaOperator.Divide)
|
|
|
{
|
|
|
- var result = string.Format("IFNULL({0},0.00)", fieldmap[attribute.Value]);
|
|
|
+ var result = string.Format("IFNULL({0},0.00)", fieldmap.TryGetValue(attribute.Value, out var _v) ? _v : attribute.Value);
|
|
|
foreach (var modifier in attribute.Modifiers)
|
|
|
- result = string.Format("({0} / {1})", result, string.Format("IFNULL({0},1.00)", fieldmap[modifier]));
|
|
|
+ result = string.Format("({0} / {1})", result, fieldmap.TryGetValue(modifier, out var _value) ? $"IFNULL({_value},1.00)" : $"{modifier}");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if (attribute.Operator == FormulaOperator.Maximum)
|
|
|
{
|
|
|
- var parameters = attribute.Modifiers.Select(m => $"IFNULL({fieldmap[m]},0.00)");
|
|
|
- var result = $"MAX({fieldmap[attribute.Value]}, {String.Join(", ", parameters)})";
|
|
|
+ var parameters = attribute.Modifiers.Select(m => fieldmap.TryGetValue(m, out var _value) ? $"IFNULL({_value},0.00)" : $"{m}");
|
|
|
+ var primary = fieldmap.TryGetValue(attribute.Value, out var _v) ? _v : attribute.Value;
|
|
|
+ var result = $"MAX({primary}, {String.Join(", ", parameters)})";
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if (attribute.Operator == FormulaOperator.Minumum)
|
|
|
{
|
|
|
- var parameters = attribute.Modifiers.Select(m => $"IFNULL({fieldmap[m]},0.00)");
|
|
|
- var result = $"MIN({fieldmap[attribute.Value]}, {String.Join(", ", parameters)})";
|
|
|
+ var parameters = attribute.Modifiers.Select(m => fieldmap.TryGetValue(m, out var _value) ? $"IFNULL({_value},0.00)" : $"{m}");
|
|
|
+ var primary = fieldmap.TryGetValue(attribute.Value, out var _v) ? _v : attribute.Value;
|
|
|
+ var result = $"MIN({primary}, {String.Join(", ", parameters)})";
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -2085,16 +2091,12 @@ public class SQLiteProvider : IProvider
|
|
|
{
|
|
|
foreach (var field in fnc.Modifiers.Prepend(fnc.Value))
|
|
|
{
|
|
|
- try
|
|
|
+ if (CoreUtils.TryGetProperty(type,field,out var _))
|
|
|
{
|
|
|
CheckColumn(columns, field);
|
|
|
- LoadFieldsAndTables(command, type, prefix, fieldmap, tables, columns, Column.Create(type, field), useparams);
|
|
|
+ LoadFieldsAndTables(command, type, prefix, fieldmap, tables, columns,
|
|
|
+ Column.Create(type, field), useparams);
|
|
|
}
|
|
|
- catch (Exception e2)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error,"",$"Error creating column from field [{field}] : {e2.Message} ");
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
fieldmap[baseCol.Name] = GetFunction(fnc, fieldmap, baseCol.Name);
|
|
|
}
|