support for posix regexp in dal (sqlite and postgresql)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 1.99.4 (2012-02-26 15:42:22) stable
|
Version 1.99.4 (2012-02-26 16:03:31) stable
|
||||||
|
|||||||
@@ -962,6 +962,10 @@ class BaseAdapter(ConnectionPool):
|
|||||||
items = ','.join(self.expand(item, first.type) for item in second)
|
items = ','.join(self.expand(item, first.type) for item in second)
|
||||||
return '(%s IN (%s))' % (self.expand(first), items)
|
return '(%s IN (%s))' % (self.expand(first), items)
|
||||||
|
|
||||||
|
def REGEXP(self, first, second):
|
||||||
|
"regular expression operator"
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def LIKE(self, first, second):
|
def LIKE(self, first, second):
|
||||||
"case sensitive like operator"
|
"case sensitive like operator"
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@@ -1721,6 +1725,10 @@ class SQLiteAdapter(BaseAdapter):
|
|||||||
def lastrowid(self, table):
|
def lastrowid(self, table):
|
||||||
return self.cursor.lastrowid
|
return self.cursor.lastrowid
|
||||||
|
|
||||||
|
def REGEXP(self,first,second):
|
||||||
|
return '(%s REGEXP %s)' % (self.expand(first),
|
||||||
|
self.expand(second,'string'))
|
||||||
|
|
||||||
def _select(self, query, fields, attributes):
|
def _select(self, query, fields, attributes):
|
||||||
"""
|
"""
|
||||||
Simulate SELECT ... FOR UPDATE with BEGIN IMMEDIATE TRANSACTION.
|
Simulate SELECT ... FOR UPDATE with BEGIN IMMEDIATE TRANSACTION.
|
||||||
@@ -1998,6 +2006,10 @@ class PostgreSQLAdapter(BaseAdapter):
|
|||||||
return '(%s ILIKE %s)' % (self.expand(first),
|
return '(%s ILIKE %s)' % (self.expand(first),
|
||||||
self.expand(second,'string'))
|
self.expand(second,'string'))
|
||||||
|
|
||||||
|
def REGEXP(self,first,second):
|
||||||
|
return '(%s ~ %s)' % (self.expand(first),
|
||||||
|
self.expand(second,'string'))
|
||||||
|
|
||||||
def STARTSWITH(self,first,second):
|
def STARTSWITH(self,first,second):
|
||||||
return '(%s ILIKE %s)' % (self.expand(first),
|
return '(%s ILIKE %s)' % (self.expand(first),
|
||||||
self.expand(second+'%','string'))
|
self.expand(second+'%','string'))
|
||||||
@@ -6913,6 +6925,9 @@ class Expression(object):
|
|||||||
op = case_sensitive and self.db._adapter.LIKE or self.db._adapter.ILIKE
|
op = case_sensitive and self.db._adapter.LIKE or self.db._adapter.ILIKE
|
||||||
return Query(self.db, op, self, value)
|
return Query(self.db, op, self, value)
|
||||||
|
|
||||||
|
def regex(self, value):
|
||||||
|
return Query(self.db, self.db._adapter.REGEXP, self, value)
|
||||||
|
|
||||||
def belongs(self, value):
|
def belongs(self, value):
|
||||||
if isinstance(value,Query):
|
if isinstance(value,Query):
|
||||||
value = self.db(value)._select(value.first._table._id)
|
value = self.db(value)._select(value.first._table._id)
|
||||||
|
|||||||
Reference in New Issue
Block a user