in reply to Perl style/best practice question: how to [better] embed SQL in code ?
There are obvious constraints on what you can do with embedded SQL to make it readable. I personally would format the lines above as
my $sql = qq{ SELECT a.somedata1, } . qq{ a.somedata2, } . qq{ a.somedata3, } . qq{ [...] } . qq{ FROM table1 a, } . qq{ table2 b, } . qq{ table3 c } . qq{ WHERE a.somedata4 > ? } ; $sql .= qq{ AND a.somedata5 <= ? } . qq{ AND [...] } if some_perl_code_condition1; $sql .= qq{ AND b.somedata6 >= ? } . qq{ [...] } if some_perl_code_condition2; $sql .= qq{ ORDER BY somedata7 };
It removes a lot of the white space and all the new lines, but I'm pretty sure that my floating ; is not PBP. I'll play with field widths depending on case, but always put starting period and the closing brace at tab stops. One nice thing about this format is that mixing and matching is generally easy and safe, and changing width tends to be very fast.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl style/best practice question: how to [better] embed SQL in code ?
by jeffa (Bishop) on Dec 16, 2008 at 18:45 UTC | |
by kennethk (Abbot) on Dec 16, 2008 at 18:58 UTC | |
by jeffa (Bishop) on Dec 16, 2008 at 19:01 UTC |