From a2a530197a869d67efadc1546b9c4c4eb750255a Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Tue, 27 Oct 2009 14:13:59 +0000 Subject: [PATCH] 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 --- product/ZSQLCatalog/SQLCatalog.py | 17 +++++++++----- .../ZSQLCatalog/interfaces/query_catalog.py | 22 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index b3c64f6ce2..6e3b858b38 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -2119,10 +2119,8 @@ class Catalog(Folder, return order_by_list @profiler_decorator - def buildSQLQuery(self, query_table='catalog', REQUEST=None, - ignore_empty_string=1, only_group_columns=False, - limit=None, extra_column_list=(), - **kw): + def buildEntireQuery(self, kw, query_table='catalog', ignore_empty_string=1, + limit=None, extra_column_list=()): group_by_list = kw.pop('group_by_list', kw.pop('group_by', kw.pop('group_by_expression', ()))) if isinstance(group_by_list, basestring): group_by_list = [x.strip() for x in group_by_list.split(',')] @@ -2172,7 +2170,7 @@ class Catalog(Folder, # compatiblity, but I'm not sure if there can be a serious use for it in # new API. order_by_override_list = kw.pop('select_expression_key', ()) - query = EntireQuery( + return EntireQuery( query=self.buildQuery(kw, ignore_empty_string=ignore_empty_string), order_by_list=order_by_list, order_by_override_list=order_by_override_list, @@ -2182,6 +2180,15 @@ class Catalog(Folder, catalog_table_name=query_table, extra_column_list=extra_column_list, 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() return result diff --git a/product/ZSQLCatalog/interfaces/query_catalog.py b/product/ZSQLCatalog/interfaces/query_catalog.py index adaadc40d3..7aed3427d0 100644 --- a/product/ZSQLCatalog/interfaces/query_catalog.py +++ b/product/ZSQLCatalog/interfaces/query_catalog.py @@ -63,10 +63,9 @@ class ISearchKeyCatalog(Interface): It must be a valid ComplexQuery logical operator ('and', 'or'). """ - def buildSQLQuery(query_table='catalog', REQUEST=None, - ignore_empty_string=1, only_group_columns=False, - limit=None, extra_column_list=None, - **kw): + def buildEntireQuery(kw, query_table='catalog', REQUEST=None, + ignore_empty_string=1, limit=None, + extra_column_list=None) """ Construct and return an instance of EntireQuery class from given parameters by calling buildQuery. @@ -137,9 +136,24 @@ class ISearchKeyCatalog(Interface): This prevents given column from being ignored even if they could not be mapped. 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 Replaces former stat__ parameter. Used to globally disalow use of non-group columns in SQL. + + For other parameters, see buildEntireQuery. """ def getSearchKey(column, search_key=None): -- 2.30.9