Greetings Monks,

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


In reply to Class::DBI question by freddo411

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.