title: python loop over sqlite select with .fetchmany() until no entries left
body: <p>I need to retrieve results from my sqlite3 database 160 rows at a time, and repeat that until there are no rows left for my query, this is what I have:</p>
  
  <pre><code>conn = sqlite3.connect("C:\\Users\\%s\\AppData\\Roaming\\GridcoinResearch\\reports\\Rain.db" % user_account)
  c = conn.cursor()
  conn.text_factory = str
  address = c.execute('select Address from NNDATA where NeuralMagnitude != 0 and NeuralMagnitude is not null and CPID in (select cpids from GRIDCOINTEAM)').fetchmany(160)
  conn.text_factory = float
  nn_mag = c.execute('select NeuralMagnitude from NNDATA where NeuralMagnitude != 0 and NeuralMagnitude is not null and CPID in (select cpids from GRIDCOINTEAM)').fetchmany(160)
  conn.close()
  
  while True:
      if nn_mag == ():
          sys.exit("Complete")
  </code></pre>
  
  <p>The reason for <code>sys.exit</code> is I have a bunch of other code to go between <code>conn.close()</code> and <code>while True:</code>, so when the last loop is done I can exit the program.  Right now its doing the first pass then the cmd.exe is hanging.</p>
  
  <p>EDIT: Just relaised I dont tell the loop to select the NEXT 160, oh dear!</p>