I don’t have any onUpdate, onInsert or onDelete events.
I have a general framework that handles all database transactions. I show you a part of the framework:
The forms[_form] is my currentform
databaseManager.startTransaction()
if(forms[_form].onPreSave)
{
_methodReturn = forms[_form].onPreSave()
if(_methodReturn == -1)
{
_errormessage = ServoyException.getMessage();
databaseManager.rollbackEditedRecords();
databaseManager.rollbackTransaction() ;
if (_errormessage == '')
plugins.dialogs.showErrorDialog('Save record', 'Due to database restictions the record could not be saved','OK');
else
plugins.dialogs.showErrorDialog('Save record', _errormessage,'OK');
return;
}
}
_success = forms[_form].controller.saveData();
if (_success == false)
{
_errormessage = ServoyException.getMessage();
databaseManager.rollbackEditedRecords();
databaseManager.rollbackTransaction();
if (_errormessage == '')
plugins.dialogs.showErrorDialog('Save record', 'Due to database restictions the record could not be saved','OK');
else
plugins.dialogs.showErrorDialog('Save record', _errormessage,'OK');
return;
}
databaseManager.commitTransaction()
The onPreSave method looks as follows, but I don’t have the idea that it has something to do with it:
var _query
var _exception
var _success
sequence_nr = salesorderline_to_salesorder.sequence_nr_line + 5
_query = 'UPDATE salesorder \
SET sequence_nr_line = ' + sequence_nr + ' \
WHERE salesorder_id = ' + salesorder_id
_success = plugins.rawSQL.executeSQL( globals.sec_db_connection, 'salesorder', _query)
if (_success == false)
{
var msg = plugins.rawSQL.getException().getMessage(); //see exception node for more info about the exception obj
plugins.dialogs.showErrorDialog('Error', 'SQL exception: '+msg, 'Ok')
return -1;
}
return;
This line is returning false:
_success = forms[_form].controller.saveData();
I think that there is some restriction somewhere, which causes that the data can not be written. Think about Null-values not allowed or an invalid relation. The problem is, that I don’t get any errormessage, so I really don’t know what is wrong.
I even tried to give the variable ‘_success’ the value true and continue the transaction, but the data was not written to the database.
I also noticed that sometimes, it does work after several times trying to add a record, with the same data. That makes it even stranger. Therefore if I can get the errormessage, why the saveData() didn’t succeed, perhaps I can find out where the problem is. Can be in my application also, but without errormessage, it is difficult to find. Specially when occasionally the record was added.
So if there is a way that I can determine the errormessage, it would help me a lot already.