Commit 0208a9c0 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog: Inline _queryResult in only caller.

Also, extract unwanted kw entries by just declaring them as separate
parameters.
parent bc9d5827
...@@ -2489,36 +2489,40 @@ class Catalog(Folder, ...@@ -2489,36 +2489,40 @@ class Catalog(Folder,
""" """
return getComparisonOperatorInstance(operator) return getComparisonOperatorInstance(operator)
PROPAGATE_PARAMETER_SET = ('selection_domain',
'selection_report', def queryResults(
# XXX should get the next parameters from self,
# the ZSQLMethod class itself sql_method,
'zsql_brain') REQUEST=None,
def _queryResults(self, REQUEST=None, build_sql_query_method=None, **kw): src__=0,
""" Returns a list of brains from a set of constraints on variables """ build_sql_query_method=None,
selection_domain=None,
selection_report=None,
# XXX should get zsql_brain from ZSQLMethod class itself
zsql_brain=None,
implicit_join=False,
**kw
):
if build_sql_query_method is None: if build_sql_query_method is None:
build_sql_query_method = self.buildSQLQuery build_sql_query_method = self.buildSQLQuery
kw.setdefault('implicit_join', False) query = build_sql_query_method(
query = build_sql_query_method(REQUEST=REQUEST, **kw) REQUEST=REQUEST,
# XXX: decide if this should be made normal implicit_join=implicit_join,
ENFORCE_SEPARATION = True **kw
if ENFORCE_SEPARATION: )
# Some parameters must be propagated: return sql_method(
kw = {name: kw[name] for name in self.PROPAGATE_PARAMETER_SET src__=src__,
if name in kw} zsql_brain=zsql_brain,
kw['where_expression'] = query['where_expression'] selection_domain=selection_domain,
kw['sort_on'] = query['order_by_expression'] selection_report=selection_report,
kw['from_table_list'] = query['from_table_list'] where_expression=query['where_expression'],
kw['from_expression'] = query['from_expression'] select_expression=query['select_expression'],
kw['limit_expression'] = query['limit_expression'] group_by_expression=query['group_by_expression'],
kw['select_expression'] = query['select_expression'] from_table_list=query['from_table_list'],
kw['group_by_expression'] = query['group_by_expression'] from_expression=query['from_expression'],
# XXX: why not kw.update(query)?? sort_on=query['order_by_expression'],
return kw limit_expression=query['limit_expression'],
)
def queryResults(self, sql_method, REQUEST=None, src__=0, build_sql_query_method=None, **kw):
sql_kw = self._queryResults(REQUEST=REQUEST, build_sql_query_method=build_sql_query_method, **kw)
return sql_method(src__=src__, **sql_kw)
def getSearchResultsMethod(self): def getSearchResultsMethod(self):
return getattr(self, self.sql_search_results) return getattr(self, self.sql_search_results)
......
...@@ -226,7 +226,7 @@ class TestSQLCatalog(ERP5TypeTestCase): ...@@ -226,7 +226,7 @@ class TestSQLCatalog(ERP5TypeTestCase):
def catalog(self, reference_tree, kw, check_search_text=True, def catalog(self, reference_tree, kw, check_search_text=True,
check_select_expression=True, expected_failure=False): check_select_expression=True, expected_failure=False):
reference_param_dict = self._catalog._queryResults(query_table='foo', **kw) reference_param_dict = self._catalog.buildSQLQuery(query_table='foo', **kw)
query = self._catalog.buildEntireQuery(kw).query query = self._catalog.buildEntireQuery(kw).query
assertEqual = self.assertEqual assertEqual = self.assertEqual
if expected_failure: if expected_failure:
...@@ -236,7 +236,7 @@ class TestSQLCatalog(ERP5TypeTestCase): ...@@ -236,7 +236,7 @@ class TestSQLCatalog(ERP5TypeTestCase):
search_text = query.asSearchTextExpression(self._catalog) search_text = query.asSearchTextExpression(self._catalog)
if check_search_text: if check_search_text:
# XXX: sould "keyword" be always used for search text searches ? # XXX: sould "keyword" be always used for search text searches ?
search_text_param_dict = self._catalog._queryResults(query_table='foo', keyword=search_text) search_text_param_dict = self._catalog.buildSQLQuery(query_table='foo', keyword=search_text)
if not check_select_expression: if not check_select_expression:
search_text_param_dict.pop('select_expression') search_text_param_dict.pop('select_expression')
reference_param_dict.pop('select_expression') reference_param_dict.pop('select_expression')
......
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