下面的代码应打印10个结果,但它会打印10个“test-ite”。为什么它没有显示从数据库中获得的结果?
use Data::Dumper;
use POE;
use POE qw( Component::Pool::DBI );
POE::Session->create(
inline_states => {
_start => sub {
my ($kernel, $heap) = @_[KERNEL, HEAP];
my $dbpool = POE::Component::Pool::DBI->new(
connections => 10,
dsn => "DBI:Oracle:192.168.6.1:1524/CDB",
username => "Terry",
password => "Peller"
);
# Outstanding queries keep the calling session alive.
$dbpool->query(
callback => "handle_result",
query => "select price from cost where description= ?",
params => ["Mayotte"],
# userdata => "example"
);
$heap->{dbpool} = $dbpool;
},
handle_result => sub {
my ($kernel, $heap, $results, $userdata) = @_[KERNEL, HEAP, ARG0, ARG1];
# Will be an arrayref of hashrefs.
for my $record (@$results) {
print "test-ite \n";
print $record->{Mayotte};
}
my $dbpool = $heap->{dbpool};
# Ask for a clean shutdown.
$dbpool->shutdown;
},
},
);
POE::Kernel->run();
答案 0 :(得分:2)
看起来返回的行不会有“Mayotte”列,可能您想要写print $record->{price}
而不是print $record->{Mayotte}
。
我建议在这里使用Data::Dumper调试学校 - 找出你可以在循环中添加use Data::Dumper; warn Dumper($record);
的错误:)