DatabaseManager.setAutoSave(false) is not working

Questions and answers regarding general SQL and backend databases

DatabaseManager.setAutoSave(false) is not working

Postby hardina09 » Thu Sep 27, 2012 4:30 pm

In my form I am having UI elements to enter data and a Submit button. In onShow() event i have set databaseManager.setAutoSave(false), but when I execute form in brower adds a new empty record in table(pk is auto incremental) which should not, only on submit event should add data in table. I don't know why databaseManager.setAutoSave(false) on onShow() is not working properly or might I have missed something else.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: DatabaseManager.setAutoSave(false) is not working

Postby mboegem » Thu Sep 27, 2012 11:44 pm

databaseManager.setAutoSave(false) returns a boolean, what is the outcome of that?

A reason why databaseManager.setAutoSave(false) will fail is when there are unsaved changes which can't be written to the DB.
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: DatabaseManager.setAutoSave(false) is not working

Postby rgansevles » Fri Sep 28, 2012 10:09 am

hardina09,

databaseManager.setAutoSave(false) always returns true, only databaseManager.setAutoSave(true) may return false if some validation fails.

Isn't there some code in your solution that explicitely calls saveData()?

Try a very small sample to show this.

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

Re: DatabaseManager.setAutoSave(false) is not working

Postby hardina09 » Mon Oct 01, 2012 6:25 pm

When I start session or execute my form in browser and before any action event takes place a new empty record gets added to the table. In onShow() event I added statement databaseManager.setAutoSave(false) still adds new empty record in table. I don't know where I am wrong.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: DatabaseManager.setAutoSave(false) is not working

Postby rgansevles » Tue Oct 02, 2012 9:29 am

What happens first in your code, the newRecord() call or the setAutoSave(false) call?

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

Re: DatabaseManager.setAutoSave(false) is not working

Postby hardina09 » Tue Oct 02, 2012 2:57 pm

On show() event I am loading all records and code is :
Code: Select all
function onShow(firstShow, event) {
foundset.loadRecords('SELECT requestid FROM EMPTIMEOFF WHERE EMP_ID=? ',[globals.EMPID]);
databaseManager.setAutoSave(false)
foundset.sort('start_dts desc');
}


When I debug the code foundset.loadRecords throws an error message:
couldn't load dataset because foundset had editted records but couldn't save it
Couldn't do a sort because there where edited records on this foundset
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: DatabaseManager.setAutoSave(false) is not working

Postby rgansevles » Fri Oct 05, 2012 9:48 am

hardina09,

foundset.loadRecords() wants to save the record changes it has before loading a new set, otherwise these changes would be lost.
If it cannot save some of them due to some validation failing (like null values for non-null fields), you will get this error.

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

Re: DatabaseManager.setAutoSave(false) is not working

Postby hardina09 » Fri Oct 05, 2012 10:38 pm

You are Correct Rob. When I changed databaseManager.setAutoSave(false) to true, it worked absolutely fine

Thanks Rob.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm


Return to SQL Databases

Who is online

Users browsing this forum: Bing [Bot] and 12 guests