Page 1 of 1
Undo changes on form elements and SQLite
Posted: Tue Jan 28, 2014 1:52 am
by LEBAS
Hi,
In a local form executed in Offline mode (airplane mode), I display some form elements bound to values of an SQLite table. I can modify the values of these form elements, so values in the SQLite table are automatically updated.
If by mistake I clear the values of some form elements (salary, address…), how can I undo these changes and redisplay the original values?
In RPG or LANSA, has somebody tried solutions like:
• SQLite transactions with commit/rollback,
• Intermediate table or Temporary table,
• Other…
Regards,
Yann
Re: Undo changes on form elements and SQLite
Posted: Tue Jan 28, 2014 7:53 am
by tsupartono
Currently there is no mechanism that would do that automatically for you.
One approach is to use temporary table when in edit mode:
- Copy the record being edited to the temporary table.
Bind that temporary record to the elements.
Upon save, copy that record to the actual table, or do nothing if user selected cancel.
Re: Undo changes on form elements and SQLite
Posted: Tue Jan 28, 2014 7:20 pm
by LEBAS
Thanks Tony,
To use a Temporary table, I suppose I have to define it in LongRange Studio and check its 'Temporary table' checkbox.
But I don't know how a Temporary table works within LongRange:
- What is its scope of life, i.e. when is it created, deleted?
- Do I have to manually delete records I have added in the table or is the table automatically cleared and when?
Regards,
Yann
Re: Undo changes on form elements and SQLite
Posted: Wed Jan 29, 2014 8:01 am
by tsupartono
In this case, it does not actually really matter if you define the table or "temporary" table or not in Studio, as you would only be keeping one row in your temporary table (that is, you would be keeping the row the user is currently editing) - so you can just delete all the rows in the temporary table before inserting a new row.
For example, if you have an EMPLOYEE table, and you want to make a copy of a row the user is currently editing, you can create another table called EMPLOYEE_TEMP.
To copy the current record to the EMPLOYEE_TEMP table (first clearing the EMPLOYEE_TEMP table):
Code: Select all
DELETE FROM EMPLOYEE_TEMP;
INSERT INTO EMPLOYEE_TEMP(ROWID, EMPNO, NAME) SELECT ROWID, EMPNO, NAME FROM EMPLOYEE WHERE ROWID = &(FLD:ROWID);
To copy the record from EMPLOYEE_TEMP back to EMPLOYEE table (use REPLACE INTO):
Code: Select all
REPLACE INTO EMPLOYEE(ROWID, EMPNO, NAME) SELECT ROWID, EMPNO, NAME FROM EMPLOYEE_TEMP;
Re: Undo changes on form elements and SQLite
Posted: Wed Jan 29, 2014 8:20 pm
by LEBAS
Very interesting.
My last question will be: in Studio, what is the purpose of the 'Temporary table' checkbox?
Re: Undo changes on form elements and SQLite
Posted: Thu Jan 30, 2014 7:47 am
by tsupartono
Table indicated as 'temporary' in Studio will have its content automatically erased when the database becomes free (that is, when no forms or operations are referring to the database).