Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Use mysql NOW() fuction from DBIx::Class

by alfarid23 (Initiate)
on Jul 16, 2007 at 01:08 UTC ( #626756=perlquestion: print w/ replies, xml ) Need Help??
alfarid23 has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm using DBIx::Class, and I'm fairly new to it. I'm trying to figure out how to update column value in a table with output of mysql NOW() function. Basically i just want to execute NOW() function in scalar context, capture output and update row. thank you

Comment on Use mysql NOW() fuction from DBIx::Class
Replies are listed 'Best First'.
Re: Use mysql NOW() fuction from DBIx::Class
by haoess (Curate) on Jul 16, 2007 at 07:03 UTC

    You can use NOW() in your UPDATE-clause:

    my $item = ...; $item->update({ time_column => \'NOW()', # more columns here });

    -- Frank

      Yep, a scalar reference passes a literal string to the SQL, rather than a bind variable.
Re: Use mysql NOW() fuction from DBIx::Class
by snopal (Pilgrim) on Jul 16, 2007 at 02:19 UTC

    You are asking a MySQL question.

    'SELECT NOW()' returns the value you seek.

    Also, MySQL offers a timestamp field for just such a purpose, so that you don't have to pre-acquire the date.

    You can construct a date value creating the well documented date syntax by the results of localtime.

    Take your choice.

      I think what snopal mentions is that while creating the table you can specify the column type as TIMESTAMP in MySQL. So then when you dealing with the table in Perl or whatever you can just ignore that column and go on working. On insertion of any value into the table, MySQL puts the time at that instant into the DB.

      If this is not you are asking, pardon me.
      He really is asking a DBIx::Class question. He doesn't know how to make DBIx::Class run that SQL. I don't either, but I would ask on the DBIx::Class mailing list rather than here.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-10-10 01:27 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (254 votes), past polls