On 23/05/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I'm reimplementing an in-database tree system and I'm using custom SQL
> queries. I want to use % in LIKE but Django doesn't let me.
>
> The code:
> ##############
> def getBranch(table_name, parent_depth, parent_cutLevel, max_depth):
>         cursor = connection.cursor()
>         cursor.execute("SELECT *, INSTR(level,'0')-1 AS depth,
> INSTR(level,'0')-1 - "+ parent_depth +" AS relativeDepth FROM  " +
> table_name + " WHERE level LIKE '"+ parent_cutLevel +"%' AND
> INSTR(level,'0')-1 <= ("+ max_depth +"+"+ parent_depth +") ORDER BY
> level")
>         row = cursor.fetchall()
>         return row
> ##############
>
> The exception:
> ##############
> not enough arguments for format string
> Exception Location: /usr/lib64/python2.4/site-packages/django/db/
> backends/util.py in execute, line 19
> ##############
> I can "print" the query string, but can't make the query as cursor
> code uses %letters... Is there a solution for this. ( \ doesn't work,
> % in variable also)
>

Umm... the "%" symbol has a special meaning in a string, which is to
interpolate it and fill it with arguments from a provided list. In a
cursor it's a variable placeholder used for prepared (or normal)
queries. If you want it literal, you must escape it properly.

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to