saveData....am I crazy?

I’m experimenting with databaseManager.setAutoSave(false) in 4.1rc3. I need a check for whether I’m doing something wrong, or I just don’t understand how this should work.

I set this up in a test solution with just one form, and have reproduced this behavior against MySQL and Sybase dbs.

What I’m doing is the following:

  1. In the solution open method, call “databaseManager.setAutoSave(false);”

  2. In a form’s onRecordEditStop method, calling…

if(databaseManager.hasRecordChanges(rec))
{
    var ok = databaseManager.saveData(rec);
}

I have also tried with “saveData()” (no record specified). And have confirmed that it is in fact called, and it’s returning true. There are no transactions involved on the db level.

The changes stay in memory and continue to be reflected in the smart client, but NEVER HIT THE DATABASE!!!

Am I misunderstanding this process? It was my understanding that if I turn autoSave off, then I just need to manually call saveData when I want something to hit the db.

Thanks for the input.

greg.

I seem to be having the problem when trying to save a specific record, not when just doing a databaseManager.saveData(). With autosave off, I change data on a form, click a “save” button which calls a global method passing the form name in lccurformname:

			var lncurindex = forms[lccurformname].foundset.getSelectedIndex()
			var lnsaveok = databaseManager.saveData(forms[lccurformname].foundset.getRecord(lncurindex))

When I debug:
lncurindex = contains the index of the current record on the form
forms[lccurformname].foundset.getRecord(lncurindex) contains the correct record object with changed data
lnsaveok = true.

It appears to save, however, closing the application and restarting shows the changed data was never actually save in the database.

greg, do you have that sample solution for us to test?

If you for example look at the performance tab in the config web page (or dump as much logging as possible) you really dont see an insert/update statement ?

agiletortoise:

  1. In the solution open method, call “databaseManager.setAutoSave(false);”

Beside the issue (that’s up to Johan), keep in mind that disabling autosave on solution open sometimes is a bit dangerous, for example servoy could end up in a scenario where there are some calculations that need to be written to the DB but your solution is not in edit mode and the user cannot save. I think the best approach is to always keep autosave turned on and disable it when the user actually needs to edit some data. Just my opinion.

I think the saving of a specific record continues to be a problem. When I do this:

				var lncurindex = forms[lccurformname].foundset.getSelectedIndex()
				var losaverec =  forms[lccurformname].foundset.getRecord(lncurindex) 
				var lnsaveok = databaseManager.saveData(losaverec )

when debugged, losaverec is a record object that contains the correct record, lnsaveok is true, but data isn’t saved to the database, the “e” in the status area indicates the record has unsaved changes, and any calculation functions associated with the table don’t fire. Replacing the above code with just:

				var lnsaveok = databaseManager.saveData( )

works fine. But of course it saves any other outstanding changes as well.

are you sure you save the right record?

try to compare it with what the database manager says: databaseManager.getEditedRecords()

OK -

				var lncurindex = forms[lccurformname].foundset.getSelectedIndex()
				var losaverec =  forms[lccurformname].foundset.getRecord(lncurindex) 
				var loeditedrecords = databaseManager.getEditedRecords()
				var llsaveok = databaseManager.saveData(losaverec )
				var loeditedrecords2 = databaseManager.getEditedRecords()

Debugging this in developer, loeditedrecords should contain the record object of the edited record, and loeditedrecords2 should be empty. Here’s what happens:
If the table does not have a stored calculation, everything seems to work fine. But when there is a stored calculation, things go crazy. The stored calculation function gets fired at getRecord(), getEditedRecords(), and saveData(losaverec ). loeditedrecords sometimes has one element containing the record, sometimes it has two elements, each holding the same record object. The same goes for loeditedrecords2. But in any case the data isn’t being saved.

So, if I edit a record in a table with a stored calc, and save it, then edit a record in a table without one, the second edit will save, but the first will not. loeditedrecords with have three elements and loeditedrecords2 will have two.

first are you sure that your data is not saved??
So is really an insert statement not fired to your database?

If find it weird that getRecord() only already touches your calc. That normally doesnt happen (ask a lot of people here, thats why we have databaseManager.recalculate(fsOrRecord))

getEditedRecords() does run the calc yes. because it tries to also cleanup the records so that you really dont get records that are not changed
And because of that we need to check the calcs.

and saveData does the same thing. Before you save a record we check the calcs to be sure that the are in a consistent state.

You really shouldnt get a list of 2 records that are exactly the same… That only should happen if they are also from 2 different foundsets.

But if the record that you save in saveData() is really also returned in the editedrecords after that even when the saveData() did return true then please make a case for this

When iI run getRecord() in debuuger, it does not step through the calc, however, if application.output() is included in calc function, that displays in debug console.

saveData(record) seems to work fine when adding records. The problem is editing existing records in some tables. I’m trying to investigate further.

I’ve had the same problem in rolling back transactions. Just wouldn’t work. So went back to using the transaction approach.

//databaseManager.rollbackEditedRecords()
//databaseManager.saveData()
//databaseManager.setAutoSave(true)
databaseManager.rollbackTransaction()

Couldn’t get the commented out to work. K

Hi

I only say you are not crazy.

Regards, Robert

Kurt,

what didnt work?
Do you have a sample that you can attach to a case?

So, I think I finally see the problem with saveData(record). I have forms that contain multiple forms in a tab panel which use the same table. If the forms are related in a self-relationship (PK to PK), and changes are made to any of the forms, the save does not hit the database. If I remove the relationName, and rely on Servoy to keep the pages in sync, it works fine. I have found this to be the case with three different sets of forms using three different tables.

if you can make a sample that demonstrates this please make a case.

Hello everybody,

I’ve just started using Servoy 4.0 and it is of my understanding that setAutoSave is used like a flag to turn on and off the saving of transactions.
I’ve been working on a solution and I’m going crazy.
The reason is that in some of my forms this works great, but just in one of them seems to be working badly as it does not save into de database like it does to most of you.
It will show the new record in a list I’ve created, but once I restart the application it is gone, even if I search for it in the database with a SQL query. So obviously it’s not saving.

Does anybody have a clue to why this is happening and how to solve it???

Thanks

Martin

var didSave = databaseManager.saveData();

what is the value of didSave?

and if that is false what is then the result of databaseManager.getFailedRecords()?

I’ve checked Martin’s solution.

The problem is related to allowed null columns that are not validated into the form.

Regards,

I finally got around to adding a support case with sample app for the problem with saveData(record) on forms that contain subforms in a tabpanel which all use the same table and are self-related (order_to_orders). I needed this functionality and it is a pain to workaround.