Commit 3f079e49 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog.SQLCatalog: Factorise code creating a query from column name.

Also, add a missing ignore_unknown_columns parameter.
parent d2b11fd3
...@@ -1851,32 +1851,29 @@ class Catalog(Folder, ...@@ -1851,32 +1851,29 @@ class Catalog(Folder,
return search_key return search_key
security.declareProtected(access_contents_information, 'buildSingleQuery') security.declareProtected(access_contents_information, 'buildSingleQuery')
def buildSingleQuery(self, key, value, search_key_name=None, logical_operator=None, comparison_operator=None): def buildSingleQuery(
self,
key,
value,
search_key_name=None,
logical_operator=None,
comparison_operator=None,
ignore_unknown_columns=False,
):
""" """
From key and value, determine the SearchKey to use and generate a Query From key and value, determine the SearchKey to use and generate a Query
from it. from it.
""" """
script = self.getScriptableKeyScript(key) return self._buildQuery(
if script is None: buildQueryFromSearchKey=lambda search_key: search_key.buildQuery(
search_key, related_key_definition = self.getColumnSearchKey(key, search_key_name) value,
if search_key is None: logical_operator=logical_operator,
result = None comparison_operator=comparison_operator,
else: ),
if related_key_definition is None: key=key,
build_key = search_key search_key_name=search_key_name,
else: ignore_unknown_columns=ignore_unknown_columns,
build_key = search_key.getSearchKey(sql_catalog=self, )
related_key_definition=related_key_definition,
search_key_name=search_key_name)
result = build_key.buildQuery(value, logical_operator=logical_operator,
comparison_operator=comparison_operator)
if related_key_definition is not None:
result = search_key.buildQuery(sql_catalog=self,
related_key_definition=related_key_definition,
search_value=result)
else:
result = script(value)
return result
def _buildQueryFromAbstractSyntaxTreeNode(self, node, search_key, wrap, ignore_unknown_columns): def _buildQueryFromAbstractSyntaxTreeNode(self, node, search_key, wrap, ignore_unknown_columns):
""" """
...@@ -1948,9 +1945,24 @@ class Catalog(Folder, ...@@ -1948,9 +1945,24 @@ class Catalog(Folder,
Expected node API is described in interfaces/abstract_syntax_node.py . Expected node API is described in interfaces/abstract_syntax_node.py .
""" """
return self._buildQuery(
buildQueryFromSearchKey=lambda search_key: self._buildQueryFromAbstractSyntaxTreeNode(
node,
search_key,
wrap,
ignore_unknown_columns,
),
key=key,
ignore_unknown_columns=ignore_unknown_columns,
)
def _buildQuery(self, buildQueryFromSearchKey, key, search_key_name=None, ignore_unknown_columns=False):
"""
Determine the SearchKey to use to generate a Query, and call buildQueryFromSearchKey with it.
"""
script = self.getScriptableKeyScript(key) script = self.getScriptableKeyScript(key)
if script is None: if script is None:
search_key, related_key_definition = self.getColumnSearchKey(key) search_key, related_key_definition = self.getColumnSearchKey(key, search_key_name)
else: else:
search_key = SearchKeyWrapperForScriptableKey(key, script) search_key = SearchKeyWrapperForScriptableKey(key, script)
related_key_definition = None related_key_definition = None
...@@ -1966,9 +1978,10 @@ class Catalog(Folder, ...@@ -1966,9 +1978,10 @@ class Catalog(Folder,
build_key = search_key build_key = search_key
else: else:
build_key = search_key.getSearchKey(sql_catalog=self, build_key = search_key.getSearchKey(sql_catalog=self,
related_key_definition=related_key_definition) related_key_definition=related_key_definition,
result = self._buildQueryFromAbstractSyntaxTreeNode(node, build_key, search_key_name=search_key_name,
wrap, ignore_unknown_columns) )
result = buildQueryFromSearchKey(search_key=build_key)
if related_key_definition is not None: if related_key_definition is not None:
result = search_key.buildQuery(sql_catalog=self, result = search_key.buildQuery(sql_catalog=self,
related_key_definition=related_key_definition, related_key_definition=related_key_definition,
...@@ -2060,7 +2073,12 @@ class Catalog(Folder, ...@@ -2060,7 +2073,12 @@ class Catalog(Folder,
abstract_syntax_tree = None abstract_syntax_tree = None
if abstract_syntax_tree is None: if abstract_syntax_tree is None:
# Parsing failed, create a query from the bare string. # Parsing failed, create a query from the bare string.
result = self.buildSingleQuery(key, raw_value, search_key_name) result = self.buildSingleQuery(
key=key,
value=raw_value,
search_key_name=search_key_name,
ignore_unknown_columns=ignore_unknown_columns,
)
else: else:
result = self.buildQueryFromAbstractSyntaxTreeNode( result = self.buildQueryFromAbstractSyntaxTreeNode(
abstract_syntax_tree, key, wrap, abstract_syntax_tree, key, wrap,
...@@ -2068,7 +2086,11 @@ class Catalog(Folder, ...@@ -2068,7 +2086,11 @@ class Catalog(Folder,
) )
else: else:
# Any other type, just create a query. (can be a DateTime, ...) # Any other type, just create a query. (can be a DateTime, ...)
result = self.buildSingleQuery(key, value) result = self.buildSingleQuery(
key=key,
value=value,
ignore_unknown_columns=ignore_unknown_columns,
)
if result is None: if result is None:
# No query could be created, emit a log, add to unknown column dict. # No query could be created, emit a log, add to unknown column dict.
unknown_column_dict[key] = value unknown_column_dict[key] = value
......
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