# HG changeset patch # User Sylvain Thénault # Date 1296988384 -3600 # Node ID 1172c25655b7e90b60c5a1bbdcbba7fa4014ceb3 # Parent 8fa55cf2a8cb57aec1fc93849ab51c2dc66b057a [rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation diff -r 8fa55cf2a8cb -r 1172c25655b7 server/rqlannotation.py --- a/server/rqlannotation.py Fri Feb 04 10:02:48 2011 +0100 +++ b/server/rqlannotation.py Sun Feb 06 11:33:04 2011 +0100 @@ -195,7 +195,7 @@ for rel in sorted(relations, key=lambda x: (x.children[0].name, x.r_type)): # only equality relation with a variable as rhs may be principal if rel.operator() not in ('=', 'IS') \ - or not isinstance(rel.children[1].children[0], VariableRef): + or not isinstance(rel.children[1].children[0], VariableRef) or rel.neged(strict=True): continue if rel.scope is rel.stmt: return rel diff -r 8fa55cf2a8cb -r 1172c25655b7 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Fri Feb 04 10:02:48 2011 +0100 +++ b/server/sources/rql2sql.py Sun Feb 06 11:33:04 2011 +0100 @@ -991,24 +991,21 @@ unification (eg X attr1 A, Y attr2 A). In case of selection, nothing to do here. """ - contextrels = {} for var in rhs_vars: if var.name in self._varmap: # ensure table is added self._var_info(var.variable) principal = var.variable.stinfo.get('principal') if principal is not None and principal is not relation: - contextrels[var.name] = relation - if not contextrels: - return '' - # we have to generate unification expression - lhssql = self._inlined_var_sql(relation.children[0].variable, - relation.r_type) - try: - self._state.ignore_varmap = True - return '%s%s' % (lhssql, relation.children[1].accept(self)) - finally: - self._state.ignore_varmap = False + # we have to generate unification expression + lhssql = self._inlined_var_sql(relation.children[0].variable, + relation.r_type) + try: + self._state.ignore_varmap = True + return '%s%s' % (lhssql, relation.children[1].accept(self)) + finally: + self._state.ignore_varmap = False + return '' def _visit_attribute_relation(self, rel): """generate SQL for an attribute relation""" diff -r 8fa55cf2a8cb -r 1172c25655b7 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Fri Feb 04 10:02:48 2011 +0100 +++ b/server/test/unittest_rql2sql.py Sun Feb 06 11:33:04 2011 +0100 @@ -180,6 +180,10 @@ FROM cw_Personne AS _X WHERE _X.cw_prenom=lulu AND NOT (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, cw_CWGroup AS _G WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=_G.cw_eid AND ((_G.cw_name=lulufanclub) OR (_G.cw_name=managers))))'''), + ('Any X WHERE X title V, NOT X wikiid V, NOT X title "parent", X is Card', + '''SELECT _X.cw_eid +FROM cw_Card AS _X +WHERE NOT (_X.cw_wikiid=_X.cw_title) AND NOT (_X.cw_title=parent)''') ]