Patches item #1410834, was opened at 2006-01-20 17:21
Message generated for change (Comment added) made by phd
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410834&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Pau Aliagas (linux4u)
Assigned to: Oleg Broytmann (phd)
Summary: add RLIKE operator
Initial Comment:
Well, it looks like I'm inspired.
I tried to do all the regular expression matching in
python, but it was too slow, as I need to select
records based on an expresion matching.
So I have implemented RLIKE, also known as REGEXP or
Posix Regular Expressions. You can use it as any other
operator!
mysql and firebird call it REGEXP and RLIKE
postgres calls it ~
The rest just do not support it, so I've made it behave
like "LIKE", as I did not find a standard manner not to
support it. It's not a bad solution :)
The patch is really trivial, I've tested it with many
records (in mysql) and works as expected. I've tested
the resulting SQL in postgres and it works too.
Hope you can include it.
----------------------------------------------------------------------
>Comment By: Oleg Broytmann (phd)
Date: 2006-02-16 19:53
Message:
Logged In: YES
user_id=4799
Applied and committed to the trunk in the revision 1601,
1602 for 0.7-branch. I made some changes and added tests for
LIKE and RLIKE. Please look and run tests - does it work for
you with MySQL and SQLite?
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2006-02-16 18:30
Message:
Logged In: YES
user_id=4799
This one is much better! You've missed an important point -
__sqlrepr__() in RLIKE. I added it.
I also added tests for both LIKE and RLIKE. The test for
RLIKE fails for SQLIte because SQLIte treats REGEXP
specially - a user must define his/her own regexp() funcion.
I am going to experiment with PySQLite2 functions and then
commit.
----------------------------------------------------------------------
Comment By: Pau Aliagas (linux4u)
Date: 2006-02-15 20:00
Message:
Logged In: YES
user_id=140558
Let's see if you like this one.
I've mcreated an own class for LIKE, moved it away from
SQLOp and derived RLIKE from it.
I pass all the tests and LIKE and RLIKE work a expected
(tested in mysql),
LIKE shoule still work in the rest of databases as the
change is purely internal.
For RLIKE I looked at the manuals, it should work AFAICT.
We could even add REGEXP as another class effortlessly, but
I'm not sure you want to have several way to do the same thing.
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2006-02-13 22:26
Message:
Logged In: YES
user_id=4799
Take a look at INSubquery, NOTINSubquery, Subquery and EXISTS.
----------------------------------------------------------------------
Comment By: Pau Aliagas (linux4u)
Date: 2006-02-13 21:37
Message:
Logged In: YES
user_id=140558
I tried to mimic LIKE as much as possible, that's why I did
it this way. Moreover I could not find any example of doing
it as you suggest.
I had a look at the documentation and the generated SQL
should be valid in all cases (REGEXP is also called RLIKE in
mysql, I picked RLIKE to make it more natural, I also used
REGEXP).
If you could point me in the right direction, I could
probably redo the patch as I'm aleady using it instead of
direct use of SQL.
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2006-02-13 19:39
Message:
Logged In: YES
user_id=4799
The patch is invalid. SQLObject renders SQLOp("RLIKE", expr)
as "RLIKE " + expr. In SQLObject the operator is really
called REGEXP, in Postgres ~. The patch tries to replace
"RLIKE" to DBMS-specific name by replacing self.op (this is
fragile by itself) but in a wrong time - in .execute().
Instead of SQLOp("RLIKE", expr) the thing should be
implemented as a separate expression class, something like this:
class RLIKE(SQLOp):
def __sqlrepr__(self, db):
...
----------------------------------------------------------------------
Comment By: Oleg Broytmann (phd)
Date: 2006-01-31 18:24
Message:
Logged In: YES
user_id=4799
There is much overlap between LIKE and RLIKE. Can you
refactor it to remove duplicate code?
----------------------------------------------------------------------
Comment By: Pau Aliagas (linux4u)
Date: 2006-01-20 18:03
Message:
Logged In: YES
user_id=140558
Sorry, I attached the worng patch, this is the good one.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410834&group_id=74338
|