title: Using the python MySQLDB SScursor with nested queries
body: <p>The typical MySQLdb library query can use a lot of memory and perform poorly in Python, when a large result set is generated. For example:</p>
  
  <pre><code>cursor.execute("SELECT id, name FROM `table`")
  for i in xrange(cursor.rowcount):
      id, name = cursor.fetchone()
      print id, name
  </code></pre>
  
  <p>There is an optional cursor that will fetch just one row at a time, really speeding up the script and cutting the memory footprint of the script a lot. </p>
  
  <pre><code>import MySQLdb
  import MySQLdb.cursors
  
  conn = MySQLdb.connect(user="user", passwd="password", db="dbname", 
                         cursorclass = MySQLdb.cursors.SSCursor)
  cur = conn.cursor()
  cur.execute("SELECT id, name FROM users")
  row = cur.fetchone()
  while row is not None:
      doSomething()
      row = cur.fetchone()    
  cur.close()
  conn.close()
  </code></pre>
  
  <p>But I can't find anything about using <code>SSCursor</code> with with nested queries. If this is the definition of <code>doSomething()</code>: </p>
  
  <pre><code>def doSomething()
      cur2 = conn.cursor()
      cur2.execute('select id,x,y from table2')
      rows = cur2.fetchall()
      for row in rows:
          doSomethingElse(row)
      cur2.close()
  </code></pre>
  
  <p>then the script throws the following error:</p>
  
  <pre><code>_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")
  </code></pre>
  
  <p>It sounds as if <code>SSCursor</code> is not compatible with nested queries. Is that true? If so that's too bad because the main loop seems to run too slowly with the standard cursor.</p>