Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Best way to check which field(s) was changed

by ccn (Vicar)
on Dec 29, 2008 at 18:05 UTC ( [id://733086]=note: print w/replies, xml ) Need Help??


in reply to Best way to check which field(s) was changed

This query: "UPDATE table_name SET column_name=$inputUpdate[0] WHERE column_name=$input[1]" can update more than one rows at once! Probably it is not what you want. There some unique index column must be used for update.

I suggest to have two hashes: %input, and %inputUpdate instead of arrays. Those hashes contain ColumnName => value pairs.

Than, assuming ID is identity column:

my %update = map {$_ => $inputUpdate{$_} } grep {$inputUpdate{$_} ne $input{$_} } keys %input; $dbh->do(<<"SQL", undef, values %update, $input{ID}); update TableName set @{[ join ', ', map {"$_ = '?'"} keys %update]} where ID = ? SQL $dbh->commit;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found