Commit 7fbbfe44 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog: Add support for query table aliasing.

Allows producing SQL for inclusion in ZSQLMethods where catalog table would
be already aliased.
parent 071e4b1a
...@@ -62,6 +62,7 @@ class EntireQuery(object): ...@@ -62,6 +62,7 @@ class EntireQuery(object):
inner_join_list=(), inner_join_list=(),
limit=None, limit=None,
catalog_table_name=None, catalog_table_name=None,
catalog_table_alias=None,
extra_column_list=(), extra_column_list=(),
from_expression=None, from_expression=None,
order_by_override_list=None, order_by_override_list=None,
...@@ -75,6 +76,7 @@ class EntireQuery(object): ...@@ -75,6 +76,7 @@ class EntireQuery(object):
self.inner_join_list = inner_join_list self.inner_join_list = inner_join_list
self.limit = limit self.limit = limit
self.catalog_table_name = catalog_table_name self.catalog_table_name = catalog_table_name
self.catalog_table_alias = catalog_table_alias
self.extra_column_list = list(extra_column_list) self.extra_column_list = list(extra_column_list)
self.from_expression = from_expression self.from_expression = from_expression
self.implicit_join = implicit_join self.implicit_join = implicit_join
...@@ -98,6 +100,7 @@ class EntireQuery(object): ...@@ -98,6 +100,7 @@ class EntireQuery(object):
if 1: if 1:
column_map.registerTable( column_map.registerTable(
self.catalog_table_name, self.catalog_table_name,
self.catalog_table_alias,
) )
for extra_column in self.extra_column_list: for extra_column in self.extra_column_list:
table, column = extra_column.replace('`', '').split('.') table, column = extra_column.replace('`', '').split('.')
......
...@@ -2362,7 +2362,10 @@ class Catalog(Folder, ...@@ -2362,7 +2362,10 @@ class Catalog(Folder,
return order_by_list return order_by_list
security.declarePrivate('buildEntireQuery') security.declarePrivate('buildEntireQuery')
def buildEntireQuery(self, kw, query_table='catalog', ignore_empty_string=1, def buildEntireQuery(self, kw,
query_table='catalog',
query_table_alias=None,
ignore_empty_string=1,
limit=None, extra_column_list=(), limit=None, extra_column_list=(),
ignore_unknown_columns=False): ignore_unknown_columns=False):
kw = self.getCannonicalArgumentDict(kw) kw = self.getCannonicalArgumentDict(kw)
...@@ -2402,11 +2405,14 @@ class Catalog(Folder, ...@@ -2402,11 +2405,14 @@ class Catalog(Folder,
implicit_join=implicit_join, implicit_join=implicit_join,
limit=limit, limit=limit,
catalog_table_name=query_table, catalog_table_name=query_table,
catalog_table_alias=query_table_alias,
extra_column_list=extra_column_list, extra_column_list=extra_column_list,
from_expression=from_expression) from_expression=from_expression)
security.declarePublic('buildSQLQuery') security.declarePublic('buildSQLQuery')
def buildSQLQuery(self, query_table='catalog', REQUEST=None, def buildSQLQuery(self, query_table='catalog',
query_table_alias=None,
REQUEST=None,
ignore_empty_string=1, only_group_columns=False, ignore_empty_string=1, only_group_columns=False,
limit=None, extra_column_list=(), limit=None, extra_column_list=(),
ignore_unknown_columns=False, ignore_unknown_columns=False,
...@@ -2414,6 +2420,7 @@ class Catalog(Folder, ...@@ -2414,6 +2420,7 @@ class Catalog(Folder,
return self.buildEntireQuery( return self.buildEntireQuery(
kw, kw,
query_table=query_table, query_table=query_table,
query_table_alias=query_table_alias,
ignore_empty_string=ignore_empty_string, ignore_empty_string=ignore_empty_string,
limit=limit, limit=limit,
extra_column_list=extra_column_list, extra_column_list=extra_column_list,
......
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