Author: mboersma
Date: 2009-08-21 16:43:09 -0500 (Fri, 21 Aug 2009)
New Revision: 11476

Modified:
   
django/branches/releases/1.0.X/django/contrib/gis/management/commands/inspectdb.py
   django/branches/releases/1.0.X/django/core/management/commands/inspectdb.py
   django/branches/releases/1.0.X/django/db/backends/__init__.py
   django/branches/releases/1.0.X/django/db/backends/oracle/introspection.py
   django/branches/releases/1.0.X/tests/regressiontests/introspection/tests.py
Log:
[1.0.X] Fixed #11049: introspection on Oracle now identifies IntegerFields 
correctly.


Modified: 
django/branches/releases/1.0.X/django/contrib/gis/management/commands/inspectdb.py
===================================================================
--- 
django/branches/releases/1.0.X/django/contrib/gis/management/commands/inspectdb.py
  2009-08-21 21:42:39 UTC (rev 11475)
+++ 
django/branches/releases/1.0.X/django/contrib/gis/management/commands/inspectdb.py
  2009-08-21 21:43:09 UTC (rev 11476)
@@ -131,7 +131,7 @@
                         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.')

Modified: 
django/branches/releases/1.0.X/django/core/management/commands/inspectdb.py
===================================================================
--- django/branches/releases/1.0.X/django/core/management/commands/inspectdb.py 
2009-08-21 21:42:39 UTC (rev 11475)
+++ django/branches/releases/1.0.X/django/core/management/commands/inspectdb.py 
2009-08-21 21:43:09 UTC (rev 11476)
@@ -73,7 +73,7 @@
                         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.')

Modified: django/branches/releases/1.0.X/django/db/backends/__init__.py
===================================================================
--- django/branches/releases/1.0.X/django/db/backends/__init__.py       
2009-08-21 21:42:39 UTC (rev 11475)
+++ django/branches/releases/1.0.X/django/db/backends/__init__.py       
2009-08-21 21:43:09 UTC (rev 11476)
@@ -384,6 +384,14 @@
     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 @@
     def validate_field(self, errors, opts, f):
         "By default, there is no backend-specific validation"
         pass
-

Modified: 
django/branches/releases/1.0.X/django/db/backends/oracle/introspection.py
===================================================================
--- django/branches/releases/1.0.X/django/db/backends/oracle/introspection.py   
2009-08-21 21:42:39 UTC (rev 11475)
+++ django/branches/releases/1.0.X/django/db/backends/oracle/introspection.py   
2009-08-21 21:43:09 UTC (rev 11476)
@@ -26,6 +26,14 @@
     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")

Modified: 
django/branches/releases/1.0.X/tests/regressiontests/introspection/tests.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/introspection/tests.py 
2009-08-21 21:42:39 UTC (rev 11475)
+++ django/branches/releases/1.0.X/tests/regressiontests/introspection/tests.py 
2009-08-21 21:43:09 UTC (rev 11476)
@@ -76,7 +76,7 @@
     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 @@
             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 @@
         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:


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to