semi-concatenated strings
Delaney, Timothy
tdelaney at avaya.com
Thu May 30 22:10:40 EDT 2002
> From: Peter Hansen [mailto:peter at engcorp.com]
>
> And which has both embedded "\n" newlines and many more leading
> spaces before each line...
That's why I would bind it to a name first - that allows me to preprocess
the query before passing it in.
I would much rather write it so it is readable, then process it for the
database, than the other way around.
sql = """
select cities.city, state, country
from cities, venues, events, addresses
where cities.city like %s
and events.active = 1
and venues.address = addresses.id
and addresses.city = cities.id
and events.venue = venues.id
"""
sql = string.split(sql)
sql = string.join(sql, ' ')
sql = string.strip(sql)
rows = self.executesql(sql, (city,))
Skip also asked why I would bind the statement to a name. For a query of
this size, I find it easier to read - the sql query is separate and (to my
eye) cleaner than having the literal as a function parameter. Plus it uses
much less horizontal white space.
Tim Delaney
More information about the Python-list
mailing list