Вопрос

The code below should print ten results but instead it prints ten "test-ite". Why is it not showing the results it got from the database?

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();
Это было полезно?

Решение

It doesn't look like the returned rows would have a "Mayotte" column, probably you wanted to write print $record->{price} instead of print $record->{Mayotte}.

I suggest using the Data::Dumper school of debugging here -- to find out what was wrong you could have added a use Data::Dumper; warn Dumper($record); to the loop :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top