Hi *

I am trying to pass a variable to a Raw SQL in Django with the
following code :
Note on the function : forge and num are variables that I am getting
from an URL.

>From the Django error web :

all_info []
amount  []
aux     {}
forge   u'objectweb'
forge_proj u'objectweb'
format u'rss'
num 0
proj_forge []

As you can see the function is receiving the correct values for each
variable and the function is :

def search_projects_by_forge(forge,num=0):
  # Query modified  because of the new bbdd model
  if (num != 0):
    sql = 'SELECT p.name, pi.url '
    sql = sql + 'FROM projects p, forges f, project_info pi '
    sql = sql + 'WHERE p.forge_id = f.id '
    sql = sql + 'AND p.id = pi.project_id '
    sql = sql + 'AND f.url like "%%%s%%" LIMIT %s' % (forge,num)
  else:
    sql = 'SELECT p.name, pi.url '
    sql = sql + 'FROM projects p, forges f, project_info pi '
    sql = sql + 'WHERE p.forge_id = f.id '
    sql = sql + 'AND p.id = pi.project_id '
    sql = sql + 'AND f.url like "%%%s%%"'  % (forge)

  cursor = connection.cursor()
  cursor.execute(sql)
  results = cursor.fetchall()

  print sql
  print results

  return [{'name':r[0],'url':r[1]} for r in results]

Django is returning this error :

TypeError at /search/forges=objectweb&format=rss

not enough arguments for format string

Request Method:         GET
Request URL:    http://melquiades/search/forges=objectweb&format=rss
Exception Type:         TypeError
Exception Value:

not enough arguments for format string

Exception Location:     /var/lib/python-support/python2.5/django/db/
backends/__init__.py in last_executed_query, line 173


More about this error :
sql
u'SELECT p.name, pi.url FROM projects p, forges f, project_info pi
WHERE p.forge_id = f.id AND p.id = pi.project_id AND f.url like
"%objectweb%"'
start
1238399284.6009409
stop
1238399284.6009769

The thing is that Django is executing the SQL with the correct
parameter actually (like a said before) putting this SQL instruction
in MySQL it works perfectly.

I am not sure if the error is about the unicode or something like
that.

I know that the f variable is not necessary, that is for testing
purposes only, actually copying the error from the Django Web Page
(that page where Django shows the error, debug page) into MySQL it
works.

I really do not know what more to do, I have been seen the pages that
offer information about types in python and so on but I can not fix
this.

Any help would be great, thank you in advance and best regards.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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