Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

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

  1. #11
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,746
    Quote Originally Posted by avianmanagement View Post
    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?
    Hi David,

    Yes - for both DBC_BEFOREUPDATE and DBC_AFTERUPDATE the program is
    Quote Originally Posted by yvonne.milne View Post
    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.
    For the desktop, DBC_BEFOREUPDATE will allow you to use SCATTER and compare the record's previous values and the current buffered values from an uncommitted change.

    So:

    //DBC_BEFOREUPDATE
    para cDatabase, cTable, cJSON
    if isserver()
    // all the info you need is in the 3rd parameter: cJSON
    else
    // scatter and compare
    endif
    //...

    Regards,

    Yvonne

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

    I assume that the json old data is the value when the client app pulled the record, rather than the actual records on the server at the time the check is made?

    Let's say we have an ordering system and each order has a dispatch date.

    If a date is entered then the onafterupodate sees that a date is there now and it was not before and it prints a dispatch note.

    Two users A and B pull the same record for an order. Both see an empty date in the record on the client side. User A enters a dispatched data and saves the record.

    The system sees that the old value for the date was empty and so prints a dispatch note.

    User B now enters a date and saves his record. His old date on the client side is empty and so if the json were from the client side it would print the dispatch note again.

    I need to check the data being saved against the actual record on the server at the time of the onafterupdate fires.

    Am I thinking correctly that the json is all from the client side and not the actual data on the server at the time of the check?

  3. #13
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Hank,

    I'll taker a look at these.

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

    User B's update would fail as the olddata no longer matches the record.

    Regards,

    Yvonne

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

    Thank you, that is interesting to know.

    Would the failure occur at the onbeofreupdate level?


    Regards

    David

  6. #16
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Quote Originally Posted by yvonne.milne View Post
    Hi David,

    Yes - for both DBC_BEFOREUPDATE and DBC_AFTERUPDATE the program is

    For the desktop, DBC_BEFOREUPDATE will allow you to use SCATTER and compare the record's previous values and the current buffered values from an uncommitted change.

    So:

    //DBC_BEFOREUPDATE
    para cDatabase, cTable, cJSON
    if isserver()
    // all the info you need is in the 3rd parameter: cJSON
    else
    // scatter and compare
    endif
    //...

    Regards,

    Yvonne
    Hi Yvonne,

    If I scatter in the dbc_beofreupdate can the onafterupdate see and use that object as the check needs to happen only after the record is saved, since for some other reason it might fail to save, such as user has left off a required column entry, in which case no code needs to run.

    Only if the update goes through will the code run that would go off and say print a dispatch note.

    I'd probably create objects of buffered value and previous values and compare those in the onafterupdate

    Regards


    David
    Last edited by avianmanagement; 2022-08-05 at 03:52.

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

    Are there any sample apps in Linaja that have this sort of thing so I can look at how it's done.

    Regards


    David

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

    For the web client, the DBC_BEFOREUPDATE is called before the 'User B' update fails. So, you would actually be better using the DBC_AFTERUPDATE, as the update has then taken place.

    For the desktop client, the database events and table triggers have access to the current environment, so you can check the data, declare public variables accessible to all programs etc.

    Regards,

    Yvonne

  9. #19
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thank you.

    I'll play with this in my test app to get the hang of it.

    Do table onbeforeupdate and onafterupdate triggers would in a similar way, then I can code just at the table level rather than have a load of code in the dbc_onafterupdate which would need to check the table name and run code for each specific table.

    Regards

    David

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

    The table triggers are not passed the parameters.

    The onbeforeupdate table trigger is not called if the web client 'User B' update fails.

    Regards,

    Yvonne

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