I ran a test script and confirmed (for myself) that $sth->{ParamValues} is indeed not set with DBD::mysql. Bummer, but you can work around it: if you can pass $sth to your printing script, then surely you can pass some scalar that holds the SQL and an array ref that holds the param values to that script.

Sounds to me like what you are building is brute force (lots of wheel re-invention) and might benefit from a different approach. I can't help but cringe at the thought of subroutines that print output instead of returning output - maybe if you seperated your content from your format you wouldn't have this problem.

Just as a thought, i might approach this by writing a sub or two that accepts some parameters, grabs the data from the database and returns a data structure containing that data. Then, that data structure could be passed to a variety of subs that handle how it should be displayed. XML is very good for this kind of problem - you can transform it to HTML for the website (check out XML::LibXML and XML::LibXSLT) and to a PDF file for the printer (check out XML::Handler::AxPoint). You might even be able to use the powerful mod_perl 'plugin' AxKit to drive your app.

Update:
Consider this site. This particular node is #221372. If i want to access this node, i can pass the number off to index.pl like so:

http://www.perlmonks.org/index.pl?node_id=221372

Behind the scenes at Perlmonks, a SQL query is executed and the contents of this node are munged into themed HTML. If i want an XML version of this node, i simply pass another parameter to index.pl like so:

http://www.perlmonks.org/index.pl?node_id=221372&displaytype=xml

Again, a SQL query is executed, but this time the contents are rendered into XML. My point of all this is that for both requests, only the node id and display type were needed. No SQL was reconstructed. I don't see why your app has to reconstruct SQL to serve different displays of the same data.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: How to reconstruct a SQL query from an executed $sth by jeffa
in thread How to reconstruct a SQL query from an executed $sth by schweini

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.