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
Eteri
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
Hide 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):
...
@@ -497,8 +497,7 @@ class SimulationTool(BaseTool):
# Sort on
# Sort on
if
'sort_on'
in
new_kw
:
if
'sort_on'
in
new_kw
:
table_column_list
=
ctool
.
getSQLCatalog
().
_getCatalogSchema
(
table_column_list
=
ctool
.
getSQLCatalog
().
getTableColumnList
(
table
)
table
=
table
)
sort_on
=
new_kw
[
'sort_on'
]
sort_on
=
new_kw
[
'sort_on'
]
new_sort_on
=
[]
new_sort_on
=
[]
for
column_id
,
sort_direction
in
sort_on
:
for
column_id
,
sort_direction
in
sort_on
:
...
...
product/ZSQLCatalog/SQLCatalog.py
View file @
bb2d0ee6
...
@@ -479,12 +479,12 @@ class Catalog(Folder,
...
@@ -479,12 +479,12 @@ class Catalog(Folder,
'type'
:
'selection'
,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
'select_variable'
:
'getCatalogMethodIds'
,
'mode'
:
'w'
},
'mode'
:
'w'
},
{
'id'
:
'sql_catalog_
tables
'
,
{
'id'
:
'sql_catalog_
schema
'
,
'description'
:
'Method to get the main catalog
tables
'
,
'description'
:
'Method to get the main catalog
schema
'
,
'type'
:
'selection'
,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
'select_variable'
:
'getCatalogMethodIds'
,
'mode'
:
'w'
},
'mode'
:
'w'
},
{
'id'
:
'sql_catalog_schema'
,
{
'id'
:
'sql_catalog_
multi_
schema'
,
'description'
:
'Method to get the main catalog schema'
,
'description'
:
'Method to get the main catalog schema'
,
'type'
:
'selection'
,
'type'
:
'selection'
,
'select_variable'
:
'getCatalogMethodIds'
,
'select_variable'
:
'getCatalogMethodIds'
,
...
@@ -605,9 +605,9 @@ class Catalog(Folder,
...
@@ -605,9 +605,9 @@ class Catalog(Folder,
sql_getitem_by_path
=
''
sql_getitem_by_path
=
''
sql_getitem_by_uid
=
''
sql_getitem_by_uid
=
''
sql_optimizer_switch
=
''
sql_optimizer_switch
=
''
sql_catalog_tables
=
''
sql_search_tables
=
()
sql_search_tables
=
()
sql_catalog_schema
=
''
sql_catalog_schema
=
''
sql_catalog_multi_schema
=
''
sql_catalog_index
=
''
sql_catalog_index
=
''
sql_unique_values
=
''
sql_unique_values
=
''
sql_catalog_paths
=
''
sql_catalog_paths
=
''
...
@@ -1082,30 +1082,46 @@ class Catalog(Folder,
...
@@ -1082,30 +1082,46 @@ class Catalog(Folder,
"""
"""
return
self
.
sql_search_result_keys
return
self
.
sql_search_result_keys
def
_getCatalogSchema
(
self
,
table
=
None
):
@
transactional_cache_decorator
(
'SQLCatalog._getCatalogSchema'
)
method_name
=
self
.
sql_catalog_schema
def
_getCatalogSchema
(
self
):
try
:
method
=
getattr
(
self
,
self
.
sql_catalog_multi_schema
,
None
)
method
=
getattr
(
self
,
method_name
)
if
method
is
None
:
except
AttributeError
:
# BBB: deprecated
pass
method_name
=
self
.
sql_catalog_schema
else
:
try
:
try
:
return
tuple
(
c
.
Field
for
c
in
method
(
table
=
table
))
method
=
getattr
(
self
,
method_name
)
except
(
ConflictError
,
DatabaseError
):
except
AttributeError
:
raise
return
{}
except
Exception
:
result
=
{}
pass
for
table
in
table_list
:
try
:
result
[
table
]
=
[
c
.
Field
for
c
in
method
(
table
=
table
)]
except
(
ConflictError
,
DatabaseError
):
raise
except
Exception
:
LOG
(
'SQLCatalog'
,
WARNING
,
'_getCatalogSchema failed with the method %s'
%
method_name
,
error
=
sys
.
exc_info
())
return
result
result
=
{}
for
row
in
method
():
result
.
setdefault
(
row
.
TABLE_NAME
,
[]).
append
(
row
.
COLUMN_NAME
)
return
result
LOG
(
'SQLCatalog'
,
WARNING
,
'_getCatalogSchema failed with the method %s'
security
.
declarePrivate
(
'getTableColumnList'
)
%
method_name
,
error
=
sys
.
exc_info
())
def
getTableColumnList
(
self
,
table
):
return
()
"""
Returns the list of columns in given table.
Raises KeyError on unknown table.
"""
return
self
.
_getCatalogSchema
()[
table
]
@
transactional_cache_decorator
(
'SQLCatalog.getColumnIds'
)
@
transactional_cache_decorator
(
'SQLCatalog.getColumnIds'
)
def
_getColumnIds
(
self
):
def
_getColumnIds
(
self
):
keys
=
set
()
keys
=
set
()
add_key
=
keys
.
add
add_key
=
keys
.
add
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
for
table
in
self
.
getCatalogSearchTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
add_key
(
field
)
add_key
(
field
)
add_key
(
'%s.%s'
%
(
table
,
field
))
# Is this inconsistent ?
add_key
(
'%s.%s'
%
(
table
,
field
))
# Is this inconsistent ?
for
related
in
self
.
getSQLCatalogRelatedKeyList
():
for
related
in
self
.
getSQLCatalogRelatedKeyList
():
...
@@ -1132,8 +1148,9 @@ class Catalog(Folder,
...
@@ -1132,8 +1148,9 @@ class Catalog(Folder,
Field Ids
Field Ids
"""
"""
result
=
{}
result
=
{}
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
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
(
field
,
[]).
append
(
table
)
result
.
setdefault
(
'%s.%s'
%
(
table
,
field
),
[]).
append
(
table
)
# Is this inconsistent ?
result
.
setdefault
(
'%s.%s'
%
(
table
,
field
),
[]).
append
(
table
)
# Is this inconsistent ?
return
result
return
result
...
@@ -1146,8 +1163,9 @@ class Catalog(Folder,
...
@@ -1146,8 +1163,9 @@ class Catalog(Folder,
Field Ids
Field Ids
"""
"""
keys
=
set
()
keys
=
set
()
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getCatalogSearchTableIds
():
for
table
in
self
.
getCatalogSearchTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
return
sorted
(
keys
)
return
sorted
(
keys
)
...
@@ -1159,8 +1177,9 @@ class Catalog(Folder,
...
@@ -1159,8 +1177,9 @@ class Catalog(Folder,
Field Ids that can be used for a sort
Field Ids that can be used for a sort
"""
"""
keys
=
set
()
keys
=
set
()
table_dict
=
self
.
_getCatalogSchema
()
for
table
in
self
.
getTableIds
():
for
table
in
self
.
getTableIds
():
for
field
in
self
.
_getCatalogSchema
(
table
=
table
)
:
for
field
in
table_dict
[
table
]
:
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
keys
.
add
(
'%s.%s'
%
(
table
,
field
))
return
sorted
(
keys
)
return
sorted
(
keys
)
...
@@ -1170,22 +1189,7 @@ class Catalog(Folder,
...
@@ -1170,22 +1189,7 @@ class Catalog(Folder,
Calls the show table method and returns dictionnary of
Calls the show table method and returns dictionnary of
Field Ids
Field Ids
"""
"""
method_name
=
self
.
sql_catalog_tables
return
self
.
_getCatalogSchema
().
keys
()
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
[]
security
.
declarePrivate
(
'getUIDBuffer'
)
security
.
declarePrivate
(
'getUIDBuffer'
)
def
getUIDBuffer
(
self
,
force_new_buffer
=
False
):
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