[sf-perl] [Fwd: class DBI postgres date time format]

Kevin Frost biztos at mac.com
Thu Mar 19 00:14:19 PDT 2009


It looks like your "updated" column is mapped as a DateTime object  
(line 26).

You probably want to do something like this:

$delta_row->updated( DateTime->now() );

Further resources:

http://search.cpan.org/dist/DateTime/lib/DateTime.pm

http://search.cpan.org/dist/DateTime-Format-Pg/lib/DateTime/Format/Pg.pm

cheers

-- frosty

On Mar 18, 2009, at 4:01 PM, ken uhl wrote:

>
>
> From: ken uhl <kenuhl at berkeley.edu>
> Date: March 17, 2009 11:09:22 AM PDT
> To: beginners at perl.org
> Subject: class DBI postgres date time format
>
>
> How do I set up table class method to correctly format and write  
> 'updated'  column  date and time stamp to postgres?
>
> I have table entry object that contains this - to inflate and  
> deflate :
>
> I think I need to add  "has_timestamp"
> .....
>
>    22 __PACKAGE__->table('dhcpmac');
>    23 __PACKAGE__->columns( Primary => qw/rowid/ );
>    24 __PACKAGE__->columns( All => qw/rowid mac calnetuid updated  
> updatedby dynhostname ishmael disable/ );
>    25
>    26 __PACKAGE__->has_a( updated => 'DateTime',
>    27                     inflate => sub { DateTime::Format::Pg- 
> >parse_timestamptz(shift); },
>    28                     deflate => sub { DateTime::Format::Pg- 
> >format_timestamptz(shift); } );
>
> ...
>
> my CGI  does this :
>
> ...
> #  retrieve old row data    301          my $delta_row =  
> IST::DNSDB::dhcpmac->retrieve($old_rowid) ;
>   302          my $old_mac = $delta_row->mac();
> ...
> #  replace some of the data - including 'updated'
>   305          $delta_row->mac($new_validated_mac);
>   306              $delta_row->updated( "now()" );
> ..
>   308          $delta_row->updatedby($calnetuid);
> ...
>   313           $delta_row->update();
>   314           $delta_row->commit();
>
> ( line 306 crashes with invalid SQL command line value, obviously,  
> but what goes here? )
>
> ?
>
> TIA,
> Ken Uhl,
> UC Berkeley
>
>
>
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20090319/cd7b3d0d/attachment.html>


More information about the SanFrancisco-pm mailing list