Re: Using NOW() with MySQL
[prev]
[thread]
[next]
[Date index for 2004/08/05]
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.
>
>
>
>
|
|
Re: Using NOW() with MySQL
karjala_lists 11:55 on 05 Aug 2004
|