catching database error when databaseManager.commitTransacti

Hi,

When a databaseManager.commitTransaction() fails, is there any way to retreive the database error.
(it does show up in the serverlog. The solutions onerror method is not called)

when a databaseManager.saveData fails i do get failed records.

I tried :

if(!databaseManager.commitTransaction())
{
  var _failedArray = databaseManager.getFailedRecords()
  for( var i = 0 ; i < _failedArray.length ; i++ ) 
  {
   var _record = _failedArray[i];
   application.output('Error in commitTransaction: ' + _record.exception);   
  }
.....

but the _failedArray.length is 0 and there is an error in the serverlog (violation of unique constraint)

Any ideas ?

B.t.w. this is in Servoy 3.5.9

Regards,

Hans Nieuwenhuis

Hi,

Maybe one of the Servoyans can comment on this ?

Thanks,

Hans

Hans,

databaseManager.commitTransaction() calls saveData() internally first.
Are the errors you get from the actual commit or only related to the saveData()?
What are the errors?

Rob

Hi Rob,

We use deferred unique constraints in the (Oracle) database.

suppose you have two records with a unqiue constraint on field name.

Before you edit the values are AA and BB.

Now you edit and change AA to BB and then save / commit

The saveData gives no error (which is correct) , and the commit Transaction only retuns false.

The error is shown in the admin server (violation of unique constraint)

I’d like tot catch this commit error in my/error method.

btw we use deferred to be able to handle the following example :

Before you edit the values are AA and BB.
Now change AA to BB and BB to AA then save/commit.
I the constaint is not deferred, Oracle will complain.

Regards,

Hans

Hans,

Currently commit/rollback failure is logged and not sent to the solution error handler.
Please create a feature request for that.

Rob

if commitTransaction returns false
then i think you should be able to say: getFailedRecords()

and ask for the exception of the records then you should have your error.

problems with db transactions and savedata with autosave off is that there can be multiply errors, 1 for every record you try to save
so which one should we report back if we just throw one exception?

Hi Johan,

There are no failed records when the commit transaction fails.

Regards,

Hans

hmm i just tried this with sybase and a null constraint column (cant be null)

i started a transaction
made 3 new records, didnt fill in the column
commit the transaction
then i do get the failed records.

But i guess your case the actual insert doesnt fail yet. only with the commit of the transaction the database does see that you violated your constraint.
(which is logical because you could have swapped your columns)

Its a pitty that we then never can pin point to a record (or that you always only see 1 error)