Commit 3167bdfc authored by Sebastien Robin's avatar Sebastien Robin

allow to specify what is the none value into sql when calling buildSQLSelector

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19698 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 451bdc3c
...@@ -1426,7 +1426,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1426,7 +1426,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# SQL Expression Building # SQL Expression Building
security.declareProtected(Permissions.AccessContentsInformation, 'buildSQLSelector') security.declareProtected(Permissions.AccessContentsInformation, 'buildSQLSelector')
def buildSQLSelector(self, category_list, query_table='category'): def buildSQLSelector(self, category_list, query_table='category', none_sql_value=None):
""" """
Returns an SQL selector expression from a list of categories Returns an SQL selector expression from a list of categories
We make here a simple method wich simply checks membership We make here a simple method wich simply checks membership
...@@ -1434,6 +1434,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1434,6 +1434,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
to generate a much more complex where_expression with table aliases to generate a much more complex where_expression with table aliases
List of lists List of lists
- none_sql_value is used in order to specify what is the None value into
sql tables
""" """
if isinstance(category_list, str): if isinstance(category_list, str):
category_list = [category_list] category_list = [category_list]
...@@ -1446,10 +1449,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1446,10 +1449,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
category_uid = self.getCategoryUid(category) category_uid = self.getCategoryUid(category)
base_category_uid = self.getBaseCategoryUid(category) base_category_uid = self.getBaseCategoryUid(category)
expression = '' expression = ''
if none_sql_value is not None and category_uid is None:
category_uid = none_sql_value
if category_uid is None: if category_uid is None:
expression += '%s.category_uid is NULL' % query_table expression += '%s.category_uid is NULL' % query_table
else: else:
expression += '%s.category_uid = %s' % (query_table,category_uid) expression += '%s.category_uid = %s' % (query_table,category_uid)
if none_sql_value is not None and base_category_uid is None:
base_category_uid = none_sql_value
if base_category_uid is None: if base_category_uid is None:
expression += ' AND %s.base_category_uid is NULL' % query_table expression += ' AND %s.base_category_uid is NULL' % query_table
else: else:
...@@ -1461,10 +1468,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1461,10 +1468,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
if single_sql_expr != '': if single_sql_expr != '':
category_uid = self.getCategoryUid(single_category) category_uid = self.getCategoryUid(single_category)
base_category_uid = self.getBaseCategoryUid(single_category) base_category_uid = self.getBaseCategoryUid(single_category)
if none_sql_value is not None and category_uid is None:
category_uid = none_sql_value
if category_uid is None: if category_uid is None:
expression += '%s.category_uid is NULL' % query_table expression += '%s.category_uid is NULL' % query_table
else: else:
expression += '%s.category_uid = %s' % (query_table,category_uid) expression += '%s.category_uid = %s' % (query_table,category_uid)
if none_sql_value is not None and base_category_uid is None:
base_category_uid = none_sql_value
if base_category_uid is None: if base_category_uid is None:
expression += ' AND %s.base_category_uid is NULL' % query_table expression += ' AND %s.base_category_uid is NULL' % query_table
else: else:
......
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