Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #11049: introspection on Oracle now identifies IntegerF…

…ields correctly.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11476 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 372736b70fbbad70bd66755c65f2919cdad2e8fd 1 parent 0f70fd9
@mboersma mboersma authored
View
2  django/contrib/gis/management/commands/inspectdb.py
@@ -131,7 +131,7 @@ def handle_inspection(self):
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.')
View
2  django/core/management/commands/inspectdb.py
@@ -73,7 +73,7 @@ def handle_inspection(self):
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.')
View
9 django/db/backends/__init__.py
@@ -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
-
View
8 django/db/backends/oracle/introspection.py
@@ -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")
View
9 tests/regressiontests/introspection/tests.py
@@ -76,7 +76,7 @@ def test_get_table_description_names(self):
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 @@ def test_postgresql_real_type(self):
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 @@ def test_get_indexes(self):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.