116 raise ValidationError(source_entity.eid, {'url': _('can only have one url')}) |
116 raise ValidationError(source_entity.eid, {'url': _('can only have one url')}) |
117 |
117 |
118 def get_connection(self): |
118 def get_connection(self): |
119 try: |
119 try: |
120 return self._get_connection() |
120 return self._get_connection() |
121 except ConnectionError, ex: |
121 except ConnectionError as ex: |
122 self.critical("can't get connection to source %s: %s", self.uri, ex) |
122 self.critical("can't get connection to source %s: %s", self.uri, ex) |
123 return ConnectionWrapper() |
123 return ConnectionWrapper() |
124 |
124 |
125 def _get_connection(self): |
125 def _get_connection(self): |
126 """open and return a connection to the source""" |
126 """open and return a connection to the source""" |
335 session.set_shared_data('sources_error', msg % self.uri, txdata=True) |
335 session.set_shared_data('sources_error', msg % self.uri, txdata=True) |
336 return [] |
336 return [] |
337 translator = RQL2RQL(self) |
337 translator = RQL2RQL(self) |
338 try: |
338 try: |
339 rql = translator.generate(session, union, args) |
339 rql = translator.generate(session, union, args) |
340 except UnknownEid, ex: |
340 except UnknownEid as ex: |
341 if server.DEBUG: |
341 if server.DEBUG: |
342 print ' unknown eid', ex, 'no results' |
342 print ' unknown eid', ex, 'no results' |
343 return [] |
343 return [] |
344 if server.DEBUG & server.DBG_RQL: |
344 if server.DEBUG & server.DBG_RQL: |
345 print ' translated rql', rql |
345 print ' translated rql', rql |
346 try: |
346 try: |
347 rset = cu.execute(rql, args) |
347 rset = cu.execute(rql, args) |
348 except Exception, ex: |
348 except Exception as ex: |
349 self.exception(str(ex)) |
349 self.exception(str(ex)) |
350 msg = session._("error while querying source %s, some data may be missing") |
350 msg = session._("error while querying source %s, some data may be missing") |
351 session.set_shared_data('sources_error', msg % self.uri, txdata=True) |
351 session.set_shared_data('sources_error', msg % self.uri, txdata=True) |
352 return [] |
352 return [] |
353 descr = rset.description |
353 descr = rset.description |
571 # can safely skip not relation with an unsupported eid |
571 # can safely skip not relation with an unsupported eid |
572 if neged_relation(node): |
572 if neged_relation(node): |
573 return |
573 return |
574 # XXX what about optional relation or outer NOT EXISTS() |
574 # XXX what about optional relation or outer NOT EXISTS() |
575 raise |
575 raise |
576 except ReplaceByInOperator, ex: |
576 except ReplaceByInOperator as ex: |
577 rhs = 'IN (%s)' % ','.join(eid for eid in ex.eids) |
577 rhs = 'IN (%s)' % ','.join(eid for eid in ex.eids) |
578 self.need_translation = False |
578 self.need_translation = False |
579 self.current_operator = None |
579 self.current_operator = None |
580 if node.optional in ('right', 'both'): |
580 if node.optional in ('right', 'both'): |
581 rhs += '?' |
581 rhs += '?' |
598 #if node.name == 'IN': |
598 #if node.name == 'IN': |
599 res = [] |
599 res = [] |
600 for child in node.children: |
600 for child in node.children: |
601 try: |
601 try: |
602 rql = child.accept(self) |
602 rql = child.accept(self) |
603 except UnknownEid, ex: |
603 except UnknownEid as ex: |
604 continue |
604 continue |
605 res.append(rql) |
605 res.append(rql) |
606 if not res: |
606 if not res: |
607 raise ex |
607 raise ex |
608 return '%s(%s)' % (node.name, ', '.join(res)) |
608 return '%s(%s)' % (node.name, ', '.join(res)) |