Commit 385c6f2e authored by Vincent Pelletier's avatar Vincent Pelletier

Preserve Abstract Syntax Tree nesting of column nodes vs. other nodes.

  This fixes failing unit tests, because what used to trigger RelatedKey.buildQuery twice no triggers it just once with a ComplexQuery as join_condition.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25881 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8fdf04e5
...@@ -1917,24 +1917,9 @@ class Catalog(Folder, ...@@ -1917,24 +1917,9 @@ class Catalog(Folder,
return result return result
@profiler_decorator @profiler_decorator
def buildQueryFromAbstractSyntaxTreeNode(self, node, key): def _buildQueryFromAbstractSyntaxTreeNode(self, node, search_key):
"""
Build a query from given Abstract Syntax Tree (AST) node by recursing in
its childs.
This method calls itself recursively when walking the tree.
node
AST node being treated.
key
Default column (used when there is no explicit column in an AST leaf).
Expected node API is described in Interface/IAbstractSyntaxNode.py .
"""
if node.isLeaf(): if node.isLeaf():
result = self.buildSingleQuery(key, node.getValue(), comparison_operator=node.getComparisonOperator()) result = search_key.buildQuery(node.getValue(), comparison_operator=node.getComparisonOperator())
if result is None:
# Unknown, skip loudly
LOG('SQLCatalog', 100, 'Unknown column %r, skipped.' % (key, ))
elif node.isColumn(): elif node.isColumn():
result = self.buildQueryFromAbstractSyntaxTreeNode(node.getSubNode(), node.getColumnName()) result = self.buildQueryFromAbstractSyntaxTreeNode(node.getSubNode(), node.getColumnName())
else: else:
...@@ -1945,15 +1930,11 @@ class Catalog(Folder, ...@@ -1945,15 +1930,11 @@ class Catalog(Folder,
if subnode.isLeaf(): if subnode.isLeaf():
value_dict.setdefault(subnode.getComparisonOperator(), []).append(subnode.getValue()) value_dict.setdefault(subnode.getComparisonOperator(), []).append(subnode.getValue())
else: else:
subquery = self.buildQueryFromAbstractSyntaxTreeNode(subnode, key) subquery = self._buildQueryFromAbstractSyntaxTreeNode(subnode, search_key)
if subquery is not None: if subquery is not None:
append(subquery) append(subquery)
for comparison_operator, value_list in value_dict.iteritems(): for comparison_operator, value_list in value_dict.iteritems():
subquery = self.buildSingleQuery(key, value_list, comparison_operator=comparison_operator) append(search_key.buildQuery(value_list, comparison_operator=comparison_operator))
if subquery is None:
LOG('SQLCatalog', 100, 'Unknown column %r, skipped.' % (key, ))
else:
append(subquery)
operator = node.getLogicalOperator() operator = node.getLogicalOperator()
if operator == 'not' or len(query_list) > 1: if operator == 'not' or len(query_list) > 1:
result = ComplexQuery(query_list, operator=operator) result = ComplexQuery(query_list, operator=operator)
...@@ -1963,6 +1944,35 @@ class Catalog(Folder, ...@@ -1963,6 +1944,35 @@ class Catalog(Folder,
result = None result = None
return result return result
@profiler_decorator
def buildQueryFromAbstractSyntaxTreeNode(self, node, key):
"""
Build a query from given Abstract Syntax Tree (AST) node by recursing in
its childs.
This method calls itself recursively when walking the tree.
node
AST node being treated.
key
Default column (used when there is no explicit column in an AST leaf).
Expected node API is described in Interface/IAbstractSyntaxNode.py .
"""
search_key, related_key_definition = self.getColumnSearchKey(key)
if search_key is None:
# Unknown, skip loudly
LOG('SQLCatalog', 100, 'Unknown column %r, skipped.' % (key, ))
else:
if related_key_definition is None:
build_key = search_key
else:
build_key = search_key.getSearchKey(self, related_key_definition)
result = self._buildQueryFromAbstractSyntaxTreeNode(node, build_key)
if related_key_definition is not None:
result = search_key.buildQuery(self, related_key_definition,
search_value=result)
return result
@profiler_decorator @profiler_decorator
def buildQuery(self, kw, ignore_empty_string=True, operator='and'): def buildQuery(self, kw, ignore_empty_string=True, operator='and'):
query_list = [] query_list = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment