Friday, December 23, 2011

Re: Compare two tables in a secondary database

On Fri, 23 Dec 2011 19:14:47 +0200, Edvinas Narbutas
<enarbutas@gmail.com> wrote:


>item_search_results = item_search.objects.raw(
>"\
>SELECT \
>typeID, typeName \
>FROM \
>invGroups, \
>invTypes \
>WHERE \
>invTypes.groupID = invGroups.groupID AND \
>invGroups.categoryID IN (7, 8, 18, 20) AND \
>invTypes.typeName LIKE %s AND \
>invTypes.published = 1 \
>ORDER BY \
>typeName \
>LIMIT 0, 10",
>['%' + search_query + '%']
>).using(
> 'DataDump'
>)
>for name in item_search_results:
> results.append(name.typeName)
>
>When i wrote it i modified the search_query before the actual raw
>query. But i like how you did it in the params, one less line of code

If you use triple quotes for the main string you can maybe avoid all
those
\
terminators. I don't think SQL cares about newlines in query strings so

"""SELECT
typeID, typeName
FROM
...
LIMIT 0, 10"""",

should be handled the same.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment