Servoy 3.5.2 not saving when database indentity pks?

Hi all,

we have switched one of our systems to Servoy 3.5.2. We use PostgreSQL and database identities for our key generation. This works as long as out PostgreSQL sequences are named

tablename + ‘_’ + pk_name + ‘_seq’.

If I do a

controller.newRecord();
some_field = "Hello"

and assign a few values to fields in the record, the values don’t stick (save) unless immediately call databaseManager.saveData();

controller.newRecord();
databaseManager.saveData();
some_field = "Hello"

after creating the record.

Is this expected behaviour when using database identities?

Yes, it is. This is also very important once you start to touch a relation that needs the primary key of the parent table. Only a Servoy sequence is reliably available immediatly after a newRecord().

Hi Patrick,

thanks for confirming this.

We will make sure we add a databaseManager.saveData() call immediately after creating any record that may have child records.

Christian,

When you use database identities, the pk is not known until the record is saved.
First we do an insert into the table without listing the pk :insert into mytab (field1, field2) values (?, ?)
Next we retrieve the newly generated pk value from the db, for instance in postgres we call :select currval(‘mytab_mytab_id_seq’)

The assigned values should still stick without calling saveData().
Can you create a small sample solution that shows how it is not sticking?

Rob

Hi Rob,

thank you for your concern! No need to worry.

I had left out the databaseManager.saveData() call.
Once I added it everything worked as expected.

I have also realised I need to add a save after duplicating records.

Christian

Hi Rob,

thank you for your concern! No need to worry.

I had left out the databaseManager.saveData() call.
Once I added it everything worked as expected.

I have also realised I need to add a save after duplicating records.

Christian