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?? |
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.
In Section
Seekers of Perl Wisdom
|
|