ROCLASI wrote:Hi Kim,
The other way is to update the foundset in one fell swoop using the performUpdate() method. What happens here is that Servoy doesn't use the foundset to loop through it but sends 1 single SQL update statement to the database and therefor the Servoy Table Event has no idea what happend.
I didn't want to believe this was true, since to me that would be completely unexpected behavior, and worse yet, is most definitely an undocumented deviation (
https://wiki.servoy.com/display/DOCS/JSFoundSetUpdater).
I tested this locally with all three ways (you forgot one Robert
![Wink :wink:](./images/smilies/icon_wink.gif)
) to use the JSFoundSetUpdater
Set by iterating:
Triggers Table Events- Code: Select all
var fsu = databaseManager.getFoundSetUpdater(foundset);
while (fsu.next()) {
fsu.setColumn(columnName, value);
}
fsu.performUpdate();
Set Column with Single Value:
Does Not Trigger Table Events- Code: Select all
var fsu = databaseManager.getFoundSetUpdater(foundset);
fsu.setColumn(columnName, value);
fsu.performUpdate();
Set Column By Array:
Triggers Table Events- Code: Select all
var fsu = databaseManager.getFoundSetUpdater(foundset);
fsu.setColumn(columnName, arrayOfValues); //arrayOfValues contains one value per record to be updated
fsu.performUpdate();
Since two of three methods of using the same object trigger Table Events, I would hesitate to call this a feature request and personally view it more as a bug. I believe that the general expectation, unless otherwise noted, is that when you work directly with Servoy provided objects (JSFoundSet, JSRecord, JSFoundSetUpdater) that you are in fact working within the provided application layer that would trigger your events. Only when you fall back to manual/raw methods (rawSQL, outside applications) would I lose the expectation of attached events triggering.
This seems to essentially mean that for any type of record that
could ever trigger a record event, you cannot use the "Set Column With Single Value" option, or risk introducing bugs into your software down the line when adding a table event (maybe even in a different module that your original work has no knowledge of!). You could perhaps try and mitigate this by providing some sort of "per table, single value, column batch update" method that handles this edge case for you so that if you need to change the behavior in the future, you've only got one place to edit, but it certainly feels like unnecessary complexity and something that Servoy should be handling for you given their capacity to provide the most efficient solution possible.
TL;DR
This is preferably a bug, and, at minimum if not fixed, should be noted in the documentation as a "feature"
![Smile :)](./images/smilies/icon_smile.gif)
Edit: Reported
https://support.servoy.com/browse/SVY-6854