Commit a2a53019 authored by Vincent Pelletier's avatar Vincent Pelletier

Split buildSQLQuery into 2 parts: one responsible for building the EntireQuery...

Split buildSQLQuery into 2 parts: one responsible for building the EntireQuery (and responsible for parameter backward compatibility), and a second to just render that EntireQuery as a dict. This will help testing EntireQuery.
Update interface accordingly.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30033 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3fbbeea
...@@ -2119,10 +2119,8 @@ class Catalog(Folder, ...@@ -2119,10 +2119,8 @@ class Catalog(Folder,
return order_by_list return order_by_list
@profiler_decorator @profiler_decorator
def buildSQLQuery(self, query_table='catalog', REQUEST=None, def buildEntireQuery(self, kw, query_table='catalog', ignore_empty_string=1,
ignore_empty_string=1, only_group_columns=False, limit=None, extra_column_list=()):
limit=None, extra_column_list=(),
**kw):
group_by_list = kw.pop('group_by_list', kw.pop('group_by', kw.pop('group_by_expression', ()))) group_by_list = kw.pop('group_by_list', kw.pop('group_by', kw.pop('group_by_expression', ())))
if isinstance(group_by_list, basestring): if isinstance(group_by_list, basestring):
group_by_list = [x.strip() for x in group_by_list.split(',')] group_by_list = [x.strip() for x in group_by_list.split(',')]
...@@ -2172,7 +2170,7 @@ class Catalog(Folder, ...@@ -2172,7 +2170,7 @@ class Catalog(Folder,
# compatiblity, but I'm not sure if there can be a serious use for it in # compatiblity, but I'm not sure if there can be a serious use for it in
# new API. # new API.
order_by_override_list = kw.pop('select_expression_key', ()) order_by_override_list = kw.pop('select_expression_key', ())
query = EntireQuery( return EntireQuery(
query=self.buildQuery(kw, ignore_empty_string=ignore_empty_string), query=self.buildQuery(kw, ignore_empty_string=ignore_empty_string),
order_by_list=order_by_list, order_by_list=order_by_list,
order_by_override_list=order_by_override_list, order_by_override_list=order_by_override_list,
...@@ -2182,6 +2180,15 @@ class Catalog(Folder, ...@@ -2182,6 +2180,15 @@ class Catalog(Folder,
catalog_table_name=query_table, catalog_table_name=query_table,
extra_column_list=extra_column_list, extra_column_list=extra_column_list,
from_expression=from_expression) from_expression=from_expression)
@profiler_decorator
def buildSQLQuery(self, query_table='catalog', REQUEST=None,
ignore_empty_string=1, only_group_columns=False,
limit=None, extra_column_list=(),
**kw):
query = self.buildEntireQuery(kw, query_table=query_table,
ignore_empty_string=ignore_empty_string, limit=limit,
extra_column_list=extra_column_list)
result = query.asSQLExpression(self, only_group_columns).asSQLExpressionDict() result = query.asSQLExpression(self, only_group_columns).asSQLExpressionDict()
return result return result
......
...@@ -63,10 +63,9 @@ class ISearchKeyCatalog(Interface): ...@@ -63,10 +63,9 @@ class ISearchKeyCatalog(Interface):
It must be a valid ComplexQuery logical operator ('and', 'or'). It must be a valid ComplexQuery logical operator ('and', 'or').
""" """
def buildSQLQuery(query_table='catalog', REQUEST=None, def buildEntireQuery(kw, query_table='catalog', REQUEST=None,
ignore_empty_string=1, only_group_columns=False, ignore_empty_string=1, limit=None,
limit=None, extra_column_list=None, extra_column_list=None)
**kw):
""" """
Construct and return an instance of EntireQuery class from given Construct and return an instance of EntireQuery class from given
parameters by calling buildQuery. parameters by calling buildQuery.
...@@ -137,9 +136,24 @@ class ISearchKeyCatalog(Interface): ...@@ -137,9 +136,24 @@ class ISearchKeyCatalog(Interface):
This prevents given column from being ignored even if they could not This prevents given column from being ignored even if they could not
be mapped. be mapped.
There is no replacement. There is no replacement.
"""
def buildSQLQuery(query_table='catalog', REQUEST=None,
ignore_empty_string=1, only_group_columns=False,
limit=None, extra_column_list=None,
**kw):
"""
Return an SQLExpression-generated dictionary (see
SQLExpression.asSQLExpressionDict). That SQLExpression is generated by
an EntireQuery, itself generated by buildEntireQuery from given
parameters.
only_group_columns only_group_columns
Replaces former stat__ parameter. Replaces former stat__ parameter.
Used to globally disalow use of non-group columns in SQL. Used to globally disalow use of non-group columns in SQL.
For other parameters, see buildEntireQuery.
""" """
def getSearchKey(column, search_key=None): def getSearchKey(column, search_key=None):
......
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