I've got a db some of whose elements have been created automatically
from filesystem data (whose encoding is iso-8859-1). If I try to
select one of those elements using a standard SQL construct, things
work fine:
Butcher%",)).fe tchall()
[(1653, u'John Butcher & Eddie Pr\xe9vost')]
But if I use the pysqlite recipe for searching with a regexp, things don't work:
('John Butcher',)).fet chall()
Traceback (most recent call last):
File "<pyshell#1 4>", line 1, in -toplevel-
cursor.execute( "SELECT * FROM artists WHERE REGEXP(?, name)",
('John Butcher',)).fet chall()
OperationalErro r: user-defined function raised exception
Testing reveals that "item" is passed as None:
if item is None: return False
r = re.compile(expr , re.I)
return r.search(item) is not None
('John Butcher',)).fet chall()
[]
How can I get around this? I really want to be able to search by
regexp, and not just the standard SQL %-pattern.
--
Ben Wolfson
"However, identifying what we call 'time' or even 'space', which I
shall mention soon, is a very difficult problem, and a philosopher
would say that it is an extremely annoying subject."
(Soseki Natsume, "The Philosophical Foundations of Literature")
from filesystem data (whose encoding is iso-8859-1). If I try to
select one of those elements using a standard SQL construct, things
work fine:
>>sqlite.regist er_converter("t ext", unicode)
>>db = sqlite.connect( ".mdb/database", detect_types=sq lite.PARSE_COLN AMES)
>>cursor = db.cursor()
>>cursor.execut e("SELECT * FROM artists WHERE name LIKE ?", ("John
>>db = sqlite.connect( ".mdb/database", detect_types=sq lite.PARSE_COLN AMES)
>>cursor = db.cursor()
>>cursor.execut e("SELECT * FROM artists WHERE name LIKE ?", ("John
[(1653, u'John Butcher & Eddie Pr\xe9vost')]
>>>
>>db.create_fun ction("regexp", 2, regexp)
>>cursor.execut e("SELECT * FROM artists WHERE REGEXP(?, name)",
>>cursor.execut e("SELECT * FROM artists WHERE REGEXP(?, name)",
Traceback (most recent call last):
File "<pyshell#1 4>", line 1, in -toplevel-
cursor.execute( "SELECT * FROM artists WHERE REGEXP(?, name)",
('John Butcher',)).fet chall()
OperationalErro r: user-defined function raised exception
>>>
>>def regexp(expr, item):
r = re.compile(expr , re.I)
return r.search(item) is not None
>>db = sqlite.connect( ".mdb/database", detect_types=sq lite.PARSE_COLN AMES)
>>db.create_fun ction("regexp", 2, regexp)
>>cursor.execut e("SELECT * FROM artists WHERE REGEXP(?, name)",
>>db.create_fun ction("regexp", 2, regexp)
>>cursor.execut e("SELECT * FROM artists WHERE REGEXP(?, name)",
[]
>>>
regexp, and not just the standard SQL %-pattern.
--
Ben Wolfson
"However, identifying what we call 'time' or even 'space', which I
shall mention soon, is a very difficult problem, and a philosopher
would say that it is an extremely annoying subject."
(Soseki Natsume, "The Philosophical Foundations of Literature")