Commit 98e6dbad authored by Sebastien Robin's avatar Sebastien Robin

ZSQLCatalog: Allow retrieving the entire schema in a single query. (part 2)

work partially done by Vincent Pelletier (z_get_table_schema)
parent bb2d0ee6
<catalog_method>
<item key="sql_catalog_multi_schema" type="int">
<value>1</value>
</item>
</catalog_method>
SELECT
TABLE_NAME, COLUMN_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA=DATABASE()
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>arguments_src</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>z_get_table_schema</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -69,6 +69,7 @@ erp5_mysql_innodb/z_create_versioning ...@@ -69,6 +69,7 @@ erp5_mysql_innodb/z_create_versioning
erp5_mysql_innodb/z_delete_recorded_object_list erp5_mysql_innodb/z_delete_recorded_object_list
erp5_mysql_innodb/z_delete_translation_list erp5_mysql_innodb/z_delete_translation_list
erp5_mysql_innodb/z_delete_uid erp5_mysql_innodb/z_delete_uid
erp5_mysql_innodb/z_get_table_schema
erp5_mysql_innodb/z_getitem_by_path erp5_mysql_innodb/z_getitem_by_path
erp5_mysql_innodb/z_getitem_by_uid erp5_mysql_innodb/z_getitem_by_uid
erp5_mysql_innodb/z_portal_ids_commit erp5_mysql_innodb/z_portal_ids_commit
......
...@@ -1085,15 +1085,19 @@ class Catalog(Folder, ...@@ -1085,15 +1085,19 @@ class Catalog(Folder,
@transactional_cache_decorator('SQLCatalog._getCatalogSchema') @transactional_cache_decorator('SQLCatalog._getCatalogSchema')
def _getCatalogSchema(self): def _getCatalogSchema(self):
method = getattr(self, self.sql_catalog_multi_schema, None) method = getattr(self, self.sql_catalog_multi_schema, None)
result = {}
if method is None: if method is None:
# BBB: deprecated # BBB: deprecated
warnings.warn("The usage of sql_catalog_schema is much slower. "
"than sql_catalog_multi_schema. It makes many SQL queries "
"instead of one",
DeprecationWarning)
method_name = self.sql_catalog_schema method_name = self.sql_catalog_schema
try: try:
method = getattr(self, method_name) method = getattr(self, method_name)
except AttributeError: except AttributeError:
return {} return {}
result = {} for table in self.getCatalogSearchTableIds():
for table in table_list:
try: try:
result[table] = [c.Field for c in method(table=table)] result[table] = [c.Field for c in method(table=table)]
except (ConflictError, DatabaseError): except (ConflictError, DatabaseError):
...@@ -1102,7 +1106,6 @@ class Catalog(Folder, ...@@ -1102,7 +1106,6 @@ class Catalog(Folder,
LOG('SQLCatalog', WARNING, '_getCatalogSchema failed with the method %s' LOG('SQLCatalog', WARNING, '_getCatalogSchema failed with the method %s'
% method_name, error=sys.exc_info()) % method_name, error=sys.exc_info())
return result return result
result = {}
for row in method(): for row in method():
result.setdefault(row.TABLE_NAME, []).append(row.COLUMN_NAME) result.setdefault(row.TABLE_NAME, []).append(row.COLUMN_NAME)
return result return result
......
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