Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

error dbi

by bigup401 (Pilgrim)
on Oct 16, 2020 at 13:07 UTC ( [id://11122902]=perlquestion: print w/replies, xml ) Need Help??

bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: error dbi
by Fletch (Bishop) on Oct 16, 2020 at 13:17 UTC

    I'm going to guess the cause is that you have statement handles which you never called finish on before you tried to call disconnect on the main DBI handle. After you're done retrieving results from a handle (as returned from prepare in your sample) you should call finish to let DBI and your database know you're done so it can do whatever it needs to do (freeing up resources, closing whatever, yadda yadda yadda).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      ok me i never notic that, that i have to call finish even on select statment, i thought finish is called on update or delete or anything when COMMIT() is called

      i tried to call finish on after execute, but db can't allow fetch without excute

      i dont think you can call finish when your still fetching info

        o.O

        • prepare your statement to get a handle
        • execute to fetch results
        • call whatever fetch routines to retrieve all the results
        • WHEN YOU ARE DONE FETCHING RESULTS call finish on the handle

        *plonk*

        Edit: Obviously from the errors in the OP he's not fetching all the results from the queries and he's not scoping his handles such that they're destroyed before the DB handle is cleaned up, so he either needs to explicitly finish when he's not going to fetch anything more or properly scope the handles so they're cleaned up automagically as documented. Given the historical behavior of the source that's unlikely.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Re: error dbi
by Anonymous Monk on Oct 20, 2020 at 00:43 UTC
    I really do need clarification on several implementation-specific points that seem to have been brought up here: (1) Is it "best practice" to call FINISH() every time? (2) Will there be resource-leaks if you do not completely consume a recordset, i.e. which would not occur if you did? (3) If a cursor variable goes out-of-scope, is FINISH() automatically called on it (if necessary)?

      perldoc DBI:

      "finish" $rc = $sth->finish; Indicate that no more data will be fetched from this statement han +dle before it is either executed again or destroyed. You almost certai +nly do *not* need to call this method. Adding calls to "finish" after loop that fetches all rows is a com +mon mistake, don't do it, it can mask genuine problems like uncaught f +etch errors.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found