server/sources/rql2sql.py
changeset 4845 dc351b96f596
parent 4831 c5aec27c1bf7
parent 4836 3e3c4917e94e
child 5004 4cc020ee70e2
child 5010 b2c5aee8ca3f
equal deleted inserted replaced
4844:ad78b118b124 4845:dc351b96f596
   339         self.keyword_map = {'NOW' : self.dbms_helper.sql_current_timestamp,
   339         self.keyword_map = {'NOW' : self.dbms_helper.sql_current_timestamp,
   340                             'TODAY': self.dbms_helper.sql_current_date,
   340                             'TODAY': self.dbms_helper.sql_current_date,
   341                             }
   341                             }
   342         if not self.dbms_helper.union_parentheses_support:
   342         if not self.dbms_helper.union_parentheses_support:
   343             self.union_sql = self.noparen_union_sql
   343             self.union_sql = self.noparen_union_sql
       
   344         if self.dbms_helper.fti_need_distinct:
       
   345             self.__union_sql = self.union_sql
       
   346             self.union_sql = self.has_text_need_distinct_union_sql
   344         self._lock = threading.Lock()
   347         self._lock = threading.Lock()
   345         if attrmap is None:
   348         if attrmap is None:
   346             attrmap = {}
   349             attrmap = {}
   347         self.attr_map = attrmap
   350         self.attr_map = attrmap
   348 
   351 
   371             sql = self.union_sql(union)
   374             sql = self.union_sql(union)
   372             # we are done
   375             # we are done
   373             return sql, self._query_attrs
   376             return sql, self._query_attrs
   374         finally:
   377         finally:
   375             self._lock.release()
   378             self._lock.release()
       
   379 
       
   380     def has_text_need_distinct_union_sql(self, union, needalias=False):
       
   381         if getattr(union, 'has_text_query', False):
       
   382             for select in union.children:
       
   383                 select.need_distinct = True
       
   384         return self.__union_sql(union, needalias)
   376 
   385 
   377     def union_sql(self, union, needalias=False): # pylint: disable-msg=E0202
   386     def union_sql(self, union, needalias=False): # pylint: disable-msg=E0202
   378         if len(union.children) == 1:
   387         if len(union.children) == 1:
   379             return self.select_sql(union.children[0], needalias)
   388             return self.select_sql(union.children[0], needalias)
   380         sqls = ('(%s)' % self.select_sql(select, needalias)
   389         sqls = ('(%s)' % self.select_sql(select, needalias)