Commits

shaib committed 9425a78

Add "has_booleans" backend feature and use it for fixing default values
and in tests.
Set the feature for oracle and sql_server, which don't have booleans.

  • Participants
  • Parent commits 95ef496

Comments (0)

Files changed (4)

File south/db/generic.py

     allows_combined_alters = True
     supports_foreign_keys = True
     has_check_constraints = True
+    has_booleans = True
+
     @cached_property
     def has_ddl_transactions(self):
         self._possibly_initialise()
                             default = default()
                             
                         default = field.get_db_prep_save(default, connection=self._get_connection())
+                        default = self._default_value_workaround(default)
                         # Now do some very cheap quoting. TODO: Redesign return values to avoid this.
                         if isinstance(default, basestring):
                             default = "'%s'" % default.replace("'", "''")
         """
         return field
 
+    def _default_value_workaround(self, value):
+        """
+        DBMS-specific value alterations (this really works around
+        missing functionality in Django backends)
+        """
+        if isinstance(value, bool) and not self.has_booleans:
+            return int(value)
+        else:
+            return value 
 
     def foreign_key_sql(self, from_table_name, from_column_name, to_table_name, to_column_name):
         """

File south/db/oracle.py

     add_constraint_string =     'ALTER TABLE %(table_name)s ADD CONSTRAINT %(constraint)s %(clause)s'
 
     allows_combined_alters = False
+    has_booleans = False
     
     constraints_dict = {
         'P': 'PRIMARY KEY',

File south/db/sql_server/pyodbc.py

     
     
     default_schema_name = "dbo"
+    
+    has_booleans = False
 
 
     @delete_column_constraints
         else:
             #TODO: Anybody else needs special translations?
             return str(value) 
-
+        
     def _quote_string(self, s):
         return "'" + s.replace("'","''") + "'"
     

File south/tests/db.py

         db.create_table("test_textdef", [
             ('textcol', models.TextField(blank=True)),
         ])
-    
+
     def test_add_unique_fk(self):
         """
         Test adding a ForeignKey with unique=True or a OneToOneField
                     return value
                 return map(int, value.split(','))
 
+        false_value = db.has_booleans and 'False' or '0' 
         defaults = (
             (models.DateTimeField(default=datetime(2012, 12, 21, 0, 0, 1)), 'DEFAULT \'2012-12-21 00:00:01'),
             (models.CharField(default='sukasuka'), 'DEFAULT \'sukasuka'),
-            (models.BooleanField(default=False), 'DEFAULT False'),
+            (models.BooleanField(default=False), 'DEFAULT %s' % false_value),
             (models.IntegerField(default=42), 'DEFAULT 42'),
             (CustomField(default=[2012,2018,2021,2036]), 'DEFAULT \'2012,2018,2021,2036')
         )
         for field, sql_test_str in defaults:
             sql = db.column_sql('fish', 'YAAAAAAZ', field)
             if sql_test_str not in sql:
-                self.fail("default sql value was not properly generated for field %r." % field)
+                self.fail("default sql value was not properly generated for field %r.\nSql was %s" % (field,sql))