Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Class::DBI misbehaviour

by TVSET (Chaplain)
on Mar 11, 2004 at 10:54 UTC ( #335760=perlquestion: print w/ replies, xml ) Need Help??
TVSET has asked for the wisdom of the Perl Monks concerning the following question:

Hello All. I've encountered a very strange behavior from Class::DBI. It does work with the rest of the project, but in this particular case it simply doesn't and I cannot find any changes that I did that could cause it. No errors or warning appear, code executes just fine, but the database is not updated. I've readmore-ed the details to protect the innocent. :)
Here are the definitions:
use base 'Intranet::DBI'; __PACKAGE__->table('noc_schedule'); __PACKAGE__->columns(Primary => qw/id/); __PACKAGE__->columns(Essential => qw/ caption starts ends active locked monday tuesday wednesday thursday friday saturday sunday holiday last_modified /);
Here is the relevant peice of code:
unless (@errors) { my $shift = $self->retrieve($args->{'id'}); print "DEBUG(before update): ",Dumper($shift),"<BR>\n"; $shift->caption($args->{'caption'}); $shift->starts($args->{'starts'}); $shift->ends($args->{'ends'}); $shift->monday($args->{'monday'}); $shift->tuesday($args->{'tuesday'}); $shift->wednesday($args->{'wednesday'}); $shift->thursday($args->{'thursday'}); $shift->friday($args->{'friday'}); $shift->saturday($args->{'saturday'}); $shift->sunday($args->{'sunday'}); $shift->holiday($args->{'holiday'}); print "DEBUG(while update): ",Dumper($shift),"<BR>\n"; $shift->update; print "DEBUG(after update): ",Dumper($shift),"<BR>\n"; }
And here is the output of those Dumpers:
DEBUG(before update): $VAR1 = bless( { 'holiday' => '16', 'sunday' => +'16', 'locked' => '0', 'friday' => '18', 'last_modified' => '20040311 +080038', 'active' => '0', 'tuesday' => '18', 'monday' => '18', 'ends' + => '22:59:00', 'starts' => '22:58:00', 'caption' => 'Copy of Other', + 'saturday' => '16', 'wednesday' => '18', 'thursday' => '18', 'id' => + '21' }, 'Intranet::NOC::Shift' ); DEBUG(while update): $VAR1 = bless( { 'holiday' => '16', 'sunday' => ' +16', 'locked' => '0', 'friday' => '18', 'last_modified' => '200403110 +80038', 'active' => '0', 'tuesday' => '18', 'monday' => '18', 'ends' +=> '15:00:00', 'starts' => '13:00:00', 'caption' => 'test', 'saturday +' => '16', 'wednesday' => '18', 'thursday' => '18', '__Changed' => { +'holiday' => 1, 'sunday' => 1, 'starts' => 1, 'caption' => 1, 'saturd +ay' => 1, 'friday' => 1, 'wednesday' => 1, 'thursday' => 1, 'tuesday' + => 1, 'monday' => 1, 'ends' => 1 }, 'id' => '21' }, 'Intranet::NOC:: +Shift' ); DEBUG(after update): $VAR1 = bless( { 'locked' => '0', 'last_modified' + => '20040311080038', 'active' => '0', 'id' => '21' }, 'Intranet::NOC +::Shift' );
Any help with this will be greatly appreciate, because I, for one, am going totally nuts. :)

Comment on Class::DBI misbehaviour
Select or Download Code
And the logs say (let's not jump to conclusions)?
by PodMaster (Abbot) on Mar 11, 2004 at 11:24 UTC
    And what do the logs say? See "DEBUGGING" in the DBI documentation (and check your database's logs). I would strongly hesitate to blame Class::DBI just yet.

    UPDATE: *sigh* but before you do that, which version of Class::DBI do you have? Do you have transactions turned on? What does update return? Do you have any update triggers?

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks a lot! ;)

      The problem was that out of the code that I copy-pasted (as usual). Stupid me called one method get(). Class::DBI's behavior became very logical when I figured it out.

Re: Class::DBI misbehaviour
by matija (Priest) on Mar 11, 2004 at 12:00 UTC
    From the Class::DBI manpage:

    Note: If you have transactions turned on for your database (but see "TRANSACTIONS" below) you will also need to call dbi_commit(), as update() merely issues the UPDATE to the database).

      I don't use transactions. And there is a terribly similar piece of code that works in a nearby file. ;)
Re: Class::DBI misbehaviour
by liz (Monsignor) on Mar 11, 2004 at 12:52 UTC
    FWIW, I would write this code:
    $shift->caption($args->{'caption'}); $shift->starts($args->{'starts'}); $shift->ends($args->{'ends'}); $shift->monday($args->{'monday'}); $shift->tuesday($args->{'tuesday'}); $shift->wednesday($args->{'wednesday'}); $shift->thursday($args->{'thursday'}); $shift->friday($args->{'friday'}); $shift->saturday($args->{'saturday'}); $shift->sunday($args->{'sunday'}); $shift->holiday($args->{'holiday'});
    as:
    $shift->$_( $args->{$_} ) foreach qw( caption starts ends monday tuesday wednesday thursday friday saturday sunday holiday );
    You're specifying things twice (name of method and name of field in hash), which is always bad from a maintenance point of view.

    Also, I find the use of $shift confusing: usually a variable called $self is a more common idiom.

    Liz

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://335760]
Approved by Tomte
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-22 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls