server/mssteps.py
changeset 7109 611663348158
parent 7108 bcdf22734059
child 7521 a5a5eea29c1b
equal deleted inserted replaced
7077:784d6f300070 7109:611663348158
   160             sql = 'INSERT INTO %s %s' % (self.outputtable, sql)
   160             sql = 'INSERT INTO %s %s' % (self.outputtable, sql)
   161         return self.plan.sqlexec(sql, self.plan.args)
   161         return self.plan.sqlexec(sql, self.plan.args)
   162 
   162 
   163     def get_sql(self):
   163     def get_sql(self):
   164         self.inputmap = inputmap = self.children[-1].outputmap
   164         self.inputmap = inputmap = self.children[-1].outputmap
       
   165         dbhelper=self.plan.syssource.dbhelper
   165         # get the select clause
   166         # get the select clause
   166         clause = []
   167         clause = []
   167         for i, term in enumerate(self.selection):
   168         for i, term in enumerate(self.selection):
   168             try:
   169             try:
   169                 var_name = inputmap[term.as_string()]
   170                 var_name = inputmap[term.as_string()]
   216                 if grouped is not None:
   217                 if grouped is not None:
   217                     for vref in sortterm.iget_nodes(VariableRef):
   218                     for vref in sortterm.iget_nodes(VariableRef):
   218                         if not vref.name in grouped:
   219                         if not vref.name in grouped:
   219                             sql[-1] += ', ' + self.inputmap[vref.name]
   220                             sql[-1] += ', ' + self.inputmap[vref.name]
   220                             grouped.add(vref.name)
   221                             grouped.add(vref.name)
   221             sql.append('ORDER BY %s' % ', '.join(clause))
   222             sql = dbhelper.sql_add_order_by(' '.join(sql),
   222         if self.limit:
   223                                             clause,
   223             sql.append('LIMIT %s' % self.limit)
   224                                             None, False,
   224         if self.offset:
   225                                             self.limit or self.offset)
   225             sql.append('OFFSET %s' % self.offset)
   226         else:
   226         return ' '.join(sql)
   227             sql = ' '.join(sql)
       
   228             clause = None
       
   229 
       
   230         sql = dbhelper.sql_add_limit_offset(sql, self.limit, self.offset, clause)
       
   231         return sql
   227 
   232 
   228     def visit_function(self, function):
   233     def visit_function(self, function):
   229         """generate SQL name for a function"""
   234         """generate SQL name for a function"""
   230         try:
   235         try:
   231             return self.children[0].outputmap[str(function)]
   236             return self.children[0].outputmap[str(function)]