Commits

Mike Bayer committed 2a507fb

- fixed generation of CHECK constraints on columns [ticket:464]

Comments (0)

Files changed (4)

   for named args, or a list of list or dicts to invoke executemany()
   - small fix to BoundMetaData to accept unicode or string URLs
   - fixed named PrimaryKeyConstraint generation [ticket:466] courtesy andrija at gmail
+  - fixed generation of CHECK constraints on columns [ticket:464]
 - orm:
   - another refactoring to relationship calculation.  Allows more accurate ORM behavior
   with relationships from/to/between mappers, particularly polymorphic mappers,

lib/sqlalchemy/ansisql.py

         if constraint.name is not None:
             self.append("CONSTRAINT %s " % constraint.name)
         self.append(" CHECK (%s)" % constraint.sqltext)
+
+    def visit_column_check_constraint(self, constraint):
+        self.append(" ")
+        self.append(" CHECK (%s)" % constraint.sqltext)
         
     def visit_primary_key_constraint(self, constraint):
         if len(constraint) == 0:

lib/sqlalchemy/schema.py

         super(CheckConstraint, self).__init__(name)
         self.sqltext = sqltext
     def accept_schema_visitor(self, visitor, traverse=True):
-        visitor.visit_check_constraint(self)
+        if isinstance(self.parent, Table):
+            visitor.visit_check_constraint(self)
+        else:
+            visitor.visit_column_check_constraint(self)
     def _set_parent(self, parent):
         self.parent = parent
         parent.constraints.add(self)
         pass
     def visit_check_constraint(self, constraint):
         pass
+    def visit_column_check_constraint(self, constraint):
+        pass
         
 default_metadata = DynamicMetaData('default')
 

test/sql/constraints.py

             )
         metadata.create_all()
 
-    @testbase.unsupported('sqlite', 'mysql')
+    @testbase.unsupported('mysql')
     def test_check_constraint(self):
         foo = Table('foo', metadata, 
             Column('id', Integer, primary_key=True),
         bar = Table('bar', metadata, 
             Column('id', Integer, primary_key=True),
             Column('x', Integer, CheckConstraint('x>7')),
+            Column('z', Integer)
             )
 
         metadata.create_all()