开发者

right-hand-side MySQL functions in DBIx::Class

开发者 https://www.devze.com 2022-12-12 01:04 出处:网络
In DBIx::Class, when I generate a query using this syntax: ... \'Time(submitted_at)\' => { \'>\' => \'Time(Now()-Interval \' . $wait_period . \' minute)\' }

In DBIx::Class, when I generate a query using this syntax:

...
'Time(submitted_at)' => { '>' => 'Time(Now()-Interval ' . $wait_period . ' minute)' }
...

The generated query is perfect except for the fact that the function on the right hand side is in quotes.

... AND ( Time(submitted_at) > 'Time(Now()-Interval 5 minute)' ) ...

If it was not quoted then开发者_高级运维 it would be correct. How would I do that?

Thanks, Rob


It seems that the way to do expressions is to pass a scalar ref or array ref if you want to use literal SQL.

Here's an example showing using a query parameter for the $wait_period variable into the expression:

...
'Time(submitted_at)' => { '>' => \['Time(Now()-Interval ? Minute)', $wait_period] }
...


Pass the string as a scalar reference instead:

...
'Time(submitted_at)' => \"> Time(Now()-Interval $wait_period minute)" 
...
0

精彩评论

暂无评论...
验证码 换一张
取 消