This is probably something really silly, but a quick ping on the ChatterBox didn't show up anything obvious.

I'm trying to use C:DBI to update a field in the database. Here's the outline of the code:

my $groupid = ...; my $newvalue = ...; foreach my $key (@somekeys) { my ($obj) = MyCDBI::Obj->search(groupid => $groupid, userid => $key) +; if (defined $obj) { if ($newvalue eq 'somevalue') { $obj->status(lc $newvalue); } elsif ($newvalue eq 'someothervalue') { $obj->status("something"); } elsif ... ... } print "new value: ", $obj->status; $obj->update; } else { print "Not found"; } }
Now, the code runs, and prints the new value properly. But looking in the database, the new value doesn't get saved.

The definitions: (each in it's own file)

package MyCDBI::DBI; use base 'Class::DBI'; __PACKAGE__->set_db('Main', 'dbi:mysql:cdbidb', 'user', 'pass'); 1; package MyCDBI::Obj; use base 'MyCDBI::DBI'; use Apache::Reload; __PACKAGE__->table('objs'); __PACKAGE__->columns(Primary => qw/userid orgid status/); __PACKAGE__->has_a(userid => "MyCDBI::User"); __PACKAGE__->has_a(orgid => "MyCDBI::Org"); 1;
Other updates (elsewhere in the code, in other pages), do work properly. I'm wondering if this has something to do with the scoping of $obj?

Update: Not sure if this is related, but the 'status' column is an 'enum'. The values I'm trying to assign are valid.

Any hints or suggestions would be very welcome!

-- zigdon


In reply to C:DBI fails to update DB? by zigdon

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.