diff --git a/VERSION b/VERSION index 744164b7..e4bcb524 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 1.99.4 (2012-02-26 15:42:22) stable +Version 1.99.4 (2012-02-26 16:03:31) stable diff --git a/gluon/dal.py b/gluon/dal.py index 5e2a9819..ad570a5e 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -962,6 +962,10 @@ class BaseAdapter(ConnectionPool): items = ','.join(self.expand(item, first.type) for item in second) return '(%s IN (%s))' % (self.expand(first), items) + def REGEXP(self, first, second): + "regular expression operator" + raise NotImplementedError + def LIKE(self, first, second): "case sensitive like operator" raise NotImplementedError @@ -1721,6 +1725,10 @@ class SQLiteAdapter(BaseAdapter): def lastrowid(self, table): 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): """ Simulate SELECT ... FOR UPDATE with BEGIN IMMEDIATE TRANSACTION. @@ -1998,6 +2006,10 @@ class PostgreSQLAdapter(BaseAdapter): return '(%s ILIKE %s)' % (self.expand(first), self.expand(second,'string')) + def REGEXP(self,first,second): + return '(%s ~ %s)' % (self.expand(first), + self.expand(second,'string')) + def STARTSWITH(self,first,second): return '(%s ILIKE %s)' % (self.expand(first), self.expand(second+'%','string')) @@ -6913,6 +6925,9 @@ class Expression(object): op = case_sensitive and self.db._adapter.LIKE or self.db._adapter.ILIKE 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): if isinstance(value,Query): value = self.db(value)._select(value.first._table._id)