Hi,

On 31 Юли, 02:33, Paul Johnston <[EMAIL PROTECTED]> wrote:

> Yes, please do. I think you'll find some tweak to MssqlCompiler can
> achieve this.
>
> BTW, AND/OR are not broken generally; I think it's just BIT columns they
> have a problem with.
>
> Paul

I dont know how to restrict my changes only to where clause as mssql
has bit weird behavior -
in select like this it is ok:
select * from manager where not ( tobeornot = 1)
if the boolean expression is in the select part - sorry - error:
select not ( tobeornot = 1) from manager BUMMM
anyway the patch seems to work (at least for me).

below is the patch if it can be useful for someone (also not sure that
this is the proper way)

regards,
stefan



Index: databases/mssql.py
===================================================================
--- databases/mssql.py  (revision 2997)
+++ databases/mssql.py  (working copy)
@@ -824,6 +824,33 @@
         else:
             super(MSSQLCompiler, self).visit_alias(alias)

+    #TODO restrict changes in visit_unary, visit_clauselist to the
whereclause only!!!
+    __BOOL_HACK = ' =1'
+
+    def _isSelect( self):
+        return not self.isinsert and not self.isupdate #and
isinstance( self.dialect, MSSQLDialect_pymssql)
+
+    def visit_unary( self, unary):
+        if (self._isSelect() and 'NOT' == getattr(unary,
'operator','')
+                and isinstance( unary.element, schema.Column)
+                and isinstance( unary.element.type,
sqltypes.Boolean)   ):
+                unary.element = sql._TextClause( str(unary.element) +
self.__BOOL_HACK)
+                self.traverse( unary.element)
+        super(MSSQLCompiler, self).visit_unary(unary)
+
+    def visit_clauselist(self, list):
+        if self._isSelect():
+            column = None
+            for each in list.clauses:
+                if isinstance( each, schema.Column) and
isinstance( each.type, sqltypes.Boolean):
+                    column = each
+                    break
+            if column and list.operator in ('AND', 'OR'):
+                newClause = sql._TextClause( str(column) +
self.__BOOL_HACK)
+                self.traverse( newClause)
+                self.strings[ column] = str( newClause)
+        super(MSSQLCompiler, self).visit_clauselist(list)
+
     def visit_column(self, column):
         # translate for schema-qualified table aliases
         super(MSSQLCompiler, self).visit_column(column)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to