为什么 Perl 的 DBIx::Class $resultset->update 在复杂的搜索查询上失败?
我有一个 Perl DBIx::Class 搜索,看起来像这样:
my $rs = shift->search( {
-and => [
{ 'for_revocation' => 1 },
[
{
status => {
'not_in' => [ 'revoked', 'revoking']
},
},
{
status => 'revoking',
updated => {
'<' => \'now() - interval 1 hour'
}
},
]
]
});
然后我就这样做了..
$rs->update({ status => 'revoked' });
但我收到错误...
DBI 异常:DBD::mysql::st 执行 失败:您的 SQL 中有错误 句法;检查手册 对应你的MySQL服务器 正确使用语法的版本 第 1 行“FOR REVOCATION '1')”附近 [for 语句“更新 wmv_attempt SET 状态=?哪里(数组(0xadf93a8) 想要撤销? )" 与 ParamValues: 0='撤销', 1=1] 在 (eval 20938) 第 1 行
如果我使用 $rs->as_query()
来获取用于执行搜索的 SQL,它看起来像这样:
SELECT .... FROM wmv_attempt me WHERE ( ( ( status NOT IN ( ?, ? ) OR ( status = ? AND
updated < now() - interval 1 hour ) ) AND for_revocation = ? ) )
效果很好。
似乎当它对结果集执行 update()
时,它无法正确创建 WHERE 子句。
我怀疑这是一个错误。
谁能建议我可能做错的事情或替代方法?
谢谢,汤姆
I have a Perl DBIx::Class search the looks like this:
my $rs = shift->search( {
-and => [
{ 'for_revocation' => 1 },
[
{
status => {
'not_in' => [ 'revoked', 'revoking']
},
},
{
status => 'revoking',
updated => {
'<' => \'now() - interval 1 hour'
}
},
]
]
});
and then I do ..
$rs->update({ status => 'revoked' });
But I get the error ...
DBI Exception: DBD::mysql::st execute
failed: You have an error in your SQL
syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'FOR REVOCATION '1' )' at line 1
[for Statement "UPDATE wmv_attempt SET
status = ? WHERE ( ARRAY(0xadf93a8)
FOR REVOCATION ? )" with ParamValues:
0='revoking', 1=1] at (eval 20938)
line 1
If I use $rs->as_query()
to get the SQL used to do the search it looks like this:
SELECT .... FROM wmv_attempt me WHERE ( ( ( status NOT IN ( ?, ? ) OR ( status = ? AND
updated < now() - interval 1 hour ) ) AND for_revocation = ? ) )
Which works fine.
It seems that when it does the update()
on the resultset it fails to be able to create the WHERE clause correctly.
I suspect this is a bug.
Can anyone suggest something I might be doing wrong or an alternative approach?
Thanks, Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论