dabo Commit
Revision 4960
Date: 2009-01-25 07:52:43 -0800 (Sun, 25 Jan 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/4960
Changed:
U trunk/dabo/db/dDataSet.py
Log:
Fixed some bugs in the filter() method for dDataSet reported by Sibylle
Koczian. Also added support for 'not equals', using either '!=' or 'ne'.
Diff:
Modified: trunk/dabo/db/dDataSet.py
===================================================================
--- trunk/dabo/db/dDataSet.py 2009-01-25 15:12:06 UTC (rev 4959)
+++ trunk/dabo/db/dDataSet.py 2009-01-25 15:52:43 UTC (rev 4960)
@@ -137,6 +137,7 @@
instead of the equals sign, unless it is one of the following
strings,
which will be interpreted as indicated:
eq, equals: =
+ ne, nequals: !=
gt: >
gte: >=
lt: <
@@ -148,31 +149,36 @@
if not self:
# No rows, so nothing to filter
return self
- opDict = {"eq": " = ?",
- "equals": " = ?",
- "gt": " > ?",
- "gte": " >= ?",
- "lt": " < ?",
- "lte": " <= ?",
- "startswith": " LIKE ? ",
- "beginswith": " LIKE ? ",
- "endswith": " LIKE ? ",
- "contains": " LIKE ? " }
- if (expr in opDict) and (op not in opDict):
- # They sent the params in reverse order
- op, expr = expr, op
- clause = opDict.get(op.lower(), " = ?")
- oplow = op.lower()
- if oplow in ("startswith", "beginswith"):
+ op = op.strip().lower()
+ if op in ("=", "!=", ">", "<", ">=", "<="):
+ clause = "%s ?" % op
+ else:
+ opDict = {"eq": " = ?",
+ "equals": " = ?",
+ "ne": " != ?",
+ "nequals": " != ?",
+ "gt": " > ?",
+ "gte": " >= ?",
+ "lt": " < ?",
+ "lte": " <= ?",
+ "startswith": " LIKE ? ",
+ "beginswith": " LIKE ? ",
+ "endswith": " LIKE ? ",
+ "contains": " LIKE ? " }
+ if (expr in opDict) and (op not in opDict):
+ # They sent the params in reverse order
+ op, expr = expr, op
+ clause = opDict.get(op.lower(), " = ?")
+ if op in ("startswith", "beginswith"):
param = "%s%%" % expr
- elif oplow == "endswith":
+ elif op == "endswith":
param = "%%%s" % expr
- elif oplow == "contains":
+ elif op == "contains":
param = "%%%s%%" % expr
else:
param = expr
stmnt = "select * from dataset where %s %s" % (fld, clause)
- ret = self.execute(stmnt, params=param)
+ ret = self.execute(stmnt, (param, ))
ret._sourceDataSet = self
return ret
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]