Yes absolutely. What you are trying to do is re-invent some of the existing functionality of both Apache::DBI and DBI. DBI can cache prepared statements so you don't have to prepare them everytime and Apache::DBI can pool those statements' connections so you don't have to re-create them everytime. In a mod_perl environment you should almost always be using prepare_cached().
In fact, in this precise situation, what I have to do is examine some old code, written by another team, and try to point out potential bugs, and that's exactly why I was asking this question. (I am not trying to reinvent the wheel, that's forbidden in Perl ;) )Basically, this old code, for each request, was using Apache::DBI to retrieve DB connection
handles, but was storing prepared statement handles in package variables. Then, during later calls, they assumed that if the current DB handle was the same as the previous one (i.e. same address), then, the stored statement handle could be reused wihout being prepared again. So,according to what you are telling me, in rare situations, I think this could lead to bugs.I had a quick look at Apache::DBI::connect code, and basically, what it does, when you ask for a DB connection handle (with the same attributes as previous calls), is first of all testing the current cached DB connection handle (via a ping call) and in case pinging fails, it calls DBI::connect to get a new connection. So, in case DBI::connect returns the same address for the DB handle (but with a new connection), using an already prepared statement would fail...
Thanks for your reply. Lionel.
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.