Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Log changes in a database (DBI)

by sundialsvc4 (Abbot)
on May 03, 2011 at 12:03 UTC ( [id://902694]=note: print w/replies, xml ) Need Help??


in reply to Log changes in a database (DBI)

If your objective is specifically to give your user a friendly “undo” capability, then you could do this by creating any sort of a table in which you can manage to capture a string of values.   (Placing a JSON-encoded text string in a long-text field comes to mind ... I have not had good experiences with mod:://Storable.)

But you have to think it through very carefully, because database records may well be shared.   In any case they may be visible to many different users, who might therefore see a partially-finished record while your user is deciding exactly what she wants to do.   There could also be conflicts if two users start changing the same record.

When my goal is specifically “undo,” one thing that I like to do is to capture the original record values and all of the subsequent changes that the user may make to those values, (only) in the “undo” record stack, which is distinct for each user session.   If the user finally decides to save the record, I compare the existing record to the one that is in the database (to guard against changes by other users), then apply the changes from the latest version in the “undo” stack.   The underlying record does not change until, and unless, the user accepts whatever changes she has made ... thus replicating the behavior that folks are used-to from working with disc documents.   Since you have access to the initial version, the final version, and every change in-between, you can also be pretty “smart” about conflict resolution and so-on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://902694]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found