semi-concatenated strings
Delaney, Timothy
tdelaney at avaya.com
Wed Jun 5 19:41:37 EDT 2002
> From: Steve Holden [mailto:sholden at holdenweb.com]
>
> # The next three lines are bogus
> > > sql = string.split(sql)
> > > sql = string.join(sql, ' ')
> > > sql = string.strip(sql)
> > >
> > > rows = self.executesql(sql, (city,))
>
> Not only that, but for any reasonable database the whole schemozzle is
> completely unnecessary. SQL is a free-format language, and
> newlines and
> spaces embedded in statements make absolutely no difference.
I agree entirely - if you can rely on the database to handle embedded
newlines in queries (and most can) then there is no need to perform the
preprocessing.
I meant to include that those lines were only there to match the original,
which did not have embedded newlines.
The main point is the preference to use a triple-quoted string to lay out
the query readably. If preprocessing is necessary, I would *still* prefer
that, and add the required preprocessing.
After all, SQL queries are often read in from files, with newlines in the
queries ...
Tim Delaney
More information about the Python-list
mailing list