Re: Using q() to define a query



On Jan 10, 2008 7:59 PM, Colin Wetherbee <cww@xxxxxxxxxxxxxxxx> wrote:

Greetings.

I have a DBI (DBD::Pg) application I'm building in mod_perl. My queries
tend to look something like the following.

my $sql = q(SELECT departure_date, eq.name AS equipment,
dp.full_city AS departure_city, ap.full_city AS arrival_city,
ca.name AS carrier_name, number
FROM jsjourneys
FULL OUTER JOIN jscarriers AS ca ON jsjourneys.carrier = ca.id
FULL OUTER JOIN jsequipment AS eq ON jsjourneys.equipment = eq.id
JOIN jsports AS dp ON jsjourneys.departure_port = dp.id
JOIN jsports AS ap ON jsjourneys.arrival_port = ap.id
ORDER BY departure_date);

And, then, I execute them as follows.

$dbh->selectall_arrayref($sql, { Slice => {} });

Which works quite well.

However, I'm concerned about $sql because when I output it to Apache's
debug log, it looks like this:

[Fri Jan 11 03:49:09 2008] [debug] Log.pm(36): [client 192.168.171.80]
[JetSet] SELECT departure_date, eq.name AS equipment,\n
dp.full_city AS departure_city, ap.full_city AS arrival_city,\n
ca.name AS carrier_name, number\n FROM jsjourneys\n FULL OUTER
JOIN jscarriers AS ca ON jsjourneys.carrier = ca.id\n FULL OUTER
JOIN jsequipment AS eq ON jsjourneys.equipment = eq.id\n JOIN
jsports AS dp ON jsjourneys.departure_port = dp.id\n JOIN jsports
AS ap ON jsjourneys.arrival_port = ap.id\n ORDER BY departure_date

Notice the newline characters in there. If those were really in the
query, I can't imagine the database would run it, so I suppose they're
an artifact of the combination of using q() to quote my query and using
Apache's logger to output it.


If you're referring to the newlines in the $sql string - I'd be astonished
if the DBMS did not handle them OK. If you're referring to the \n notation
in the log output, I'd assume those are interpolated by the Apache logging
module.


All this leads up to a pretty simple question: is using q() to quote my
queries a bad thing, and/or will it cause trouble in the future?


It's fine...


(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.)


q{}; q%%; q[];

On occasion, I've done evil things like q"" and qq'' -- it seemed like a
good idea at the time.




Thanks.

Colin




--
Jonathan Leffler <jonathan.leffler@xxxxxxxxx> #include <disclaimer.h>
Guardian of DBD::Informix - v2007.0914 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."


Relevant Pages

  • RE: Using q() to define a query
    ... queries tend to look something like the following. ... FULL OUTER JOIN jsequipment AS eq ON jsjourneys.equipment = eq.id ... JOIN jsports AS dp ON jsjourneys.departure_port = dp.id ... I'm concerned about $sql because when I output it to ...
    (perl.dbi.users)
  • Using q() to define a query
    ... My queries tend to look something like the following. ... FULL OUTER JOIN jsequipment AS eq ON jsjourneys.equipment = eq.id ... JOIN jsports AS dp ON jsjourneys.departure_port = dp.id ... However, I'm concerned about $sql because when I output it to Apache's debug log, it looks like this: ...
    (perl.dbi.users)
  • Re: Relational question
    ... If one considers the question as purely a SQL question then, ... the two queries are equivalent but with further explanation ... Note that if this were an INNER JOIN we would only need to ... >> left outer join ...
    (microsoft.public.sqlserver.programming)
  • Re: Official Status of SQLServer 2005 ADP
    ... I have said that the support for SQL passthrough ... queries under MDB was bad and worst than the one offered by ADP while you ... > attempt to "pass through" every Access query against a linked ODBC ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Massive Large Query Issues
    ... Project Budgets: Entered at the Capital Request level, ... installed (One install is typically $100,000 plus the cost of the equpment, ... install SQL Server. ... Often, a collection of queries ...
    (microsoft.public.access.queries)