How to make a rule update when making changes to SQL DB value?
I'm using this method...
Child IntentDbConnection As :dbConnection
dataProvider = :SQLSERVER
connectionString = "Data Source=" & dataSourceName & ";Initial Catalog=" & initialCatalogName & ";Integrated Security=True"
onNullReturn = ""
showInModelBrowser? = True
End Child
' Get the design data.
Child DT_cDesign As :dbDataTable
Connection = IntentDbConnection
selectCommandText = "SELECT dbUniqueId, BaseStructureHeight, PanelDepthNumeric, UnitMounting FROM cDesign WHERE Name = '" & designName & "' "
tableName = "cDesign"
showInModelBrowser? = False
End Child
' Get the base height.
Uncached Rule BaseStructureHeight As String
If DT_cDesign.RowCount > 0 Then
Return DT_cDesign.getFieldValue(0, 1)
Else
Return ""
End If
End Rule
When making changes to the field (i.e.BaseStructureHeight), the rule doesn't update!!! I tried Uncached but that doesn't work!!!
Thanks!
Luc
Hi Luc,
Several notes:
1. dbDataTable stores the tabular data in memory. If you know that the data cannot change and access to it is frequent, then it is the right solution. If you need to re-read data from the Server, call DT_cDesign.Fill() Method in your rule BaseStructureHeight
2. You may wish to consider another approach: perform the queries on IntentDbConnection child. The Methods of interest would be GetQueryResultsByRow or GetQueryResultsByColumn. The return value will be List of Lists. The translation between database and Intent data types is automatic. The documentation is available on Wiki.
Uncached Rule BaseStructureHeight As String
Dim result = IntentDbConnection.GetQueryResultsByRow("SELECT dbUniqueId, BaseStructureHeight, _
PanelDepthNumeric, UnitMounting FROM cDesign WHERE Name = '" & designName & "' ")
'.... more logic
End Rule
Thanks Alex!
Using either suggested methods works great. When evaluating the rule in the Immediate window, I get the updated value...
However, I need to find a way to trigger the update of the model. Is there a way to accomplish that? Rigth now, the only way I can update the model is by modifying the Intent code. I saw (Root.RenderSelf) but that doesn't seem to work!!!
Regards,
Luc
Since rules always have the correct value, there is no built-in way to "update". Of course, if you change a rule's formula, then all dependent rules will update automatically. In your situation, the rules no longer have the correct value because they have an external dependency. So the solution to "fake" changing the rule's formula. You do this directly thru the Intent API if you have a custom UI, or thru the IDE. You can either literally change the rule's formula, or you can "unbind" it. In either case, all dependent rules will also be unbound. Then when you do an update/render, they will all be recomputed with the new values. Of course you only have to change something that the DB-related rule depends upon, such as its connection string or whatever, in order to get it to re-read the data from the DB.
Hope this helps.
Ok thanks John!
Will live with that for now! I guess we could had this to ETO Idea Station...Re-compute button!!!
Regards,
Luc