为什么下面的代码出现以下错误? [英] Why the following error apperas for the below code?
本文介绍了为什么下面的代码出现以下错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DBI fetchall_hashref:无效的参数数量:得到句柄+ 0,预期句柄+ 1到1
用法:$ h-> fetchall_hashref($ key_field)
我的尝试:
sub pending_running_partition
{
my $ str = shift;
$ DBH =& connect或die无法连接到sql server \ n;
$ DBH-> do(USE $ str;);
my $ stmt =select rowc,jobs_pending,jobs_running from queues order by time desc;;
我的$ sth = $ DBH-> prepare($ stmt);
$ sth-> execute()或printcould not prepare_overall_queues_data;
我的%TABLE_DATA =();
my @sys = qw / Adice Incisive Caliber Vcs others /;
my $ table = $ sth-> fetchall_hashref;
我的$ r(@ $ table){
my $ name ='others';
打印$ name;
for my s(@sys){
if($ r-> {queue_name} = ~m / $ s / i){$ name = $ s;最后一个;}
}
$ TABLE_DATA {$ name} {jobs_pending} + = $ r-> {jobs_pending};
$ TABLE_DATA {$ name} {jobs_running} + = $ r-> {jobs_running};我的$ var(qw /正在等待/){
my @ parts =();
}
for my $ s(@sys){
push @parts,'['。$ s。','
。$ TABLE_DATA {$ s} {'jobs _'。$ var}
。']';
}
}
}
解决方案
h-> fetchall_hashref(
key_field)
我尝试过:
sub pending_running_partition
{
my
str = shift;
DBI fetchall_hashref: invalid number of arguments: got handle + 0, expected handle + between 1 and 1 Usage: $h->fetchall_hashref($key_field)
What I have tried:
sub pending_running_partition { my $str=shift; $DBH=&connect or die "cant connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select queue_name,jobs_pending,jobs_running from queues order by time desc;"; my $sth=$DBH->prepare($stmt); $sth->execute() or print "could not prepare_overall_queues_data"; my %TABLE_DATA=(); my @sys=qw/Adice Incisive Calibre Vcs others/; my $table = $sth->fetchall_hashref; for my $r (@$table) { my $name='others'; print $name; for my $s (@sys){ if ($r->{queue_name}=~m/$s/i) {$name=$s; last;} } $TABLE_DATA{$name}{jobs_pending}+=$r->{jobs_pending}; $TABLE_DATA{$name}{jobs_running}+=$r->{jobs_running}; } for my $var(qw/running pending/) { my @parts=(); for my $s (@sys){ push @parts,'["'.$s.'",' .$TABLE_DATA{$s}{'jobs_'.$var} .']'; } } }
解决方案
h->fetchall_hashref(
key_field)
What I have tried:
sub pending_running_partition { my
str=shift;
这篇关于为什么下面的代码出现以下错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文