title: Escaping chars in Python and sqlite
body: <p>I have a python script that reads raw movie text files into an sqlite database.</p>
  
  <p>I use re.escape(title) to add escape chars into the strings to make them db safe before executing the inserts.</p>
  
  <p>Why does this not work:</p>
  
  <pre><code>In [16]: c.execute("UPDATE movies SET rating = '8.7' WHERE name='\'Allo\ \'Allo\!\"\ \(1982\)'")
  --------------------------------------------------------------------------- OperationalError                       Traceback (most recent call last)
  
  /home/rajat/Dropbox/amdb/&lt;ipython console&gt; in &lt;module&gt;()
  
  OperationalError: near "Allo": syntax error
  </code></pre>
  
  <p>Yet this works (removed \' in two places) :</p>
  
  <pre><code>In [17]: c.execute("UPDATE movies SET rating = '8.7' WHERE name='Allo\ Allo\!\"\ \(1982\)'") Out[17]: &lt;sqlite3.Cursor object at 0x9666e90&gt;
  </code></pre>
  
  <p>I can't figure it out. I also can't ditch those leading quotes because they're actually part of the movie title.
  Thank you.</p>