Re: Using NOW() with MySQL

[prev] [thread] [next] [Date index for 2004/08/05]

From: karjala_lists
Subject: Re: Using NOW() with MySQL
Date: 11:55 on 05 Aug 2004
I don't know about NOW() and how to use it, but my solution to this is 
to use Class::DBI::mysql, and write:

<%once>
use Time::Piece;
</%once>

and then, inside the component:

$t = localtime;
Some::Class->create({ somekey => somevalue, created => $t });

...and also in the class declarations in the ::DBI file:

__PACKAGE__->autoinflate(dates => 'Time::Piece');



tom@xxxxxxxx.xxx wrote:

>Hi.
>
>This seems like a terrible question to ask, but I have read through the FAQ, the perldoc, googled and have tried as many ways as I can find in any documentation to get Class::DBI to pass "NOW()" to MySQL as a column value that will make mySQL insert the current date.
>
>SQL that I want: INSERT INTO note ('foreignKey', 'note', 'created')
>                        VALUE (1, 'some note', NOW());
>
>This is my current incarnation.
>
>package My::Base;
>
>use base 'Class::DBI';
>Table::Homelet->connection( "string", "name", "pass" ); #paraphrased.
>
>__PACKAGE__->set_sql(setAsNow => <<"");
>UPDATE __TABLE__
>SET %s = NOW()
>WHERE __IDENTIFIER__
>1;
>
>package Note;
>require My::Base;
>
>Note->table('note');
>Note->columns(All => qw/id, foreignKey, created, note/ );
>
>my $newNote = My::Base->create(
>                { foreignKeyId = 1,
>                  note       => 'some note'
>                } );
>$newNote->sql_setAsNow("created");
>1;
>
>
>I have tried all sorts of variations, amazed that I could not just hadd the key-value pair created=>NOW() into the create hash.
>
>Surely I am missing something very simple?
>
>Thanks.
>
>
>  
>


Using NOW() with MySQL
tom 11:46 on 05 Aug 2004

Re: Using NOW() with MySQL
karjala_lists 11:55 on 05 Aug 2004

Re: Using NOW() with MySQL
karjala_lists 12:15 on 05 Aug 2004

Re: Using NOW() with MySQL
Tony Bowden 12:02 on 05 Aug 2004

Re: Re: Using NOW() with MySQL
tom 16:04 on 06 Aug 2004

Re: Re: Using NOW() with MySQL
Tony Bowden 16:26 on 06 Aug 2004

Re: Re: Using NOW() with MySQL
Tim Bunce 16:30 on 06 Aug 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52