【问题标题】:Why are these POE threads results not showing when I print them?为什么我打印这些 POE 线程结果时不显示它们?
【发布时间】:2011-05-20 13:40:12
【问题描述】:

下面的代码应该打印 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();

【问题讨论】:

    标签: perl poe


    【解决方案1】:

    返回的行似乎没有“Mayotte”列,可能您想写 print $record->{price} 而不是 print $record->{Mayotte}

    我建议在这里使用Data::Dumper 调试学校——要找出问题所在,您可以在循环中添加use Data::Dumper; warn Dumper($record); :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      • 2014-12-05
      相关资源
      最近更新 更多