Don't put the % inside of " characters, or Python will attempt to
evaluate it out. Alternately, escape it so it doesn't eval. I
generally form up my custom SQL strings outside of the execute()
method to make debugging this kind of thing a tad easier.

-joe

On 5/23/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)
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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