title: Index out of range while executing results from db
body: <p>I'm having a problem while trying to simply execute data from rows from db (sqlite3). The DB input has 4 fields, therefore once entered they're being saved. But here's my problem, where I execute all of the 4 rows, if one of the fields was not filled I get an error. </p>
  
  <p>That's the database execute code:</p>
  
  <pre><code>def ids(self):
      con = lite.connect('foo.db')
  
      with con:
  
          cur = con.cursor()    
          cur.execute("SELECT Id FROM foo")
  
      while True:
  
          ids = cur.fetchall()
  
          if ids == None:
              continue
  
          return ids
  </code></pre>
  
  <p>And since there are 4 rows, my output code:</p>
  
  <pre><code> print ''.join(ids[0]) + ',' + ''.join(ids[1]) + ',' + ''.join(ids[2])
   + ',' + ''.join(ids[3])
  </code></pre>
  
  <p>so my question is how to make an exception when there's no existing row to not show anything and just leave the ones that actually exist? I tried doing <code>if ids[0] is not None: #do something</code> but that would make my code really slow and it's non-pythonic way I guess. Is there any better way to make that work? Any help will be appreciated.</p>