899 jointo, not_) + restriction |
899 jointo, not_) + restriction |
900 |
900 |
901 def visit_comparison(self, cmp, contextrels=None): |
901 def visit_comparison(self, cmp, contextrels=None): |
902 """generate SQL for a comparaison""" |
902 """generate SQL for a comparaison""" |
903 if len(cmp.children) == 2: |
903 if len(cmp.children) == 2: |
|
904 # XXX occurs ? |
904 lhs, rhs = cmp.children |
905 lhs, rhs = cmp.children |
905 else: |
906 else: |
906 lhs = None |
907 lhs = None |
907 rhs = cmp.children[0] |
908 rhs = cmp.children[0] |
908 operator = cmp.operator |
909 operator = cmp.operator |
909 if operator in ('IS', 'LIKE', 'ILIKE'): |
910 if operator in ('IS', 'LIKE', 'ILIKE'): |
910 if operator == 'ILIKE' and not self.dbms_helper.ilike_support: |
911 if operator == 'ILIKE' and not self.dbms_helper.ilike_support: |
911 operator = ' LIKE ' |
912 operator = ' LIKE ' |
912 else: |
913 else: |
913 operator = ' %s ' % operator |
914 operator = ' %s ' % operator |
|
915 elif (operator == '=' and isinstance(rhs, Constant) |
|
916 and rhs.eval(self._args) is None): |
|
917 if lhs is None: |
|
918 return ' IS NULL' |
|
919 return '%s IS NULL' % lhs.accept(self, contextrels) |
914 elif isinstance(rhs, Function) and rhs.name == 'IN': |
920 elif isinstance(rhs, Function) and rhs.name == 'IN': |
915 assert operator == '=' |
921 assert operator == '=' |
916 operator = ' ' |
922 operator = ' ' |
917 if lhs is None: |
923 if lhs is None: |
918 return '%s%s'% (operator, rhs.accept(self, contextrels)) |
924 return '%s%s'% (operator, rhs.accept(self, contextrels)) |