This is a mailing list for developing of django itself.
For usage of django please use the django-user mailing list.

Jorge

On Jul 17, 2013, at 4:21 PM, spondbob squelpen wrote:

> I have problem in django using query statement "LIKE %s%" with 
> Model.objects.raw(). I guess the problem is on '%' character but i don't know 
> where is it. Here's my model's code:
> 
>     def listInRange(self, placeLat, placeLng, typeId, range, placeTag):
>         tags = ''
>         if placeTag:
>             tags = " AND (placeTag LIKE '%" + "%' OR placeTag LIKE 
> '%".join(placeTag.split(',')) + "%')"
>         
>         query = "SELECT *, \
>                 ( \
>                     6371000 * \
>                     acos( \
>                         cos( radians(%s) ) * \
>                         cos( radians(placeLat) ) * \
>                         cos( radians(placeLng) - radians(%s) ) + \
>                         sin( radians(%s) ) * \
>                         sin( radians(placeLat) ) \
>                     ) \
>                 ) AS placeDistance, \
>             COUNT(r.reviewId) as placeReviews, \
>             
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>  AS averagePoint \
>             FROM place_place p \
>             LEFT JOIN review_review r \
>             ON r.reviewPlace_id = p.placeId\
>             WHERE placeType_id = %s %s \
>             GROUP BY p.placeId \
>             HAVING placeDistance < %s \
>             ORDER BY placeDistance"
>         
>         return Place.objects.raw(query, [placeLat, placeLng, placeLat, 
> typeId, tags, range])
> 
> If placeTag is not empty, then it will added to the WHERE condition. When the 
> placeTag is empty there's no such problem, but when placeTag is not empty i 
> got this error :
> 
>     Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE '%cafe%' 
> OR placeTag LIKE '%pub%')'
> 
> I think python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE '%pub%')' 
> as the value for placeType_id. How can i make the value of placeType_id=1 and 
> add the AND statement? What's the better way to write the sql statement using 
> Model.objects.raw() with 'like' statement?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-developers.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to