Re: Using q() to define a query



Tim Bunce wrote:
On Fri, Jan 11, 2008 at 12:14:03PM +0000, Victor Churchill wrote:
On 11/01/2008, Colin Wetherbee <cww@xxxxxxxxxxxxxxxx> wrote:

(As an aside, how do you guys quote your queries? I find that for
anything longer than about 60 characters, q() and '' and everything else
start to look horribly inelegant.)
Can't comment on your main question, but on the secondary query-layout
topic, I find this works quite nicely:
$query2 = qq/SELECT MTR_REFERENCE FROM ALLOCATED_METERS,METERS /;
$query2 .= qq/WHERE ALM_MTR_ID = MTR_ID /;
$query2 .= qq/AND ALM_LP_ID = ( /;
$query2 .= qq/ SELECT LP_ID /;
$query2 .= qq/ FROM LOGGER_POINTS,ALLOCATED_METERS,METERS /;
$query2 .= qq/ WHERE LP_ID=ALM_LP_ID /;
$query2 .= qq/ AND MTR_ID=ALM_MTR_ID /;
$query2 .= qq/ AND MTR_REFERENCE = ? ) /;

(In a mono font the right hand /;'s align, for neatness, but that's optional).

Nice thing doing it this way is that it does not confuse the editor's
auto indent.

On the other hand, you can't easily copy-n-paste the query into other
tools, which I'd find much more frustrating. I'd also find the extra
line noise distracting. And when the query needs changing I'd find the
extra effort to maintain that layout would be a pain, literally.

Agreed. I'd rather not have my query broken up like that.

I almost always use q{} or qq{} for multi-line strings.

(Using a bracketing character like {, (, [ etc. means that perl will
also take care of skipping any nested brackets within the string without
them beeding to be escaped.)

That sounds good. I would think q{} would be the best choice for SQL, since () and [] are common SQL characters. Not that it really matters in terms of Perl functionality, but I'd imagine it's at least slightly less confusing in the long run.

Thanks.

Colin
.



Relevant Pages

  • Re: Solaris 9 username longer that 8 characters
    ... I dont want to end up in a cauldron!! ... that format only prints the first 8 characters of a username. ... < This line left intentionally blank to confuse you. ...
    (comp.unix.solaris)
  • Re: Linked table shows no data
    ... text files from non-Windows computers sometimes use different characters for ... and this can confuse Access's import routine. ... not showing for this linked table? ...
    (microsoft.public.access.externaldata)
  • Re: Double Click Field Conflicts
    ... What do you mean by "sometimes has characters that confuse the double ... The same thing exaggerated for clarity: ... If there's a chance that the item number could also contain a single quote, ...
    (microsoft.public.access.formscoding)
  • Re: Validation - Error message if equals Left formula
    ... then you will lose any leading zeroes; ... confuse your users? ... I wanted to place a data validation in B that gives> the ... > characters in A. Same for B with the right 3 characters of A. I've> tried ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Unicode in Photoshop CS3 Text Layer - doable ?
    ... the 'Characters to copy' space, copy it and paste them where needed. ... Still a lot of extra effort or memorization required. ... The Magazine of Folk and World Music ...
    (comp.graphics.apps.photoshop)