zigdon has asked for the wisdom of the Perl Monks concerning the following question:
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:
Now, the code runs, and prints the new value properly. But looking in the database, the new value doesn't get saved.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"; } }
The definitions: (each in it's own file)
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.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;
Any hints or suggestions would be very welcome!
-- zigdon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: C:DBI fails to update DB?
by perrin (Chancellor) on Sep 28, 2004 at 21:22 UTC | |
by zigdon (Deacon) on Sep 29, 2004 at 12:46 UTC | |
Re: SOLVED: C:DBI fails to update DB?
by zigdon (Deacon) on Sep 30, 2004 at 13:00 UTC |