in reply to (jeffa) 2Re: SQL Query
in thread SQL Query

I think that the here doc is a good solution in this case. If not, then I can think of absolutely no situation where it would be a good solution. You avoid quoting issues (both ' and " are valid quotes in sql, so why restict yourself to just one because you chose to open your string with one or the other?) and save yourself a headache when trying to debug.

thor

Replies are listed 'Best First'.
(jeffa) 4Re: SQL Query
by jeffa (Bishop) on Jan 11, 2002 at 11:50 UTC
    I didn't say that a here doc is a _bad_ solution, just too much of a solution. Because i use placeholders ( see bind values), i don't need inner quotes, but there is nothing stopping you from using placeholders inside a here document, either. It really is just a matter of style.

    A good use for here docs is for user display, and i don't mean debugging. But since i discovered the wonderful world of templating, i haven't used a here doc in a long, long time.

    I rather like this quick and dirty method of encapsulating a SQL query, i really think that here docs add line noise:

    sub get_artists { my $artist = shift() . '%'; return $dbh->selectcol_arrayref(' select name from artist where name like ? ',undef,$artist); }
    All i need is a pair of single quotes. But, this week taught me a pretty important lesson - there really are CPAN modules that take away having to even worry about such issues ... check out the replies by princepawn and autarch at Save MP3 Tag's to Database with SPOPS. (please note that SPOPS itself is meant for much more than what i presented.)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)