[Dbix-class] SQL Function in update
Ronald J Kimball
rkimball+dbixclass at pangeamedia.com
Mon Mar 31 16:33:19 BST 2008
My example using NOW() was just to show that I already know about the
usual solution (ref to string) for this problem. I am already using
DateTime as you suggest.
I'm calling GREATEST so that the value of paused_until will only be
updated if the new value is greater than the current value.
thanks,
Ronald
Hartmaier Alexander wrote:
> Hello Ronald!
>
> In my opinion ist better to fetch the datetime in your model to be database
> function independent and pass that to update and let the database specific
> deflator make what it's best at:
>
> $row->mydate(DateTime->now( time_zone=> 'UTC' ));
> $row->update;
>
> or
>
> $row->update(mydate => DateTime->now(time_zone=> 'UTC' ));
>
> What should GREATEST do in your case?
>
> -Alex
>
> -----Original Message-----
> From: Ronald J Kimball [mailto:rkimball+dbixclass at pangeamedia.com]
> Sent: Monday, March 31, 2008 5:03 PM
> To: dbix-class at lists.rawmode.org
> Subject: [Dbix-class] SQL Function in update
>
> Yes, it's another question about using SQL functions in an update. I
> know I can pass a reference to a string containing literal SQL, as in:
>
> $row->update({ mydate => \ 'NOW()' });
>
>
> However, in this case I need to pass arguments to the function, one of
> which needs to be quoted. Here's what I'm using right now:
>
> my $date = DateTime->now();
> my $until = "GREATEST(paused_until, " .
> $schema->storage->dbh->quote("$dt") . ")";
>
> $row->update({ paused_until => \$until });
>
>
> Ideally, I could do something like this:
>
> $row->update({ paused_until =>
> { GREATEST => [ \ 'paused_until', $dt ] } });
>
>
> Suggestions?
>
> Ronald
More information about the DBIx-Class
mailing list