changeset 13:cf03ab908a2b

add _ignore_empty option (default=true) to ZSQLInlineSearch.
author casties
date Thu, 07 Jul 2011 21:04:23 +0200
parents 09882d5a3989
children 9cea47dc6926
files ZDBInterfaceFolder.py
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ZDBInterfaceFolder.py	Thu Jul 07 19:22:29 2011 +0200
+++ b/ZDBInterfaceFolder.py	Thu Jul 07 21:04:23 2011 +0200
@@ -37,9 +37,10 @@
         # default text search mode
         self.default_search = default_search
 
-    def getSQLQuery(self, table, argv):
-        """returns dict with SQL query string and args"""
-        logging.debug("getSQLquery table=%s argv=%s"%(table,argv))
+    def getSQLQuery(self, table, argv, ignore_empty=False):
+        """returns dict with SQL query string and args. 
+        ignore_empty: remove fields with empty string values from query."""
+        logging.debug("getSQLquery table=%s argv=%s ignore_empty=%s"%(table,argv,ignore_empty))
         args = []
         select = "*"
         order = None
@@ -47,12 +48,18 @@
         whereOp = "AND"
         processed = {}
         unprocessed = {}
+        ignored = {}
         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 ignore_empty and not val:
+                # ignore parameter
+                logging.debug("  param=%s ignored"%(param))
+                return
+            
             if isinstance(val, list): 
                 # join multiple parameters with spaces (makes sense with checkbox and -op=all)
                 val = " ".join(val)
@@ -122,7 +129,6 @@
                 # number of results
                 limit = sqlName(val)
             elif key == "_skip" or key == "_start":
-                logging.debug("SKIP!")
                 # start at result number
                 offset = sqlName(val)
             elif key[:3] == "_op":
@@ -162,9 +168,9 @@
 
         return {'query' : query, 'args' : args}
 
-    def ZDBInlineSearch(self, _table=None, **argv):
+    def ZDBInlineSearch(self, _table=None, _ignore_empty=True, **argv):
         """returns result set from search with given parameters"""
-        query = self.getSQLQuery(_table, argv)
+        query = self.getSQLQuery(_table, argv, ignore_empty= _ignore_empty)
         result = self.executeZSQL(query['query'], query['args'])
         return result