cursor.execute("SELECT '%' ") --> tuple index out of range

1,997 views
Skip to first unread message

Thomas Guettler

unread,
Jul 30, 2008, 4:29:56 AM7/30/08
to django...@googlegroups.com
Hi,

can someone please check if this fails with current SVN trunk?

#import psycopg2
#connection=psycopg2.connect("dbname='...' user='...'")
#cursor=connection.cursor()
#cursor.execute('''SELECT '%' ''') # Does not fail
#cursor.execute('''SELECT '%' ''', ()) # Does fail

from django.db import connection
cursor=connection.cursor()
cursor.execute('''SELECT '%' ''')

I get this traceback:

Traceback (most recent call last):
File "/localhome/modw/tmp/t.py", line 8, in <module>
cursor.execute('''SELECT '%s' ''')
File "/localhome/modw/django/db/backends/util.py", line 21, in execute
return self.cursor.execute(sql, params)
IndexError: tuple index out of range

This is because params is () and not None.

PS: I am not running the latest SVN snapshot, so maybe this bug
is already fixed.

--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

Malcolm Tredinnick

unread,
Jul 30, 2008, 10:41:38 AM7/30/08
to django...@googlegroups.com

On Wed, 2008-07-30 at 10:29 +0200, Thomas Guettler wrote:
> Hi,
>
> can someone please check if this fails with current SVN trunk?
>
> #import psycopg2
> #connection=psycopg2.connect("dbname='...' user='...'")
> #cursor=connection.cursor()
> #cursor.execute('''SELECT '%' ''') # Does not fail
> #cursor.execute('''SELECT '%' ''', ()) # Does fail
>
> from django.db import connection
> cursor=connection.cursor()
> cursor.execute('''SELECT '%' ''')
>
> I get this traceback:
>
> Traceback (most recent call last):
> File "/localhome/modw/tmp/t.py", line 8, in <module>
> cursor.execute('''SELECT '%s' ''')
> File "/localhome/modw/django/db/backends/util.py", line 21, in execute
> return self.cursor.execute(sql, params)
> IndexError: tuple index out of range
>
> This is because params is () and not None.
>
> PS: I am not running the latest SVN snapshot, so maybe this bug
> is already fixed.

This doesn't look like it's going to be any sort of problem with Django.
That error is coming from the psycopg2 module by the looks of things. I
think the solution here is "don't do that!". All cursor.execute() in
Django does is pass the query string and parameters through to the
appropriate Python-DB module.

Regards,
Malcolm

Reply all
Reply to author
Forward
0 new messages