[Dbix-class] setting SQL function

Mark Hedges hedges at ucsd.edu
Mon Apr 10 22:51:16 CEST 2006


Sorry I've missed how to do this.  I want to set columns to raw 
SQL.  For instance, I want to set a datetime field to sql 
'now()' (i.e. 'CURRENT_TIMESTAMP()').  

In mysql type 'timestamp' fields do the right thing if you set 
the value to undef, but type 'datetime' fields do not, and you 
cannot set a default value to CURRENT_TIMESTAMP for them like 
you can for type 'timestamp' fields.

I could always create a DateTime->now() object and plug it into 
the field when I create it (or do this as a default value in an 
overloaded 'new()' subroutine for the class.  But this seems 
less efficient than (and slightly asynchronous from) SQL now().
Or I could make this a timestamp column.  But setting direct SQL 
in $row->new({ }) could be useful in other ways.  Possible?

Mark



More information about the Dbix-class mailing list