Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Perl DBI connect cached still active

by Corion (Patriarch)
on Oct 29, 2020 at 11:11 UTC ( [id://11123293]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl DBI connect cached still active
in thread Perl DBI connect cached still active

Maybe the (Sybase) database driver doesn't like only half-fetching the resultset? Have you tried fetching the complete resultset and then issuing your second query? Something like:

my $prod_dbh = DBI->connect_cached('DBI:Sybase:database','web_','web') + || die "Couldn't connect to DB!\n" . DBI->errstr; my $parent_sth = $prod_dbh->prepare_cached('select * from table where +id = ?'); $parent_sth->bind_param(1,$id); $parent_sth->execute(); my $parent_data = $parent_sth->fetchall_arrayref(); ... my $child_sth = $prod_dbh->prepare_cached('select * from table2 where +id = ?'); $child_sth->bind_param(1,$parent_data[0]); $child_sth->execute(); my $child_data = $child_sth->fetchall_arrayref(); print Dumper($child_data->[0]);

Of course, with your statement handles named $parent_data and $child_data, maybe you are trying to fetch data in a parent/child relationship where you instead could be doing an SQL JOIN between the two tables to issue only a single query?

select parent.* , child.* from table parent join table2 child on (parent.id=child.id) where parent.id = ?

Replies are listed 'Best First'.
Re^4: Perl DBI connect cached still active
by derby (Abbot) on Oct 30, 2020 at 10:43 UTC

    Corion++ Sybase will fail if you finish an sth when there are unread results. You can override that by setting the syb_flush_finish attribute

    my $prod_dbh = DBI->connect_cached('DBI:Sybase:database','web_','web +' {syb_flush_finish => 1})
    but that wouldn't be my recommendation. I find most cases of extracting data are better suited by using selectall_arrayref. Sure you lose the re-usability of prepared statements (I only used those if I'm in a loop) and you may have memory issues if the data being returned is huge but I find the vast majority of my use cases are better served by the simplicity of selectall_arrayref:
    my $parent_data = $prod_dbh->selectall_arrayref('select * from table + where id = ?', {Slice => {}}, $id );
    -derby

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found