← servoy magazine

[Tip] Why use transactions

  • Tips

by Marcel Trapman
www.it2be.com

Within Servoy we can use transactions. Transactions give you the possibility to let Servoy completely undo all actions on the database from the moment you started the transaction. No matter how complex.

Now, you may think you don't need a transaction, like I did.... But what about when you use dialogs to let the user set certain dataprovider values and you also give the user the possibility to cancel his/her activities? Without a transaction you need to use globals or 'remember' the old settings.

With a transaction you simply start the transaction 'onShow' with 'databaseManager.startTransaction()'. In a "cancel" method you do a 'databaseManager.rollbackTransaction()' and in an "ok" method you do 'databaseManager.commitTransaction()’.

As simple as that!

Cheers,

Marcel