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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian
erp5
Commits
bb2d0ee6
Commit
bb2d0ee6
authored
Jul 13, 2016
by
Vincent Pelletier
Committed by
Sebastien Robin
Jul 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZSQLCatalog: Allow retrieving the entire schema in a single query.
parent
6ca7d1a6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
41 deletions
+44
-41
product/ERP5/Tool/SimulationTool.py
product/ERP5/Tool/SimulationTool.py
+1
-2
product/ZSQLCatalog/SQLCatalog.py
product/ZSQLCatalog/SQLCatalog.py
+43
-39
No files found.
product/ERP5/Tool/SimulationTool.py
View file @
bb2d0ee6
...
...
@@ -497,8 +497,7 @@ class SimulationTool(BaseTool):
# Sort on
if
'sort_on'
in
new_kw
:
table_column_list
=
ctool
.
getSQLCatalog
().
_getCatalogSchema
(
table
=
table
)
table_column_list
=
ctool
.
getSQLCatalog
().
getTableColumnList
(
table
)
sort_on
=
new_kw
[
'sort_on'
]
new_sort_on
=
[]
for
column_id
,
sort_direction
in
sort_on
:
...
...
product/ZSQLCatalog/SQLCatalog.py
View file @
bb2d0ee6
...
...
@@ -479,12 +479,12 @@ class Catalog(Folder,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
'mode'
:
'w'
},
{
'id'
:
'sql_catalog_
tables
'
,
'description'
:
'Method to get the main catalog
tables
'
,
{
'id'
:
'sql_catalog_
schema
'
,
'description'
:
'Method to get the main catalog
schema
'
,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
'mode'
:
'w'
},
{
'id'
:
'sql_catalog_schema'
,
{
'id'
:
'sql_catalog_
multi_
schema'
,
'description'
:
'Method to get the main catalog schema'
,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
...
...
@@ -605,9 +605,9 @@ class Catalog(Folder,
sql_getitem_by_path
=
''
sql_getitem_by_uid
=
''
sql_optimizer_switch
=
''
sql_catalog_tables
=
''
sql_search_tables
=
()
sql_catalog_schema
=
''
sql_catalog_multi_schema
=
''
sql_catalog_index
=
''
sql_unique_values
=
''
sql_catalog_paths
=
''
...
...
@@ -1082,30 +1082,46 @@ class Catalog(Folder,
"""
return
self
.
sql_search_result_keys
def
_getCatalogSchema
(
self
,
table
=
None
):
@
transactional_cache_decorator
(
'SQLCatalog._getCatalogSchema'
)
def
_getCatalogSchema
(
self
):
method
=
getattr
(
self
,
self
.
sql_catalog_multi_schema
,
None
)
if
method
is
None
:
# BBB: deprecated
method_name
=
self
.
sql_catalog_schema
try
:
method
=
getattr
(
self
,
method_name
)
except
AttributeError
:
pass
else
:
return
{}
result
=
{}
for
table
in
table_list
:
try
:
return
tuple
(
c
.
Field
for
c
in
method
(
table
=
table
))
result
[
table
]
=
[
c
.
Field
for
c
in
method
(
table
=
table
)]
except
(
ConflictError
,
DatabaseError
):
raise
except
Exception
:
pass
LOG
(
'SQLCatalog'
,
WARNING
,
'_getCatalogSchema failed with the method %s'
%
method_name
,
error
=
sys
.
exc_info
())
return
()
return
result
result
=
{}
for
row
in
method
():
result
.
setdefault
(
row
.
TABLE_NAME
,
[]).
append
(
row
.
COLUMN_NAME
)
return
result
security
.
declarePrivate
(
'getTableColumnList'
)
def
getTableColumnList
(
self
,
table
):
"""
Returns the list of columns in given table.
Raises KeyError on unknown table.
"""
return
self
.
_getCatalogSchema
()[
table
]
@
transactional_cache_decorator
(
'SQLCatalog.getColumnIds'
)
def
_getColumnIds
(
self
):
keys
=
set
()
add_key
=
keys
.
add
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
add_key
(
field
)
add_key
(
'%s.%s'
%
(
table
,
field
))
# Is this inconsistent ?
for
related
in
self
.
getSQLCatalogRelatedKeyList
():
...
...
@@ -1132,8 +1148,9 @@ class Catalog(Folder,
Field Ids
"""
result
=
{}
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
result
.
setdefault
(
field
,
[]).
append
(
table
)
result
.
setdefault
(
'%s.%s'
%
(
table
,
field
),
[]).
append
(
table
)
# Is this inconsistent ?
return
result
...
...
@@ -1146,8 +1163,9 @@ class Catalog(Folder,
Field Ids
"""
keys
=
set
()
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
return
sorted
(
keys
)
...
...
@@ -1159,8 +1177,9 @@ class Catalog(Folder,
Field Ids that can be used for a sort
"""
keys
=
set
()
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
return
sorted
(
keys
)
...
...
@@ -1170,22 +1189,7 @@ class Catalog(Folder,
Calls the show table method and returns dictionnary of
Field Ids
"""
method_name
=
self
.
sql_catalog_tables
try
:
method
=
getattr
(
self
,
method_name
)
except
AttributeError
:
pass
else
:
try
:
return
[
c
[
0
]
for
c
in
method
()]
except
(
ConflictError
,
DatabaseError
):
raise
except
Exception
:
pass
LOG
(
'SQLCatalog'
,
WARNING
,
'getTableIds failed with the method %s'
%
method_name
,
error
=
sys
.
exc_info
())
return
[]
return
self
.
_getCatalogSchema
().
keys
()
security
.
declarePrivate
(
'getUIDBuffer'
)
def
getUIDBuffer
(
self
,
force_new_buffer
=
False
):
...
...
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