f8d976479401c3889439a803180615d2019fa8b6
FAQ/Questions/Storing-Custom-Constraints.md
| ... | ... | @@ -1,36 +1,28 @@ |
| 1 | 1 | ##Question |
| 2 | 2 | |
| 3 | -Is there a way to store a pre-built string or object at the application level? so that the application does not have to call the AddConstraint() method every time a user wants to connect to a database |
|
| 3 | +Is there a way to store a pre-built string or object at application level? so that the application does not have to call the AddConstraint() method every time a user wants to connect to a database |
|
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | ##Answer |
| 7 | 7 | |
| 8 | -When Izenda loads a report that uses a stored procedure, it creates a temporary table to store the values. For string, it creates NVARCHAR(MAX) columns and for numeric fields a DECIMAL(18,6). Therefore, if any field with greater precision such as NUMERIC(22,8) is used, the report then fails with a conversion error as below because it cannot fit the NUMERIC(22,8) value into a DECIMAL(18,6) column. |
|
| 8 | +Custom constraints can be stored in application through following 3 steps |
|
| 9 | 9 | |
| 10 | + 1) Before adding constraints, put this line of code: |
|
| 10 | 11 | |
| 11 | - |
|
| 12 | + Driver driver = AdHocContext.Driver; |
|
| 12 | 13 | |
| 14 | +and change all their "AdHocContext.Driver.AddConstraint(...)" lines to "driver.AddConstraint(...)" |
|
| 13 | 15 | |
| 14 | -The hard-code default setting, DECIMAL(18,6) can be easily modified by adding below setting code to the Driver (within InitializeReporting() method) . |
|
| 16 | + |
|
| 15 | 17 | |
| 16 | -### Example) DECIMAL(18,6) (Default) to NUMERIC(22,8) |
|
| 18 | +2) Add following line of code right before adding first custom constraint: |
|
| 17 | 19 | |
| 18 | -```csharp |
|
| 20 | + AdHocContext.Driver.BeginAddingMultipleConstraints(); |
|
| 19 | 21 | |
| 20 | -public class CustomAdHocConfig : FileSystemAdHocConfig { |
|
| 21 | - public static void InitializeReporting() { |
|
| 22 | -... |
|
| 22 | + |
|
| 23 | + |
|
| 24 | +3) Add following line of code right after adding last custom constraint: |
|
| 25 | + |
|
| 26 | + AdHocContext.Driver.EndAddingMultipleConstraints(); |
|
| 23 | 27 | |
| 24 | -List<KeyValuePair<string, string>> typeOverrides = AdHocContext.Driver.NativeTypesOverrides; |
|
| 25 | -for (int i = 0; i < typeOverrides.Count; i++) |
|
| 26 | - if (typeOverrides[i].Key == "Decimal") |
|
| 27 | - { |
|
| 28 | - typeOverrides[i] = new KeyValuePair<string, string>(typeOverrides[i].Key, "NUMERIC(22,8)"); |
|
| 29 | - break; |
|
| 30 | - } |
|
| 31 | -AdHocContext.Driver.NativeTypesOverrides = typeOverrides; |
|
| 32 | 28 | |
| 33 | - }// End of InitializeReporting. |
|
| 34 | -... |
|
| 35 | -} |
|
| 36 | -``` |