[Erp5-report] r25944 - in /erp5/trunk/products/ZSQLCatalog: ./ Interface/ SearchKey/ Search...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Mar 10 15:45:40 CET 2009


Author: vincent
Date: Tue Mar 10 15:45:38 2009
New Revision: 25944

URL: http://svn.erp5.org?rev=25944&view=rev
Log:
Instead of using a static set, use a callback mechanism. This fixes virtual column detection.

Modified:
    erp5/trunk/products/ZSQLCatalog/Interface/ISearchKey.py
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/DefaultKey.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py
    erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextDetector.py
    erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py

Modified: erp5/trunk/products/ZSQLCatalog/Interface/ISearchKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/Interface/ISearchKey.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/Interface/ISearchKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/Interface/ISearchKey.py [utf8] Tue Mar 10 15:45:38 2009
@@ -109,7 +109,7 @@
         If given, expresses the comparison between column and value.
     """
 
-  def parseSearchText(value, column_id_set):
+  def parseSearchText(value, is_column):
     """
       Parse given value to generate an Abstract Syntax Tree representing its
       logical structure, or None if there is no obvious structure in given
@@ -118,9 +118,12 @@
 
       value (string)
         The string to parse.
-      column_id_set (set)
-        A list of valid column names. This is used when deciding wether value
-        should really be parsed or remain a bare string.
+      is_column (function taking one parameter)
+        This function will be called with a single parameter, being a column
+        name candidate.
+        It must return a boolean:
+        True: value is a valid column name
+        False: value is not a valid column name
 
       Returns: (None, AbstratSyntaxNode)
         AbstratSyntaxNode complies with the IAbstractSyntaxNode interface.

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] Tue Mar 10 15:45:38 2009
@@ -1794,6 +1794,18 @@
                          cache_factory='erp5_content_long')(table=table).copy()
 
   @profiler_decorator
+  def isValidColumn(self, column_id):
+    """
+      Tells wether given name is or not an existing column.
+
+      Warning: This includes "virtual" columns, such as related keys.
+    """
+    result = column_id in self.getColumnMap()
+    if not result:
+      result = self.getRelatedKeyDefinition(column_id) is not None
+    return result
+
+  @profiler_decorator
   def getRelatedKeyDefinition(self, key):
     """
       Returns the definition of given related key name if found, None
@@ -1981,9 +1993,6 @@
     # column names with empty values. This is for backward compatibility. See
     # comment about empty values.
     implicit_table_list = []
-    # It's not a problem to use a dict instead of a set here, and saves a
-    # cast.
-    column_id_set = self.getColumnMap()
     for key, value in kw.iteritems():
       result = None
       if isinstance(value, dict_type_list):
@@ -2017,7 +2026,7 @@
           # String: parse using key's default search key.
           search_key = self.getColumnDefaultSearchKey(key)
           if search_key is not None:
-            abstract_syntax_tree = search_key.parseSearchText(value, column_id_set)
+            abstract_syntax_tree = search_key.parseSearchText(value, self.isValidColumn)
             if abstract_syntax_tree is None:
               # Parsing failed, create a query from the bare string.
               result = self.buildSingleQuery(key, value)

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/DefaultKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/DefaultKey.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/DefaultKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/DefaultKey.py [utf8] Tue Mar 10 15:45:38 2009
@@ -42,8 +42,8 @@
   default_comparison_operator = '='
   get_operator_from_value = True
 
-  def parseSearchText(self, value, column_id_set):
-    return parse(value, column_id_set)
+  def parseSearchText(self, value, is_column):
+    return parse(value, is_column)
 
   def _guessComparisonOperator(self, value):
     if isinstance(value, basestring) and '%' in value:

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] Tue Mar 10 15:45:38 2009
@@ -40,8 +40,8 @@
   default_comparison_operator = 'match'
   get_operator_from_value = False
 
-  def parseSearchText(self, value, column_id_set):
-    return parse(value, column_id_set)
+  def parseSearchText(self, value, is_column):
+    return parse(value, is_column)
 
 verifyClass(ISearchKey, FullTextKey)
 

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] Tue Mar 10 15:45:38 2009
@@ -42,8 +42,8 @@
   default_comparison_operator = 'like'
   get_operator_from_value = True
  
-  def parseSearchText(self, value, column_id_set):
-    return parse(value, column_id_set)
+  def parseSearchText(self, value, is_column):
+    return parse(value, is_column)
 
   def _buildQuery(self, operator_value_dict, logical_operator, parsed, group):
     """

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py [utf8] Tue Mar 10 15:45:38 2009
@@ -341,7 +341,7 @@
       query = ComplexQuery(query_list, operator=logical_operator)
     return query
 
-  def parseSearchText(self, value, column_id_set):
+  def parseSearchText(self, value, is_column):
     return None
 
 verifyClass(ISearchKey, SearchKey)

Modified: erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextDetector.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextDetector.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextDetector.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextDetector.py [utf8] Tue Mar 10 15:45:38 2009
@@ -47,7 +47,7 @@
     return t
 
   def t_COLUMN(self, t):
-    self.found = t.value[:-1] in self.column_id_set
+    self.found = self.isColumn(t.value[:-1])
     t.type = 'WORD'
     return t
 
@@ -89,8 +89,8 @@
   def token(self):
     return self.token_list.pop(0)
 
-  def __call__(self, input, column_id_set):
-    self.column_id_set = column_id_set
+  def __call__(self, input, is_column):
+    self.isColumn = is_column
     self.found = False
     check_grammar = False
     self.token_list = token_list = []

Modified: erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py?rev=25944&r1=25943&r2=25944&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] Tue Mar 10 15:45:38 2009
@@ -66,8 +66,8 @@
     return parser
 
 @profiler_decorator
-def _parse(input, column_id_set, *args, **kw):
-  if getAdvancedSearchTextDetector()(input, column_id_set):
+def _parse(input, is_column, *args, **kw):
+  if getAdvancedSearchTextDetector()(input, is_column):
     result = getAdvancedSearchTextParser()(input, *args, **kw)
   else:
     result = None




More information about the Erp5-report mailing list