【发布时间】:2012-08-22 22:45:51
【问题描述】:
我有这个代码:
my (@matches, @vars);
if ($date_to) {
push(@matches, q{ m.mentioned_at <= ? });
push(@vars, $date_to);
}
if ($person) {
push(@matches, q{ t.name like ? });
push(@vars, $person);
}
if ($show) {
push(@matches, q{ t.name like ? });
push(@vars, $show);
}
if (@vars){
my $where = join (' and ', @matches);
$where = qq{where $where} if @matches
$res = $db->do({ page => $.p, per_page => $.s }, q{
select m.id, m.body, m.link,
count(distinct(m.id)) as num_items
from mentions m
$where
group by m.id, m.body, m.link,
order by m.created_at desc
}, @vars );
}
print STDERR Dumper ($where);
$VAR1 = 'where m.mentioned_at <= ? and t.name like ? ';`
print STDERR Dumper (@vars);
$VAR1 = '2012/06/01';
$VAR2 = 'Adby Phil';`
为什么会出现这个错误:
called with 2 bind variables when 0 are needed
Can't use an undefined value as an ARRAY reference
好像没有看到 $where 子句。
【问题讨论】:
-
什么是 $db?这不是典型的 DBI->do call...
-
在
do方法的第二个参数中,您使用q{}引号运算符。变量没有在里面插入,所以你传递了文字字符串$where。这是故意的吗?使用qq{}运算符将$where的内容放入您的查询中。 -
@BrianPhillips,我的 $db = DBIx::DataStore->new('www');
-
@amon - 这应该是一个答案,而不是评论! :-)