https://phspeed.com/

Wrong record edited when table resultcache=no

VictorUlloa, Tue Oct 01 2024, 12:43PM

Hi,

I have a simple GRID + POPUP FORM app, using a really basic dbtable (three columns, primary key, description and a date).

When the table had resultcache=yes, I select any record with the pencil icon to edit, press on the "Edit" button and then edit the values for the selected record.

But if I set resultcache=no, I can see the selected record in the popup edit window, but when I click on the "Edit" button, the values change to the first record in the table, somehow the dataset is refreshed when pressing the edit button and the wrong record gets edited.

Why put resultcache=no? Because I'm using a user button to change update the date column in the table to the current date, and I want the grid to reload to show the updated values (that does not happens when resultcache=yes, the data in the grid still shows the old date, even when the database is already updated).
Maybe is there an alternative to update the grid data in the onEndProcessRows event?

Hope I made myself clear...

Best regards,
Re: Wrong record edited when table resultcache=no
administrator, Tue Oct 01 2024, 05:36PM

A question: do you have a check-boxed grid with a process button to process the selected records? Or are you just seeking for a way to refresh the grid?
Re: Wrong record edited when table resultcache=no
VictorUlloa, Tue Oct 01 2024, 09:06PM

I have a check-boxed grid (via clicktoselect = true), and a process button. The UPDATE sentence is execute in the onProcessRow event using a simpleDBQuery. Regards,
Re: Wrong record edited when table resultcache=no
administrator, Thu Oct 03 2024, 06:25PM

First, the cached properties applies to lookup situations, where you have to fill drop-downs based on mastertables. Having the data cached will cause the dropdown to be empty after the initial query because the related data cannot be found in the cached dataset. Do not use on master datasets.

To refresh your form, simply close the dataset like in the following example:

//
function dbgrid_1_onProcessRow($app, $row, $sender, $buttonid)
{
   $sql='update employees set upddate=:upd where emp_no=:emp';
   $$qq->sql=$sql;
   $$qq->SetStringFieldByName(':upd', $$calendar_1->value);
   $$qq->SetStringFieldByName(':emp', $row['employees_emp_no']);
   $$qq->SimpleExecSQL();
   $$dbtable_1->Close();
}

The basic query is executed, as the update does not apply to the cached table. The main reason is that there could be triggers on the master table that otherwise would not affect the shown data.