title: Reading unicode from sqlite db using python
body: <p>The data stored in unicode (in database) has to be retrieved and convert into a different form.</p>
  
  <p>The following snippet</p>
  
  <pre><code>def convert(content):
      content = content.replace("ஜௌ", "n\[s");
      return content;
  
  mydatabase = "database.db"
  connection = sqlite3.connect(mydatabase)
  cursor = connection.cursor()
  query = ''' select unicode_data from table1'''
  cursor.execute(query)
  for row in cursor.fetchone():
      print convert(row)
  </code></pre>
  
  <p>yields the following error message in convert method.</p>
  
  <blockquote>
    <p>exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in
    position 0: ordinal not in range(128)</p>
  </blockquote>
  
  <p>If the database content is <strong>"ஜௌஜௌஜௌ"</strong>, the output should be <strong>"n\[sn\[sn\[s"</strong></p>
  
  <p>The documentation suggests to use ignore or replace to avoid the error, when creating the unicode string.</p>
  
  <p>when the iteration is changed as follows:</p>
  
  <pre><code>for row in cursor.fetchone():
      print convert(unicode(row, errors='replace'))
  </code></pre>
  
  <p>it returns</p>
  
  <blockquote>
    <p>exceptions.TypeError: decoding Unicode is not supported</p>
  </blockquote>
  
  <p>which informs that row is already a unicode.</p>
  
  <p>Any light on this to make it work is highly appreciated. Thanks in advance.</p>