![]() |
|
The stupid question is the question not asked | |
PerlMonks |
DBI - get info from statement handlesby shemp (Deacon) |
on Sep 29, 2004 at 19:03 UTC ( #395104=perlquestion: print w/replies, xml ) | Need Help?? |
shemp has asked for the wisdom of the Perl Monks concerning the following question:
I want to write a little wrapper function to the prepare() and execute() part of querying a database. For instance, here's a relatively simple version:
Pretty basic, given a db handle and a query, prepare()'s and execute()'s it, returning the executed handle, doing error checking along the way. Yes, i'm aware that i could accomplish this other ways, but I dont necessarily want to execute all queries this way in a script, some queries will want some of their own specialized error checking, like recovering from the error, etc. I wrote this because I write similar code often in my scripts, so i wrapped it. Note, i used or confess on the prepare(), and eval{} on the execute() - opinions on that could be another thread. Anyhow, i want to write a nice (similar) wrapper for queries with input bind params. The problem im running into is getting the query for error statements. I'd like the function to look something like: I dont want to have to pass in the query, sometimes they're created on the fly, and are out of scope when the handles are executed, but i cant find any way to get the query out of the handle itself. Is this possible? Any other approaches to accomplish this same idea? Note: someday i'll perhaps add stuff for giving SQL_TYPES to the bind params, perhaps with a Tie::IxHash instead of an array. Perhaps other options eventually too.
Back to
Seekers of Perl Wisdom
|
|