title: Python, MySQL and a weird error
body: <p>I have a bug that I don't know how to fix or even reproduce:</p>
  
  <pre><code>query = "SELECT id, name  FROM names ORDER BY id"
  results = database.execute(query)
  </code></pre>
  
  <p>where the class <code>Database</code> contains:</p>
  
  <pre><code>def execute(self, query):
      cursor = self.db.cursor()
      try:
          cursor.execute(query)
          return cursor.fetchall()
      except:
          import traceback
          traceback.print_exc(file=debugFile)
          return []
  </code></pre>
  
  <p>This is how I open the database connection:</p>
  
  <pre><code>self.db = MySQLdb.connect(
      host=mysqlHost,
      user=mysqlUser,
      passwd=mysqlPasswd,
      db=mysqlDB
  )
  </code></pre>
  
  <p>This is the stacktrace of the error:</p>
  
  <pre><code>File "foo.py", line 169, in application results = config.db.execute(query)
  File "Database.py", line 52, in execute
       return cursor.fetchall()
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 340, in fetchall
       self._check_executed()
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 70, in _check_executed
       self.errorhandler(self, ProgrammingError, "execute() first")
  File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
       raise errorclass, errorvalue
  ProgrammingError: execute() first
  </code></pre>
  
  <p>Do you have any ideas of why this is happening and how can I fix it? I searched on the internet and I found out that the reason may be having 2 cursors, but I have only one.</p>