catching database error when databaseManager.commitTransacti

Questions, tips and tricks and techniques for scripting in Servoy

catching database error when databaseManager.commitTransacti

Postby Hans Nieuwenhuis » Wed May 13, 2009 10:46 am

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 :

Code: Select all
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
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: catching database error when databaseManager.commitTransacti

Postby Hans Nieuwenhuis » Sat May 16, 2009 7:15 pm

Hi,

Maybe one of the Servoyans can comment on this ?

Thanks,

Hans
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: catching database error when databaseManager.commitTransacti

Postby rgansevles » Mon May 18, 2009 1:53 pm

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: catching database error when databaseManager.commitTransacti

Postby Hans Nieuwenhuis » Mon May 18, 2009 2:11 pm

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 Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: catching database error when databaseManager.commitTransacti

Postby rgansevles » Mon May 18, 2009 4:05 pm

Hans,

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

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: catching database error when databaseManager.commitTransacti

Postby jcompagner » Mon May 18, 2009 6:22 pm

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?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: catching database error when databaseManager.commitTransacti

Postby Hans Nieuwenhuis » Mon May 18, 2009 6:25 pm

Hi Johan,

There are no failed records when the commit transaction fails.

Regards,

Hans
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: catching database error when databaseManager.commitTransacti

Postby jcompagner » Mon May 18, 2009 6:46 pm

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)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 30 guests

cron