[Dbix-class] setting SQL function
Matt S Trout
dbix-class at trout.me.uk
Mon Apr 10 22:58:50 CEST 2006
Mark Hedges wrote:
> 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.
timestamp DEFAULT now()
?
> 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?
my $obj = $rs->new_result({ created => \'now()' });
$obj->insert;
$obj->discard_changes;
might work (I have an awful cold today so I may be off there).
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list