server/sources/rql2sql.py
changeset 7429 20ef21926774
parent 7397 6a9e66d788b3
parent 7421 5115daeeb2ff
child 7473 a164fdf3de5d
equal deleted inserted replaced
7423:598a4f051259 7429:20ef21926774
    70 
    70 
    71 def default_update_cb_stack(self, stack):
    71 def default_update_cb_stack(self, stack):
    72     stack.append(self.source_execute)
    72     stack.append(self.source_execute)
    73 FunctionDescr.update_cb_stack = default_update_cb_stack
    73 FunctionDescr.update_cb_stack = default_update_cb_stack
    74 
    74 
    75 LENGTH = SQL_FUNCTIONS_REGISTRY.get_function('LENGTH')
    75 get_func_descr = SQL_FUNCTIONS_REGISTRY.get_function
       
    76 
       
    77 LENGTH = get_func_descr('LENGTH')
    76 def length_source_execute(source, session, value):
    78 def length_source_execute(source, session, value):
    77     return len(value.getvalue())
    79     return len(value.getvalue())
    78 LENGTH.source_execute = length_source_execute
    80 LENGTH.source_execute = length_source_execute
    79 
    81 
    80 def _new_var(select, varname):
    82 def _new_var(select, varname):
   269         sort_term_selection(sorts, selectedidx, rqlst, not needwrap and groups)
   271         sort_term_selection(sorts, selectedidx, rqlst, not needwrap and groups)
   270     if sorts and groups:
   272     if sorts and groups:
   271         # when a query is grouped, ensure sort terms are grouped as well
   273         # when a query is grouped, ensure sort terms are grouped as well
   272         for sortterm in sorts:
   274         for sortterm in sorts:
   273             term = sortterm.term
   275             term = sortterm.term
   274             if not isinstance(term, Constant):
   276             if not (isinstance(term, Constant) or \
       
   277                     (isinstance(term, Function) and
       
   278                      get_func_descr(term.name).aggregat)):
   275                 for vref in term.iget_nodes(VariableRef):
   279                 for vref in term.iget_nodes(VariableRef):
   276                     if not vref in groups:
   280                     if not vref in groups:
   277                         groups.append(vref)
   281                         groups.append(vref)
   278     if needwrap:
   282     if needwrap:
   279         if groups:
   283         if groups:
   306         node = node.parent
   310         node = node.parent
   307         if node is stmt:
   311         if node is stmt:
   308             break
   312             break
   309         if not isinstance(node, Function):
   313         if not isinstance(node, Function):
   310             raise QueryError()
   314             raise QueryError()
   311         func = SQL_FUNCTIONS_REGISTRY.get_function(node.name)
   315         funcd = get_func_descr(node.name)
   312         if func.source_execute is None:
   316         if funcd.source_execute is None:
   313             raise QueryError('%s can not be called on mapped attribute'
   317             raise QueryError('%s can not be called on mapped attribute'
   314                              % node.name)
   318                              % node.name)
   315         state.source_cb_funcs.add(node)
   319         state.source_cb_funcs.add(node)
   316         func.update_cb_stack(stack)
   320         funcd.update_cb_stack(stack)
   317 
   321 
   318 
   322 
   319 # IGenerator implementation for RQL->SQL #######################################
   323 # IGenerator implementation for RQL->SQL #######################################
   320 
   324 
   321 class StateInfo(object):
   325 class StateInfo(object):