Perl的DBD :: MySQL的执行不支持限制关键字后面的字符串参数。始终被视为号码

问题描述 投票:0回答:2

我们最近成立了一个新的操作系统,最多最新的MySQL的DBI,Perl等

这种模式在发现了几个我们的应用程序,并当上了新的操作系统安装的断裂。

my $sth = $dbh->prepare('select null colname, null colname2 limit 0'
        . ' union all select x, y from tbl where col like ?'
        . ' union all select z, a from tbl2 where col like ?');
$sth->execute('%test%', '%test%') or die ...;

错误是MySQL的语法错误。我们已经确定了在路上的参数被引用的问题。

在上面的例子,它可以解决像这样在MySQL的。

select null colname, null colname2 limit 0
union all select x, y from tbl where col like 
union all select z, a from tbl2 where col like 

然而,如果'%test%'与数字换出(例如'555'),它涉及通过。

select null colname, null colname2 limit 0
union all select x, y from tbl where col like 555
union all select z, a from tbl2 where col like 555

请注意,没有引号。

我们已经确定了这是被相关limit关键词的存在。卸下关键字解决了语法错误。

select null colname, null colname2
union all select x, y from tbl where col like '%test%'
union all select z, a from tbl2 where col like '%test%'

此外,在Perl设置'555'现在导致'555'在MySQL中,带引号的。

我们发现,使用派生的表,现在要解决的最快捷的方式,

select * from (select null colname, null colname2 limit 0)a
union all select x, y from tbl where col like '%test%'
union all select z, a from tbl2 where col like '%test%'

(试过只是括号,但需要派生表的工作),但我很好奇,如果有通过DBI / DBD控制标价法:: MySQL的接口,而不是一个办法。 (避免的更新语句)

要么改变默认的行为禁用limit关键字逻辑 或者,以迫使特定参数类型为字符串?

mysql perl limit quotes sanitization
2个回答
4
投票

含LIMIT命令的解析是越野车。尝试DBD::MariaDB代替已经希望已经解决了该问题(here)。


0
投票

请问您更新OS包括一个更新的MySQL版本?该documentation for UNION in MySQL这样说:

通过或LIMIT应用于为了将个人选择,将围绕该SELECT括号内的条款:

(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);

和这个:

要使用ORDER BY或LIMIT子句来进行排序或限制整个UNION结果,圆括号个人SELECT语句并把ORDER BY或LIMIT最后一个之后。下面的示例使用这两种条款:

(SELECT a FROM t1 WHERE a=10 AND B=1)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;

所以,我认为你需要一些括号添加到您的SQL。

© www.soinside.com 2019 - 2024. All rights reserved.