2011-05-20 72 views
0

下面的代碼應該打印十個結果,而是打印十個「test-ite」。爲什麼不顯示它從數據庫中獲得的結果?爲什麼這些POE線程在打印時不會顯示?

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(); 

回答

2

它看起來並不像返回的行,將有一個「馬約特島」一欄,也許你想寫print $record->{price},而不是print $record->{Mayotte}

我建議在這裏使用Data::Dumper學校調試 - 找出什麼是錯的,你可以添加一個use Data::Dumper; warn Dumper($record);到循環:)

+0

感謝名單霍布斯它的工作 – finidi 2011-05-20 14:28:29

相關問題