Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

sqlconnection question

by grashoper (Monk)
on Aug 13, 2009 at 14:39 UTC ( #788313=perlquestion: print w/replies, xml ) Need Help??

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

I have an existing perl script that connects to sql and performs queries which it then merges the query result into another sql database, if I close the connection, prior to the execution of the datamerge will the data persist or will perl garbage collection throw it away?

Replies are listed 'Best First'.
Re: sqlconnection question
by moritz (Cardinal) on Aug 13, 2009 at 14:48 UTC
    Perls garbage collector won't throw anything away to which you still have access.
Re: sqlconnection question
by busunsl (Vicar) on Aug 13, 2009 at 14:50 UTC
    This depends on your code.

    Show us a simplified example of what you are doing.

    If you use one of the combined functions of DBI, like fetchall_arrayref, the data will persist.

    On the other hand, if you loop over the results using prepare, execute, fetch, you cannot close the connection, as this will drop your statement handle.

      Thanks, I see its not using combined functions so I guess the only option would be to do a re-write of most of it.
        Why do you want to close the connection anyway?

        There should be no problem with something like:

        sth1 = prepare select sth1->execute sth2 = prepare select sth2->execute sth3 = prepare insert while () { sth1->fetch sth2->fetch sth3->execute } sth1->finish sth2->finish sth3->finish
        Unless your database prevents having multiple statements at the same time.

        Hang on a minute - you may be rushing to change something you do not need to. The point being made is that if you open a cursor on a result-set, don't retrieve the whole result-set then close the connection you have not got all of the result-set you queried in the first place. So long as you retrieve the result-set via combined DBI functions or otherwise, then closing the connection should not matter. Of course this depends on where you store the results and whether the variables you store the results in go out of scope and are destroyed but the basic principle is go need to retrieve the result-set before closing the connection.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-01-17 02:15 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (50 votes). Check out past polls.