Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: What is the best way in Lianja to check changes to column after update

  1. #1
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657

    What is the best way in Lianja to check changes to column after update

    I have two columns on a table which are datatime

    After the user makes changes and saves the record I need to check if the value of these now have an entries, or the entries have changed form their original values.

    If they has then I will run some code to update other tables, such as adding a new chick to stock if the datetime is empty before and now has a hatch date.

    What is the best way in Lianja to check in the onafterupodate call on the table for this?

    I'm thinking of using the onbeforeupdate to store the value to Lianja.localstorage.aim.thatchfrom and Lianja.localstorage.aim.thatchto

    The checking these values in the onafterupodate and comparing them to the current values.

    Or is there a simpler / better way to do this?

  2. #2
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,746
    Hi David,

    You can associate a program with the DBC_AFTERUPDATE database event triggered after an update operation. It gets passed the database name, table name and (when update initiated from web/mobile) a JSON string with the new and old data for the record.

    DBC_AFTERUPDATE database event
    All Database Events

    Regards,

    Yvonne

  3. #3
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Yvonne,
    Yes I was going to have a prg called onafterupdate_degg and set that at the database level

    I want to use this for both web and desktop however.

    Some of my users will be only too happy to use it on the web, but some will want a desktop app due to concerns over data and access with poor internet access.

    So I want to look for a way to save / refer to the value before the update occurred so I can use it in desktop as well.

    In my current vfp application we have an oldrecord object that we use for this.

    I could do the same I guess on the beforeupdate and store it in Lianja.localstorage.aim.oldRecord_degg

    Is that a good way to do it in Lianja or does it have built in better ways?

    Regards

    David

  4. #4
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,746
    Hi David,

    Note that the database events are separate to the table triggers.

    The ISSERVER() function allows you to determine whether the code is running on the desktop or via the Lianja Server, so one program can handle both scenarios.

    In the DBC_BEFOREUPDATE database event you could compare the objects for the desktop from SCATTER objects:

    Code:
    scatter oldvalues name <object>
    and

    Code:
    scatter name <object>
    Regards,

    Yvonne

  5. #5
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Hi Yvonne,

    Thank you for that.

    I was thinking of table triggers I think.

    Using scatter I think I woudl need to determine if I am in desktop of web.

    My thinking on using the Lianja.localstorage.aim.oldRecord_degg approach was that I just have oen piece of code fal all, I think.

    Regards

    David

  6. #6
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,889
    Blog Entries
    18
    HI David

    the triggers run on the server.

    localestorage resides on the client.

    Yvonne mentioned using the isServer() function to determine whether it’s desktop or a web request.
    Last edited by barrymavin; 2022-08-04 at 12:06.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  7. #7
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Barry,

    I'll use the isServer() and have two sets of code then to determine the values to run as triggers on the server

  8. #8
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Is there any advantage to using DBC_BEFOREUPDATE as opposed to table triggers of onbeforeupdate

    I assume both run on the server.

    In web apps if I scatter the name record to a named object is that object then on the server or on the client?

  9. #9
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,161
    Hi David,

    The scattered object is on the server. Assuming you made a call to the server from the web client to make this happen, you can json_encode() this object and return it as the return value for the call made from the JS on the client. In the JS script you can JSON_Encode the object and then base64_encode the JSON (to prevent illegal chars in the transmitted string back to the client) and then reverse the process on the client.

    Hank

    Hank

  10. #10
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,161
    In JS, you can use Lianja.getCursor("<table>") to get the cursor at the time you want to check.

    The cursor object's Values property returns an object with the field names and values.

    The cursor object's ChangedValues property returns an object with the former and current values for all fields that have changed.

    The only thing better would be if the ChangedValues also had the original value before editing -- but you can use the values property before editing and compare with the ChangedValues and get the same result.

    Hank

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us