Undo changes on form elements and SQLite

Please do not use to report errors- use your regional help desk.
Please mark posts as being for RPG or RDMLX (LANSA) developer.
To subscribe by email, display this forum, scroll to the end and select ‘Subscribe Forum’.
Post Reply
LEBAS
Posts: 23
Joined: Fri May 11, 2012 5:02 pm

Undo changes on form elements and SQLite

Post 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
tsupartono
Posts: 289
Joined: Wed Apr 18, 2012 10:21 am

Re: Undo changes on form elements and SQLite

Post 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.
LEBAS
Posts: 23
Joined: Fri May 11, 2012 5:02 pm

Re: Undo changes on form elements and SQLite

Post 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
tsupartono
Posts: 289
Joined: Wed Apr 18, 2012 10:21 am

Re: Undo changes on form elements and SQLite

Post 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;
LEBAS
Posts: 23
Joined: Fri May 11, 2012 5:02 pm

Re: Undo changes on form elements and SQLite

Post by LEBAS »

Very interesting.

My last question will be: in Studio, what is the purpose of the 'Temporary table' checkbox?
tsupartono
Posts: 289
Joined: Wed Apr 18, 2012 10:21 am

Re: Undo changes on form elements and SQLite

Post 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).
Post Reply