CommonValue "numeric" rendered as string #119
-
Hi, I'm migrating from an old version to the newest. Things have changed, but up until now I've figured everything to update my config/settings to the new way of things. However, I'm hitting a wall with one of my report. That report is using a {CommonValue_XYZ} to select one or more element from the restriction drop down list. That CommonValue is populated dynamically with a SQL query. The list renders as expected. But when I select more that one value and execute the report, it throws an error. A quick investigation in the logs showed that the list is rendered in the SQL as fieldname in '10,8' Which of course fail because "fieldname" is a field of numeric type. fieldname in (10,8) I've look these aspects to make sure the type is okay :
Maybe I'm just missing a simple config somewhere. Have a nice day |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi again, After a bit of local debugging the solution, I found that a line of the file "ReportRestriction.cs" has changed from _SQLText = string.Format("({0})", (HasValue ? EnumSQLValue : "NULL")); to _SQLText = string.Format("{0}", (HasValue ? EnumSQLValue : "NULL")); commit adfdb4a And then from _SQLText = string.Format("{0}", (HasValue ? EnumSQLValue : "NULL")); to _SQLText = HasValue ? "'" + string.Join(",", EnumValues.Select(s => s.Replace("'", "''")).ToList()) + "'" : "NULL"; commit 391374e#diff-f00206604f1cc94abf1d54a393c51c772901c16c764263ba9edbf02fc9033869 Given the last line, no matter the type of data, the values are joined with a To fix this, I have changed that line (ReportRestriction.cs line 1669) with : if (IsNumeric)
{
_SQLText = HasValue ? "(" + string.Join(",", EnumValues.ToList()) + ")" : "NULL";
}
else if (IsText)
{
_SQLText = HasValue ? "(" + string.Join(",", EnumValues.Select(s => "'" + s.Replace("'", "''") + "'").ToList()) + ")" : "NULL";
}
else
{
_SQLText = HasValue ? "'" + string.Join(",", EnumValues.Select(s => s.Replace("'", "''")).ToList()) + "'" : "NULL";
} With the modified code above, the generated sql is : fieldname in (10,8) And in case of a text enum : fieldname in ('abc', 'def') That's a bit quick & dirty, but it seems to works for what I need. The case of dates should probably be taken in account too, but I think it's not as common as this to have dropdowns with dates. At least I don't have any in my reports, in the majority of the time I only use IDs so numeric data to use in a "where field in (1,2,3)" clause. Have a nice day! |
Beta Was this translation helpful? Give feedback.
-
Marked as resolved because PR #120 was merged. |
Beta Was this translation helpful? Give feedback.
Marked as resolved because PR #120 was merged.
Have a nice day!