I'm having issues trying to extract utf-8 encoded values stored in an sqlite3 database in python.
>> import sqlite3
>> connection=sqlite3.connect('mySQLite3DB.db')
>> cursor=connection.cursor()
>> word = unichr(2675)+unichr(37) # ੳ%
>> cursor.execute('select distinct col1 from table1 where col1 like ? limit 3', word)
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
/Users/punjcoder/code/<ipython-input-10-358f7ffe8df0> in <module>()
----> 1 cursor.execute('select distinct col1 from table1 where col1 like ? limit 3', word)
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.
Now if I run the query by manually inserting the unicode, it runs. However I'm not able to retrieve the text, but buffer ptr instead.
>> cursor.execute('select distinct col1 from table1 where col1 like "ੳ%" limit 3')
<sqlite3.Cursor at 0x10dab8500>
>> for row in cursor.fetchall():
>> print row
(<read-write buffer ptr 0x10dabf898, size 3 at 0x10dabf858>,)
I have alread seen the links below, however can't seem to find a way to make it work. I'm working on Python 2.7.2 and SQLite 3.7.10. Your help is appreciated in advance.
Try:
cursor.execute('select distinct col1 from table1 where col1 like ? limit 3', [word])
I expect that you're treating the unicode string word
as an iterable and seeing each character separately.