changeset 7:917e28a08c58

search case insensitive. max and skip options.
author casties
date Tue, 15 Feb 2011 21:14:03 +0100
parents 1b25a85a2165
children 17b19345d011
files ZDBInterfaceFolder.py
diffstat 1 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ZDBInterfaceFolder.py	Tue Feb 15 20:41:28 2011 +0100
+++ b/ZDBInterfaceFolder.py	Tue Feb 15 21:14:03 2011 +0100
@@ -43,13 +43,21 @@
         wheres = []
         whereOp = "AND"
         done = {}
+        limit = None
+        offset = None
 
         def doOp(op, param, val):
             # handles comparison operations in WHERE clause
+            logging.debug("doop op=%s param=%s val=%s"%(op,param,val))
             if isinstance(val, list): 
                 # join multiple parameters with spaces (makes sense with checkbox and -op=all)
                 val = " ".join(val)
-            logging.debug("doop op=%s param=%s val=%s"%(op,param,val))
+                
+            # string comparisons are case-insensitive
+            if isinstance(val, basestring):
+                param = "LOWER(%s)"%param
+                val = val.lower()
+                
             if op == "eq":
                 wheres.append(param + " = %s")
                 args.append(val)
@@ -60,20 +68,26 @@
                 wheres.append(param + " > %s")
                 args.append(val)
             elif op == "bw":
-                wheres.append(param + " LIKE %s")
+                wheres.append(param + " ILIKE %s")
                 args.append("%" + val)
             elif op == "ew":
-                wheres.append(param + " LIKE %s")
+                wheres.append(param + " ILIKE %s")
                 args.append(val + "%")
             elif op == "ct":
-                wheres.append(param + " LIKE %s")
+                wheres.append(param + " ILIKE %s")
                 args.append("%" + val + "%")
             elif op == "all":
                 words = []
                 for word in val.split(" "):
-                    words.append(param + " LIKE %s")
+                    words.append(param + " ILIKE %s")
                     args.append("%" + word + "%")
                 wheres.append("(" + " AND ".join(words) + ")")
+            elif op == "one":
+                words = []
+                for word in val.split(" "):
+                    words.append(param + " ILIKE %s")
+                    args.append("%" + word + "%")
+                wheres.append("(" + " OR ".join(words) + ")")
             else:
                 logging.error("getSQLquery: unknown op=%s!"%op)
                 
@@ -98,6 +112,12 @@
             elif key == "_lop":
                 # logical operation joining WHERE clauses
                 whereOp = sqlName(val)
+            elif key == "max":
+                # number of results
+                limit = sqlName(val)
+            elif key == "skip":
+                # start at result number
+                offset = sqlName(val)
             elif key[:3] == "_op":
                 # operation parameters _op_param=option
                 param = sqlName(key[4:])
@@ -123,6 +143,12 @@
         
         if order:
             query += " ORDER BY " + order
+            
+        if limit:
+            query += " LIMIT " + limit
+            
+        if offset:
+            query += " OFFSET " + offset
 
         return {'query' : query, 'args' : args}