Ticket #11049: 11049_fix.diff
File 11049_fix.diff, 4.9 KB (added by , 16 years ago) |
---|
-
django/db/backends/oracle/introspection.py
21 21 except AttributeError: 22 22 pass 23 23 24 def get_field_type(self, data_type, description): 25 # If it's a NUMBER with scale == 0, consider it an IntegerField 26 if data_type == cx_Oracle.NUMBER and description[5] == 0: 27 return 'IntegerField' 28 else: 29 return super(DatabaseIntrospection, self).get_field_type( 30 data_type, description) 31 24 32 def get_table_list(self, cursor): 25 33 "Returns a list of table names in the current database." 26 34 cursor.execute("SELECT TABLE_NAME FROM USER_TABLES") -
django/db/backends/__init__.py
470 470 def __init__(self, connection): 471 471 self.connection = connection 472 472 473 def get_field_type(self, data_type, description): 474 """Hook for a database backend to use the cursor description to 475 match a Django field type to a database column. 476 477 For Oracle, the column data_type on its own is insufficient to 478 distinguish between a FloatField and IntegerField, for example.""" 479 return self.data_types_reverse[data_type] 480 473 481 def table_name_converter(self, name): 474 482 """Apply a conversion to the name for the purposes of comparison. 475 483 … … 560 568 def validate_field(self, errors, opts, f): 561 569 "By default, there is no backend-specific validation" 562 570 pass 563 -
django/core/management/commands/inspectdb.py
73 73 extra_params['db_column'] = column_name 74 74 else: 75 75 try: 76 field_type = connection.introspection. data_types_reverse[row[1]]76 field_type = connection.introspection.get_field_type(row[1], row) 77 77 except KeyError: 78 78 field_type = 'TextField' 79 79 comment_notes.append('This field type is a guess.') -
django/contrib/gis/management/commands/inspectdb.py
131 131 if srid != 4326: extra_params['srid'] = srid 132 132 else: 133 133 try: 134 field_type = connection.introspection. data_types_reverse[row[1]]134 field_type = connection.introspection.get_field_type(row[1], row) 135 135 except KeyError: 136 136 field_type = 'TextField' 137 137 comment_notes.append('This field type is a guess.') -
tests/regressiontests/introspection/tests.py
76 76 def test_get_table_description_types(self): 77 77 cursor = connection.cursor() 78 78 desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table) 79 self.assertEqual([datatype(r[1] ) for r in desc],79 self.assertEqual([datatype(r[1], r) for r in desc], 80 80 ['IntegerField', 'CharField', 'CharField', 'CharField']) 81 81 82 82 # Regression test for #9991 - 'real' types in postgres … … 86 86 cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);") 87 87 desc = connection.introspection.get_table_description(cursor, 'django_ixn_real_test_table') 88 88 cursor.execute('DROP TABLE django_ixn_real_test_table;') 89 self.assertEqual(datatype(desc[0][1] ), 'FloatField')89 self.assertEqual(datatype(desc[0][1], desc[0]), 'FloatField') 90 90 91 91 def test_get_relations(self): 92 92 cursor = connection.cursor() … … 104 104 indexes = connection.introspection.get_indexes(cursor, Article._meta.db_table) 105 105 self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False}) 106 106 107 def datatype(dbtype): 107 108 def datatype(dbtype, description): 108 109 """Helper to convert a data type into a string.""" 109 dt = connection.introspection. data_types_reverse[dbtype]110 dt = connection.introspection.get_field_type(dbtype, description) 110 111 if type(dt) is tuple: 111 112 return dt[0] 112 113 else: