server/sources/rql2sql.py
changeset 4831 c5aec27c1bf7
parent 4794 81075b09ebf1
child 4845 dc351b96f596
equal deleted inserted replaced
4829:3b79a0fc91db 4831:c5aec27c1bf7
   330 
   330 
   331     WARNING: a CubicWebSQLGenerator instance is not thread safe, but generate is
   331     WARNING: a CubicWebSQLGenerator instance is not thread safe, but generate is
   332     protected by a lock
   332     protected by a lock
   333     """
   333     """
   334 
   334 
   335     def __init__(self, schema, dbms_helper, dbencoding='UTF-8', attrmap=None):
   335     def __init__(self, schema, dbms_helper, attrmap=None):
   336         self.schema = schema
   336         self.schema = schema
   337         self.dbms_helper = dbms_helper
   337         self.dbms_helper = dbms_helper
   338         self.dbencoding = dbencoding
   338         self.dbencoding = dbms_helper.dbencoding
   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
   975             pass
   975             pass
   976         return '(%s %s %s)'% (lhs.accept(self), operator, rhs.accept(self))
   976         return '(%s %s %s)'% (lhs.accept(self), operator, rhs.accept(self))
   977 
   977 
   978     def visit_function(self, func):
   978     def visit_function(self, func):
   979         """generate SQL name for a function"""
   979         """generate SQL name for a function"""
   980         # function_description will check function is supported by the backend
   980         # func_sql_call will check function is supported by the backend
   981         sqlname = self.dbms_helper.func_sqlname(func.name)
   981         return self.dbms_helper.func_as_sql(func.name,
   982         return '%s(%s)' % (sqlname, ', '.join(c.accept(self)
   982                                             [c.accept(self) for c in func.children])
   983                                               for c in func.children))
       
   984 
   983 
   985     def visit_constant(self, constant):
   984     def visit_constant(self, constant):
   986         """generate SQL name for a constant"""
   985         """generate SQL name for a constant"""
   987         value = constant.value
   986         value = constant.value
   988         if constant.type is None:
   987         if constant.type is None: