I've tried the debugger but i have no idea how to use it to find my 
problem. in Pdb console i've tried check any variable value and everything 
seems fine

On Wednesday, July 17, 2013 10:34:39 PM UTC+7, [email protected] wrote:
>
> On Wed, Jul 17, 2013 at 9:28 AM, spondbob squelpen 
> <[email protected]<javascript:>> 
> wrote: 
> > sorry i'm new with django, could u please tell me how to use the 
> debugger? 
>
> In your python code, add this "import pdb; pdb.set_trace()' at the 
> place you want the breakpoint. 
>
> Then run: 
>
> python manage.py runserver 
>
> Then go to your web page that will cause your code to be invoked, but 
> add :8000 to the address (e.g. http://127.0.0.1:8000/...) 
>
> Then when it hits your breakpoint you can set other breakpoints, print 
> out variables, step though your program, etc. 
>
> http://docs.python.org/2/library/pdb.html 
>
> > On Wednesday, July 17, 2013 10:17:10 PM UTC+7, [email protected]: 
> >> 
> >> On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen <[email protected]> 
>
> >> wrote: 
> >> > the '1' is coming from typeId, so the WHERE condition must be look 
> like: 
> >> > WHERE placeType_id=1  AND (placeTag LIKE '%test%') 
> >> > 
> >> > print out tags: 
> >> >  AND (placeTag LIKE '%test%') 
> >> > 
> >> > i have tried your solution by adding double percentage but still got 
> >> > same 
> >> > error 
> >> 
> >> Like I said, use the debugger. 
> >> 
> >> > 
> >> > On Wednesday, July 17, 2013 10:04:48 PM UTC+7, [email protected] 
> >> > wrote: 
> >> >> 
> >> >> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen <
> [email protected]> 
> >> >> wrote: 
> >> >> > where do i put those double percentage? like this? 
> >> >> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
> >> >> > '%%".join(placeTag.split(',')) + "%%')" 
> >> >> > 
> >> >> > but still got the same error: 
> >> >> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
> >> >> > '%%test%%')' 
> >> >> 
> >> >> Where is the '1' coming from? I'd set a breakpoint here and run the 
> >> >> development server and see exactly what is going on. Print out the 
> >> >> tags and query, and if necessary step into Place.objects.raw. 
> >> >> 
> >> >> > 
> >> >> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, [email protected] 
> >> >> > wrote: 
> >> >> >> 
> >> >> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
> >> >> >> <[email protected]> 
> >> >> >> 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: '1AND (placeTag 
> >> >> >> > LIKE 
> >> >> >> > '%cafe%' 
> >> >> >> > OR placeTag LIKE '%pub%')' 
> >> >> >> > 
> >> >> >> > I guess 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 need '%%' when you want to end up with '%' 
> >> >> > 
> >> >> > -- 
> >> >> > You received this message because you are subscribed to the Google 
> >> >> > Groups 
> >> >> > "Django users" 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-users. 
> >> >> > For more options, visit https://groups.google.com/groups/opt_out. 
> >> >> > 
> >> >> > 
> >> > 
> >> > -- 
> >> > You received this message because you are subscribed to the Google 
> >> > Groups 
> >> > "Django users" 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-users. 
> >> > For more options, visit https://groups.google.com/groups/opt_out. 
> >> > 
> >> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to 
> > [email protected]<javascript:>. 
>
> > Visit this group at http://groups.google.com/group/django-users. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to