Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Lu Xu
erp5
Commits
3f079e49
Commit
3f079e49
authored
Nov 06, 2019
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZSQLCatalog.SQLCatalog: Factorise code creating a query from column name.
Also, add a missing ignore_unknown_columns parameter.
parent
d2b11fd3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
28 deletions
+50
-28
product/ZSQLCatalog/SQLCatalog.py
product/ZSQLCatalog/SQLCatalog.py
+50
-28
No files found.
product/ZSQLCatalog/SQLCatalog.py
View file @
3f079e49
...
...
@@ -1851,32 +1851,29 @@ class Catalog(Folder,
return
search_key
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 it.
"""
script
=
self
.
getScriptableKeyScript
(
key
)
if
script
is
None
:
search_key
,
related_key_definition
=
self
.
getColumnSearchKey
(
key
,
search_key_name
)
if
search_key
is
None
:
result
=
None
else
:
if
related_key_definition
is
None
:
build_key
=
search_key
else
:
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
return
self
.
_buildQuery
(
buildQueryFromSearchKey
=
lambda
search_key
:
search_key
.
buildQuery
(
value
,
logical_operator
=
logical_operator
,
comparison_operator
=
comparison_operator
,
),
key
=
key
,
search_key_name
=
search_key_name
,
ignore_unknown_columns
=
ignore_unknown_columns
,
)
def
_buildQueryFromAbstractSyntaxTreeNode
(
self
,
node
,
search_key
,
wrap
,
ignore_unknown_columns
):
"""
...
...
@@ -1948,9 +1945,24 @@ class Catalog(Folder,
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
)
if
script
is
None
:
search_key
,
related_key_definition
=
self
.
getColumnSearchKey
(
key
)
search_key
,
related_key_definition
=
self
.
getColumnSearchKey
(
key
,
search_key_name
)
else
:
search_key
=
SearchKeyWrapperForScriptableKey
(
key
,
script
)
related_key_definition
=
None
...
...
@@ -1966,9 +1978,10 @@ class Catalog(Folder,
build_key
=
search_key
else
:
build_key
=
search_key
.
getSearchKey
(
sql_catalog
=
self
,
related_key_definition
=
related_key_definition
)
result
=
self
.
_buildQueryFromAbstractSyntaxTreeNode
(
node
,
build_key
,
wrap
,
ignore_unknown_columns
)
related_key_definition
=
related_key_definition
,
search_key_name
=
search_key_name
,
)
result
=
buildQueryFromSearchKey
(
search_key
=
build_key
)
if
related_key_definition
is
not
None
:
result
=
search_key
.
buildQuery
(
sql_catalog
=
self
,
related_key_definition
=
related_key_definition
,
...
...
@@ -2060,7 +2073,12 @@ class Catalog(Folder,
abstract_syntax_tree
=
None
if
abstract_syntax_tree
is
None
:
# 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
:
result
=
self
.
buildQueryFromAbstractSyntaxTreeNode
(
abstract_syntax_tree
,
key
,
wrap
,
...
...
@@ -2068,7 +2086,11 @@ class Catalog(Folder,
)
else
:
# 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
:
# No query could be created, emit a log, add to unknown column dict.
unknown_column_dict
[
key
]
=
value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment