When are 'table events' triggered?

I am considering the new 3.5 feature ‘table events’ to be analogous to database triggers, is that a correct assumption?

If so, when are they triggered? Before or after the data is written to the DB?

For example… If i do an update to a record I want servoy to perform some other functions with the data that in the database before the update to said record takes place.

They are triggered just before the data is written into the table.

When you have them return false, the write tothe database is canceled.

The events receive the record that is being inserted/updated/deleted as arguments[0].

hope that helps.

Paul

I just noticed a situation that hopefully it is a bug (and can be fixed as soon as possible if it is)

I have triggers on a table (for example currency)

onInsert I call the globals.currency_insert method
onUpdate I call the globals.currency_update method

That works correct, but …

In my method I do a test, and if the test returns false, then the insert/update must be undone

var _record = arguments[0];

// Number of decimals between 0 and 4
if (_record['number_of_decimals'] < 0 || _record['number_of_decimals'] > 4)
{
	plugins.dialogs.showErrorDialog( '',  i18n.getI18NMessage('globis.msg.number_of_decimals_values'), 'OK')
	return false;
}

return true

The method returns false in my test situation, because I gave ‘number_of_decimals’ the value 52.

The line below returns false as expected:

var _success = databaseManager.saveData();

But now it goes wrong:

if (_success == false)
{
   // If in transaction, then rollback the transaction
   if (databaseManager.hasTransaction())
   {
      databaseManager.rollbackTransaction()
   }	
}

I have a transaction, so the databasemanager should do a rollback.
But while doing the rollback, my insert trigger is called again :cry:

That is not what I expected, because now I’m getting my errormessage twice!

I’ve got the same situation again but I also succeeded to make a small example solution. I’ll post a bug

Martin,

This will be changed in release 3.5.4.
Table events will no longer be triggered on calling rollbackTransaction.

Rob

rgansevles:
Martin,

This will be changed in release 3.5.4.
Table events will no longer be triggered on calling rollbackTransaction.

Rob

I’m still experiencing occasional problems that makes the repository unreacheable. Since I didn’t have this kind of problems before adding a table event to my solution, the cause is probably some conflict between transactions and table events.
I’m not 100% sure, though. So, before filling a case in the support system: anybody is experiencing similar problems?
In my case, Servoy is not able to reach the repository anymore.
Restarting Servoy and Sybase solves the problem.

Servoy Developer
Version 3.5.5-build 518
Java version 1.5.0_13-121 (Mac OS X)

Riccardino:

rgansevles:
Martin,

In my case, Servoy is not able to reach the repository anymore.
Restarting Servoy and Sybase solves the problem.

Servoy Developer
Version 3.5.5-build 518
Java version 1.5.0_13-121 (Mac OS X)

Correction: I removed the table event, but I get this random error anyway.
So the issue come from elsewhere. I’ll set up a sample solution for the support team.