Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
Now say I have a web interface to edit/update those relationships, which brings all of a person's details into one form.TABLE 'People': NAME ID --------- Alice 1 Bob 2 TABLE 'Qualifications': QUAL ID --------- MA 1 MSc 2 PhD 3 TABLE 'people_who_have_qualifications': PERSON QUAL 1 1 # Alice has an MA 1 3 # Alice also has a PhD 2 2 # Bob has an MSc.
When Bob gets his PhD or I realise Alice's MA was a data entry error and should be a BA, I need to edit their record and save in a way that updates that 'people_who_have_qualifications' table.
The simplest way to do that, it seems to me, is to just delete everything and then re-enter it. First pass, Alice has no qualifications at all. Then, second pass, we read off the CGI param()s we got from our checkboxes and put her qualifications back in.
Now, it's kind of inefficient, because every time we edit Alice's record, we're deleting everything and re-inserting it. And of course if the network/db server/script hits a problem between the first and second pass we've got missing data.
But if I don't do that I have to tiresomely look up and compare every value already in the db with the values in the CGI param()s. "Is this value there in the db and in the form? Leave it alone. Is it there in the db but not in the form? Delete it. Is it in the form but not in the db? Insert it." Lots more database activity in total, lots more scripting, etc.
I guess what I'm asking is, Is the "delete all, re-insert" method good laziness, à la Larry, or bad?
Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OT: updating database question
by revdiablo (Prior) on Jul 22, 2007 at 07:58 UTC | |
by apl (Monsignor) on Jul 22, 2007 at 12:37 UTC | |
|
Re: OT: updating database question
by Conrad.Irwin (Novice) on Jul 22, 2007 at 20:27 UTC | |
|
Re: OT: updating database question
by graff (Chancellor) on Jul 23, 2007 at 02:58 UTC | |
by herveus (Prior) on Jul 23, 2007 at 11:51 UTC | |
|
Re: OT: updating database question
by Cody Pendant (Prior) on Jul 23, 2007 at 23:37 UTC | |
|
Re: OT: updating database question
by poqui (Deacon) on Jul 23, 2007 at 21:18 UTC |