473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

sqlite user-defined functions & unicode issue

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:
>>sqlite.register_converter("text", unicode)
db = sqlite.connect(".mdb/database", detect_types=sqlite.PARSE_COLNAMES)
cursor = db.cursor()
cursor.execute("SELECT * FROM artists WHERE name LIKE ?", ("John
Butcher%",)).fetchall()
[(1653, u'John Butcher & Eddie Pr\xe9vost')]
>>>
But if I use the pysqlite recipe for searching with a regexp, things don't work:
>>db.create_function("regexp", 2, regexp)
cursor.execute("SELECT * FROM artists WHERE REGEXP(?, name)",
('John Butcher',)).fetchall()

Traceback (most recent call last):
File "<pyshell#14>", line 1, in -toplevel-
cursor.execute("SELECT * FROM artists WHERE REGEXP(?, name)",
('John Butcher',)).fetchall()
OperationalError: user-defined function raised exception
>>>
Testing reveals that "item" is passed as None:
>>def regexp(expr, item):
if item is None: return False
r = re.compile(expr, re.I)
return r.search(item) is not None
>>db = sqlite.connect(".mdb/database", detect_types=sqlite.PARSE_COLNAMES)
db.create_function("regexp", 2, regexp)
cursor.execute("SELECT * FROM artists WHERE REGEXP(?, name)",
('John Butcher',)).fetchall()
[]
>>>
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")
Jan 24 '07 #1
0 1250

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DurumDara | last post by:
Hi ! I want to process many data with python, and want to store in database. In the prior version of my code I create a simple thing that delete the old results, recreate the database and fill...
2
by: Christian Stooker | last post by:
Part one: ====== Hi ! I want to use SQLite database like the FireBird database: with big isolation level. What's that meaning ? I have an application that periodically check some input...
12
by: John Salerno | last post by:
I've been looking around and reading, and I have a few more questions about SQLite in particular, as it relates to Python. 1. What is the current module to use for sqlite? sqlite3? or is that not...
4
by: Jim Carlock | last post by:
I added the following lines to PHP.INI. extension=php_pdo.dll extension=php_pdo_sqlite.dll extension=php_sqlite.dll specifically in that order. I noticed the extensions getting loaded are...
10
by: Luigi | last post by:
Hello all! I'm a newbie in PHP. I have written a short script that tries to update a SQLite database with the user data. It is pretty simple, something like this: <?php $sqlite =...
20
by: Rob Stevens | last post by:
Can someone tell me how to import the sqlite3.dll file into c#. I am pretty new to this, and I want to use sqlite. The problem is I don't have a clue on how to import the dll file so i can call...
8
by: Gilles Ganault | last post by:
Hello I need to compile PHP5 with SQLite statically and without PDO. I don't need DB-independence, so it's fine using sqlite_*() functions instead of PDO. 1. I've downloaded, compiled, and...
3
by: Daniel Fetchinson | last post by:
Does Python 2.5.2's embedded SQLite support full text searching? Sqlite itself is not distributed with python. Only a python db api compliant wrapper is part of the python stdlib and as such it...
0
by: Joe Goldthwaite | last post by:
Thanks Guilherme. That helped. I guess I was thinking that pysqlite would automatically come with some version of sqlite. The fact that it doesn't is what was causing me to get the strange...
20
by: timotoole | last post by:
Hi all, On a (sun) webserver that I use, there is python 2.5.1 installed. I'd like to use sqlite3 with this, however sqlite3 is not installed on the webserver. If I were able to compile sqlite...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.