Commit 372736b7 authored by Matt Boersma's avatar Matt Boersma
Browse files

[1.0.X] Fixed #11049: introspection on Oracle now identifies IntegerFields correctly.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11476 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 0f70fd99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ class Command(InspectCommand):
                        if srid != 4326: extra_params['srid'] = srid
                    else:
                        try:
                            field_type = connection.introspection.data_types_reverse[row[1]]
                            field_type = connection.introspection.get_field_type(row[1], row)
                        except KeyError:
                            field_type = 'TextField'
                            comment_notes.append('This field type is a guess.')
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class Command(NoArgsCommand):
                        extra_params['db_column'] = column_name
                else:
                    try:
                        field_type = connection.introspection.data_types_reverse[row[1]]
                        field_type = connection.introspection.get_field_type(row[1], row)
                    except KeyError:
                        field_type = 'TextField'
                        comment_notes.append('This field type is a guess.')
+8 −1
Original line number Diff line number Diff line
@@ -384,6 +384,14 @@ class BaseDatabaseIntrospection(object):
    def __init__(self, connection):
        self.connection = connection

    def get_field_type(self, data_type, description):
        """Hook for a database backend to use the cursor description to
        match a Django field type to a database column.

        For Oracle, the column data_type on its own is insufficient to
        distinguish between a FloatField and IntegerField, for example."""
        return self.data_types_reverse[data_type]

    def table_name_converter(self, name):
        """Apply a conversion to the name for the purposes of comparison.

@@ -466,4 +474,3 @@ class BaseDatabaseValidation(object):
    def validate_field(self, errors, opts, f):
        "By default, there is no backend-specific validation"
        pass
+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,14 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
    except AttributeError:
        pass

    def get_field_type(self, data_type, description):
        # If it's a NUMBER with scale == 0, consider it an IntegerField
        if data_type == cx_Oracle.NUMBER and description[5] == 0:
            return 'IntegerField'
        else:
            return super(DatabaseIntrospection, self).get_field_type(
                data_type, description)

    def get_table_list(self, cursor):
        "Returns a list of table names in the current database."
        cursor.execute("SELECT TABLE_NAME FROM USER_TABLES")
+5 −4
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ class IntrospectionTests(TestCase):
    def test_get_table_description_types(self):
        cursor = connection.cursor()
        desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
        self.assertEqual([datatype(r[1]) for r in desc],
        self.assertEqual([datatype(r[1], r) for r in desc],
                          ['IntegerField', 'CharField', 'CharField', 'CharField'])

    # Regression test for #9991 - 'real' types in postgres
@@ -86,7 +86,7 @@ class IntrospectionTests(TestCase):
            cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);")
            desc = connection.introspection.get_table_description(cursor, 'django_ixn_real_test_table')
            cursor.execute('DROP TABLE django_ixn_real_test_table;')
            self.assertEqual(datatype(desc[0][1]), 'FloatField')
            self.assertEqual(datatype(desc[0][1], desc[0]), 'FloatField')

    def test_get_relations(self):
        cursor = connection.cursor()
@@ -104,9 +104,10 @@ class IntrospectionTests(TestCase):
        indexes = connection.introspection.get_indexes(cursor, Article._meta.db_table)
        self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False})

def datatype(dbtype):

def datatype(dbtype, description):
    """Helper to convert a data type into a string."""
    dt = connection.introspection.data_types_reverse[dbtype]
    dt = connection.introspection.get_field_type(dbtype, description)
    if type(dt) is tuple:
        return dt[0]
    else: