On Tue, Feb 10, 2009 at 10:28 PM, Bobby Roberts <tchend...@gmail.com> wrote:

>
> hi gang.  For various reasons i've decided to use a raw sql statement
> in my view.  Following the example located at
> http://docs.djangoproject.com/en/dev/topics/db/sql/, I have a view
> which looks like this:
>
>
> def searchform(request):
>  from django.db import connection
>  ...
>  # a massive sql statement is dynamically built here. called sqlall
> (used below)
>
>  try:
>    #setup recordset
>    cursor=connection.cursor()
>    cursor.execute (sqlall)
>    tms=cusor.fetchall()  #this will be pushed back to the template
>  except IndexError:
>    #nothing found so redirect to "no results page"
>    return HttpResponseRedirect ('/search/results/none/')
>
> ...
>
>
> When I assert the sqlall variable, the sql statement executes
> perfectly in phpmyadmin.  However, Django throws the following
> traceback:
>
> not enough arguments for format string
>
> I have no idea what this error means and why it's not working... any
> ideas?


(Aside: That's not a traceback, it's a (partial) error message.  A traceback
includes an error message but also identifies the line of code causing the
error, including file name and line number, plus similar for all the code up
the call stack.  It is much more informative than just the error message,
and it's usually a good idea to include the whole traceback instead of just
the error message in posts asking for help.)

This is the  kind of thing that can cause the error message you are
reporting:

Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "%s %s" % ('hi',)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>>

I specified a string with two %s placeholders but only one object to take
their place, so Python raises an error that there are not enough arguments
for my format string.  Since you left out all the stuff that has anything to
do with creating the sql statement I'm not sure what you are doing to cause
this, though I notice you are not passing any parameter argument list to
your execute() call.  Are there no parameters that need to be substituted
into your dynatmically-generated sql statement?

Karen

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to