self.db.query and query with a join

4 views
Skip to first unread message

cd34

unread,
Oct 14, 2010, 2:45:51 AM10/14/10
to Tornado Web Server
While working with db.query on a project, I ran across an error in my
code:

whatever = self.db.query('select * from table')

results in being able to print whatever[0] without a problem.
However, if I do a join in the query:

whatever = self.db.query('select * from table,table2 where
table.id=table2.id')
print whatever[0]

results in:

IndexError: list index out of range

Even using a subselect results in the same issue.

for what in whatever:
print what

Works whether the join is present or not.

I checked python-mysqldb and using

cursor.execute('select * from table,table2 where table.id=table2.id')
rows = cursor.fetchall()

creates a tuple of tuples. Converting it to a list also allows it to
be addressed as I would expect.

I get the feeling I've missed something simple.

type(whatever) returns list in both cases whether I use the join or
not. printing whatever results in exactly the same output to screen
that I would expect, and the result is identical when the query is.
In doing a quick test, if it returns 1 row, whatever[0] is invalid,
but, if I get two rows, whatever[0] is valid whether using the join or
not.

cd34

unread,
Oct 15, 2010, 12:03:42 PM10/15/10
to Tornado Web Server
This appears to be an error on my part. One of my table column names
was a reserved word which I renamed for a different reason, and it
works now. However, I was not able to recreate the issue after
changing it back. If I can duplicate it, I'll write a test case and
submit it as a bug.
Reply all
Reply to author
Forward
0 new messages