Commit 4ed89617 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support limit_expression.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2859 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ece9eb52
<dtml-comment> <dtml-comment>
title: title:
connection_id:erp5_sql_connection connection_id:erp5_sql_connection
max_rows:500 max_rows:0
max_cache:100 max_cache:100
cache_time:0 cache_time:0
class_name:ZSQLBrain class_name:ZSQLBrain
...@@ -13,7 +13,8 @@ selection_report ...@@ -13,7 +13,8 @@ selection_report
where_expression where_expression
select_expression select_expression
from_table_list:list from_table_list:list
sort_on</params> sort_on
limit_expression</params>
SELECT DISTINCT SELECT DISTINCT
<dtml-in getCatalogSearchResultKeys> <dtml-var sequence-item><dtml-if sequence-end> <dtml-else>, </dtml-if> </dtml-in> <dtml-in getCatalogSearchResultKeys> <dtml-var sequence-item><dtml-if sequence-end> <dtml-else>, </dtml-if> </dtml-in>
...@@ -37,3 +38,8 @@ WHERE ...@@ -37,3 +38,8 @@ WHERE
ORDER BY ORDER BY
<dtml-var sort_on> <dtml-var sort_on>
</dtml-if> </dtml-if>
<dtml-if limit_expression>
LIMIT <dtml-var "limit_expression">
<dtml-else>
LIMIT 1000
</dtml-if>
...@@ -1339,7 +1339,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1339,7 +1339,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
# We can now consider that old style query is changed into new style # We can now consider that old style query is changed into new style
for key in kw.keys(): # Do not use kw.items() because this consumes much more memory for key in kw.keys(): # Do not use kw.items() because this consumes much more memory
value = kw[key] value = kw[key]
if key not in ('where_expression', 'sort-on', 'sort_on', 'sort-order', 'sort_order'): if key not in ('where_expression', 'sort-on', 'sort_on', 'sort-order', 'sort_order', 'limit'):
# Make sure key belongs to schema # Make sure key belongs to schema
key_is_acceptable = key in acceptable_keys # Only calculate once key_is_acceptable = key in acceptable_keys # Only calculate once
key_is_related = key in related_keys key_is_related = key in related_keys
...@@ -1487,11 +1487,18 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1487,11 +1487,18 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression = "(%s) AND (%s)" % (kw['where_expression'], join(where_expression, ' AND ') ) where_expression = "(%s) AND (%s)" % (kw['where_expression'], join(where_expression, ' AND ') )
else: else:
where_expression = join(where_expression, ' AND ') where_expression = join(where_expression, ' AND ')
limit_expression = kw.get('limit', None)
if type(limit_expression) in (type(()), type([])):
limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1])
elif limit_expression is not None:
limit_expression = str(limit_expression)
# Use a dictionary at the moment. # Use a dictionary at the moment.
return { 'from_table_list' : from_table_dict.items(), return { 'from_table_list' : from_table_dict.items(),
'order_by_expression' : sort_on, 'order_by_expression' : sort_on,
'where_expression' : where_expression } 'where_expression' : where_expression,
'limit_expression' : limit_expression }
def queryResults(self, sql_method, REQUEST=None, used=None, src__=0, **kw): def queryResults(self, sql_method, REQUEST=None, used=None, src__=0, **kw):
""" Returns a list of brains from a set of constraints on variables """ """ Returns a list of brains from a set of constraints on variables """
...@@ -1499,6 +1506,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1499,6 +1506,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
kw['where_expression'] = query['where_expression'] kw['where_expression'] = query['where_expression']
kw['sort_on'] = query['order_by_expression'] kw['sort_on'] = query['order_by_expression']
kw['from_table_list'] = query['from_table_list'] kw['from_table_list'] = query['from_table_list']
kw['limit_expression'] = query['limit_expression']
# Return the result # Return the result
#LOG('acceptable_keys',0,'acceptable_keys: %s' % str(acceptable_keys)) #LOG('acceptable_keys',0,'acceptable_keys: %s' % str(acceptable_keys))
......
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