freddo411 has asked for the wisdom of the Perl Monks concerning the following question:
I'm using Class::DBI in my perl code to provide an OO interface to my simple DB table. The application is a classic CRUD pattern (create/retrieve/update/delete).
I've successfully set up my table, and have retrieved data, created data, and deleted data. I'm having trouble figuring how to update a record with the OO methods. The Class::DBI docs show only one example of an update, and in that one it simply updates a single field. I have a hash containing fieldnames/values and would like to pass it all at once.
Can anyone provide an example, or point me to method code to accomplish this?
# Various stuff above to use Class::DBI and set it up # verified to work by retrieving # Put the validated fields into the DB # New, unique ID number is automagically generated # if needed my $hashref = $results->valid; my %hash = %$hashref; my $foo = $hash{'id'}; carp "ID is: $foo "; my $entry = Contacts->find_or_create( id => $foo ); $entry->$hashref; # this doesn't work $entry->dbi_commit(); $entry->update;
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI question
by perrin (Chancellor) on Oct 20, 2003 at 21:32 UTC | |
by freddo411 (Chaplain) on Oct 20, 2003 at 22:06 UTC | |
by PodMaster (Abbot) on Oct 20, 2003 at 23:32 UTC | |
by freddo411 (Chaplain) on Oct 21, 2003 at 00:16 UTC | |
|
Re: Class::DBI question
by set_uk (Pilgrim) on Oct 21, 2003 at 10:13 UTC |