server/sources/rql2sql.py
branchstable
changeset 6131 087c5a168010
parent 6050 20af96a6fffc
child 6286 4d10e9895679
equal deleted inserted replaced
6130:15fa8425b6e7 6131:087c5a168010
  1152                 rel._q_needcast = value
  1152                 rel._q_needcast = value
  1153             return self.keyword_map[value]()
  1153             return self.keyword_map[value]()
  1154         if constant.type == 'Boolean':
  1154         if constant.type == 'Boolean':
  1155             value = self.dbhelper.boolean_value(value)
  1155             value = self.dbhelper.boolean_value(value)
  1156         if constant.type == 'Substitute':
  1156         if constant.type == 'Substitute':
  1157             _id = constant.value
  1157             try:
  1158             if isinstance(_id, unicode):
  1158                 # we may found constant from simplified var in varmap
  1159                 _id = _id.encode()
  1159                 return self._mapped_term(constant, '%%(%s)s' % value)[0]
       
  1160             except KeyError:
       
  1161                 _id = constant.value
       
  1162                 if isinstance(_id, unicode):
       
  1163                     _id = _id.encode()
  1160         else:
  1164         else:
  1161             _id = str(id(constant)).replace('-', '', 1)
  1165             _id = str(id(constant)).replace('-', '', 1)
  1162             self._query_attrs[_id] = value
  1166             self._query_attrs[_id] = value
  1163         return '%%(%s)s' % _id
  1167         return '%%(%s)s' % _id
  1164 
  1168 
  1260                     scope = 0 # XXX
  1264                     scope = 0 # XXX
  1261                 if scope == 0:
  1265                 if scope == 0:
  1262                     break
  1266                     break
  1263         return scope
  1267         return scope
  1264 
  1268 
       
  1269     def _mapped_term(self, term, key):
       
  1270         """return sql and table alias to the `term`, mapped as `key` or raise
       
  1271         KeyError when the key is not found in the varmap
       
  1272         """
       
  1273         sql = self._varmap[key]
       
  1274         tablealias = sql.split('.', 1)[0]
       
  1275         scope = self._temp_table_scope(term.stmt, tablealias)
       
  1276         self.add_table(tablealias, scope=scope)
       
  1277         return sql, tablealias
       
  1278 
  1265     def _var_info(self, var):
  1279     def _var_info(self, var):
  1266         try:
  1280         try:
  1267             sql = self._varmap[var.name]
  1281             return self._mapped_term(var, var.name)
  1268             tablealias = sql.split('.', 1)[0]
       
  1269             scope = self._temp_table_scope(var.stmt, tablealias)
       
  1270             self.add_table(tablealias, scope=scope)
       
  1271         except KeyError:
  1282         except KeyError:
  1272             scope = self._state.scopes[var.scope]
  1283             scope = self._state.scopes[var.scope]
  1273             etype = self._state.solution[var.name]
  1284             etype = self._state.solution[var.name]
  1274             # XXX this check should be moved in rql.stcheck
  1285             # XXX this check should be moved in rql.stcheck
  1275             if self.schema.eschema(etype).final:
  1286             if self.schema.eschema(etype).final: