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.