为什么 Perl 的 DBIx::Class $resultset->update 在复杂的搜索查询上失败?

发布于 2024-08-19 18:47:56 字数 1409 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文