# question on calculations

**URL:** <https://forum.servoy.com/t/question-on-calculations/9866>\
**Category:** Classic Servoy\
**Created:** [November 11, 2008, 10:34am UTC](https://forum.servoy.com/t/question-on-calculations/9866 "2008-11-11T10:34:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [November 11, 2008, 10:34am UTC](https://forum.servoy.com/t/question-on-calculations/9866/1 "2008-11-11T10:34:30Z")

</div>

Hi,

This is a followup on [http://www.servoy.com/forum/viewtopic.php?f=2&t=11535](http://www.servoy.com/forum/viewtopic.php?f=2&t=11535)

We use quite a few calculations (unstored) in our solution.  
Some of these had loops in them to calculate values based on 2 or 3 related tables/fields.  
First of all these (heavy) calculations give errors in tableview and i created a case for this.

I noticed ( also thanks to Harjo) that these calculations also have a significant impact  
on the performance of Servoy and the Oracle database.

So i changed the calculation into a Sql query and that was much faster and also gives no errors in tableview.

But using databaseManager.getDataSetByQuery in a calculation is not supported.

So i changed my calculation to use a stored function which is even faster then a sql-query.  
AND it is supported in a calculation.

```auto
var args = new Array() ; 
args[0] = java.sql.Types.NUMERIC ; 
args[1] = inkpordkrt_id
var typesArray = new Array() ; 
typesArray[0] = 1;
typesArray[1] = 0;
var proc_declaration = '{?=call get_inkorder_inkbedr_tot(?)}' ;
var dmesp = plugins.rawSQL.executeStoredProcedure('berp2', proc_declaration, args, typesArray,1) ; 
return dmesp.getValue(1,1);

```

This al works great.  
If I change one of the related table-fields (that are used in the stored function) in a child record the calculation is also updated.

But : if another user changes such a table-field of a child record the databroadcasting takes care of updating those  
table-fields in the child records in my solution (on my screen), but the calculation (also on my screen) based on  
the stored function is not updated.

if I do it the old-fashioned way ( looping trough foundset in calculation) the calculation does get updated if  
one of the childrecords is updated by databroadcasting.

So it seems that if there are no relations / fields in the calculation pointing to the childrecords,  
the calculation does nog get updated if childrecords are updated trough databroadcastring.

Is this standard behaviour or could this be a bug ?

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [November 11, 2008, 11:21am UTC](https://forum.servoy.com/t/question-on-calculations/9866/2 "2008-11-11T11:21:00Z")

</div>

I inserted some dummy lines to refer to the fields on the childrecords  
and now the calcuation is also updated when the childrecords are updated trough databroadcasting.

```auto
if(utils.hasRecords(bvko_full_inkorderkaarten_to_inkorderspecregels))
{
 var _dum1 = bvko_full_inkorderkaarten_to_inkorderspecregels.inkorsrgl_aantal
 var _dum2 = bvko_full_inkorderkaarten_to_inkorderspecregels.inkorsrgl_ik_prijs
 var _dum3 = bvko_full_inkorderkaarten_to_inkorderspecregels.bvko_inkorderspecregels_to_verkorderregels$verkor_id.verkor_aantal
}

var args = new Array() ; 
args[0] = java.sql.Types.NUMERIC ; 
args[1] = inkpordkrt_id
var typesArray = new Array() ; 
typesArray[0] = 1;
typesArray[1] = 0;
var proc_declaration = '{?=call get_inkorder_inkbedr_tot(?)}' ;
var dmesp = plugins.rawSQL.executeStoredProcedure('berp2', proc_declaration, args, typesArray,1) ; 
return dmesp.getValue(1,1);

```

Is this a good workaround or ??

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [November 11, 2008, 12:23pm UTC](https://forum.servoy.com/t/question-on-calculations/9866/3 "2008-11-11T12:23:58Z")

</div>

Hi Hans,

I think IMHO this is a good workaround, because you now reference the calc, to related data, the servoy way.  
So Servoy now knows that it has to update this calculation because some of childeren has changed.

(PS If I look out of the window, I see your company! ![;-)]( "Wink") I’m working in Hengelo today ![:-)]( "Smile") )

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [November 11, 2008, 3:30pm UTC](https://forum.servoy.com/t/question-on-calculations/9866/4 "2008-11-11T15:30:03Z")

</div>

calcs know what the reference and based on that they get refreshed  
so if you do rawSQL under the hood we dont know anything so that is normal behavior

Harjo: you have a new building start working in that!

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [November 11, 2008, 4:21pm UTC](https://forum.servoy.com/t/question-on-calculations/9866/5 "2008-11-11T16:21:59Z")

</div>

Thanks !

There is one thing i still do not understand :

- I put the calculation ( only raw sql, no dummy lines) in a masterform

- I put the child records in a tabpanel on that masterform

- then when I change data in the child records on the tabpanel and save, the calculation  
in the masterform is being updated by Servoy.  
And there is no reference in there, only rawsql !!  
Or do al calculations on screen get updated when you save data ?

- i start a second smartclient with the same solution.

- do the same actions in the second smartclient

- in the second smartclient the calculation in the master form gets updated

- in the first smartclient the childrecords are updated, but the calculation  
in the masterform is not updated.

Regards,

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [November 11, 2008, 4:34pm UTC](https://forum.servoy.com/t/question-on-calculations/9866/6 "2008-11-11T16:34:12Z")

</div>

yes calculations are tested for records that are set in edit mode  
So when you save records then all the stored calcs are recalculated of those records.

This way way make sure to be in sync with calcs like you use.
