title: Dynamically search for null in sqlite select query using python
body: <p>I'm new to python and I want to do a similar query to this one:</p>
  
  <pre><code>_c.execute('select * from cases where bi = ? and age = ? and 
              shape = ? and margin = ? and density = ?',(obj['bi'], 
              obj['age'], obj['margin'], obj['density']))
  </code></pre>
  
  <p>When some of the parameters are <code>None</code>, for example <code>obj['bi'] = None</code>, the query searches for the row when <code>bi = 'None'</code>. But I want it to search for the row when: <code>'bi is NULL'</code></p>
  
  <p>A possible solution is to verify the values of the parameters one by one in a sequence of if-elses. For example:</p>
  
  <pre><code>query = 'select * from cases where'
  
  if obj['bi'] is None:
     query += ' bi is null'
  else:
     query += ' bi = ' + str(obj['bi']) + ' and '
      ...
  # do the same if-else for the other parameters
      ...
  
  _c.execute(query)
  </code></pre>
  
  <p>But, it doesn't seem to me as the best solution. 
  The question is, what is the best solution to the given problem and how to avoid SQL injections.</p>