Clear questions and runnable code
get the best and fastest answer
Perl style/best practice question: how to [better] embed SQL in code ?by Krambambuli (Curate)
|on Dec 16, 2008 at 17:29 UTC||Need Help??|
Krambambuli has asked for the
wisdom of the Perl Monks concerning the following question:
although I have a a few solutions for my problem, I have none with which I would be really happy, so I'm coming to ask around:
how do You embed SQL in your code?
My current way to do it - I'm referring mostly to complex queries, usually with a subroutine build around them - is something like
That's as readable as I could make it. Still, if later on, after being built, the resulting sql string is printed out for testing or is logged, the embedded newlines and spaces make the shown SQL string rather less appealing.
Clearly, I do want to get an optimum of somewhat opposite requirements - keeping the SQL readable in Perl, but also rather easy to cut-and-paste into/from SQL for testing/editing. Giving up indentation to use HERE documents seems not an real alternative, as I'd like to _keep_ the subroutine code nicely indented.
How are You solving this conundrum in the code you write?