View Single Post
Old Feb 12th, 2007, 5:57 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
The "fetchall" function returns a list of tuples that represents the rows in your resultset. So result[0] returns the first item of the list; a tuple. You'd have to then index that again to get the first item of the tuple: result[0][0]

However, if you only expect your SQL to return one result, it's better to use "fetchone" instead.
python Syntax (Toggle Plain Text)
  1. cursor.execute(sql_first_look)
  2. result = cursor.fetchone()
  3. date = result[0]
  4.  
  5. print date.strftime("%Y-%m-%d")
Also, I'm not sure you need connection.commit() unless your SQL statement is part of a transaction that alters the database. Nor do you need to close your cursor separately to your database; closing the database closes the cursor too.

So it's likely you just need:
python Syntax (Toggle Plain Text)
  1. connection.close()
Arevos is offline   Reply With Quote