dataSave() returns true but does not save

Questions, tips and tricks and techniques for scripting in Servoy

dataSave() returns true but does not save

Postby maria » Wed Jul 22, 2009 7:24 am

I am saving a record from the current foundset but the changes are not saved in the database:

Code: Select all
   var _siteRecord = foundset.getRecord(foundset.getSelectedIndex());
   databaseManager.saveData(_siteRecord);


I inspected _siteRecord, it returns the record with the expected changes done by the user.
The save command returns true. However nothing changes in the database.
What could this be?

In another scenario, databaseManager.saveData(_record) returns false but .getFailedRecords() returns an empty array.
Why would this happen?

Cheer,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: dataSave() returns true but does not save

Postby ngervasi » Wed Jul 22, 2009 11:27 am

Did you check the database log? Any error message there?
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: dataSave() returns true but does not save

Postby jcompagner » Wed Jul 29, 2009 12:29 pm

if you cal databaseManager.getEditedRecords() right before you call save
is that record that you try to save next in that array?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: dataSave() returns true but does not save

Postby maria » Thu Jul 30, 2009 3:36 am

jcompagner wrote:if you cal databaseManager.getEditedRecords() right before you call save
is that record that you try to save next in that array?


Thanks Johan,
I've already solved the problem a few days ago but will keep in mind this way of checking edited records.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: dataSave() returns true but does not save

Postby maria » Thu Aug 20, 2009 6:25 am

jcompagner wrote:if you cal databaseManager.getEditedRecords() right before you call save
is that record that you try to save next in that array?


The problem came up again.
I check the edited records and can see the record that has been edited with all appropriate changes.
The form that the record is created in was modified before that: the datasource was changed to another table, but everything seems ok, the form data reflect whatever is in the database table, deleteRecord() works fine on the same form...

Any other clues?

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: dataSave() returns true but does not save

Postby birgit » Thu Aug 20, 2009 8:54 am

Hi Maria

If I understand you right, you have two problems:
- First, the result of databaseManager.saveData() returns a non predictable result
- Second, the saveData does not save the data into the DB

I also figured out that I better ignore the result of the saveData(). I check for databaseManager.getFailedRecords() to check if a save was successful. This works fine for us.

If a save fails I ckeck:
- Is the primary key filled out and unique?
- do I have a constraints on the table in the DB which prevents a save?
- is there a table event in Servoy (onRecordUpdate or onRecordInsert) preventing a save?
- databaseManager.getFailedRecords()
- was auto save true or false?
- record.exception.getMessage()
- databaseManager.getLastDatabaseMessage()

Good luck and regards
Birgit Rieder
7r gmbh, Switzerland
SAN Developer
User avatar
birgit
 
Posts: 302
Joined: Sun Jan 15, 2006 10:04 pm
Location: Switzerland

Re: dataSave() returns true but does not save

Postby jcompagner » Thu Aug 20, 2009 9:09 am

what are the results of:

var before = databaseManager.getEditedRecords();
// does before really have the right changed values..
var saved = databaseManagger.saveData();
var after= databaseManager.getEditedRecords();
var failed= databaseManager.getFailedRecords();

By the way databaseManager.saveData() can return false without failedReccords giving results
if the validation does fail in servoy (onDataChange events or table events) then it will just return false.
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 1 guest

cron