mirror / django-1.0.X (http://djangoproject.com/)
Mirror of the 1.0.X maintenance release branch.
$ hg clone http://bitbucket.org/mirror/django-10x/
| commit 737: | a16c10697701 |
| parent 736: | 92fa4c03b4b1 |
| branch: | default |
7 months ago
Changed (Δ767 bytes):
django/contrib/gis/management/commands/inspectdb.py (1 lines added, 1 lines removed)
django/core/management/commands/inspectdb.py (1 lines added, 1 lines removed)
django/db/backends/__init__.py (8 lines added, 1 lines removed)
django/db/backends/oracle/introspection.py (8 lines added, 0 lines removed)
tests/regressiontests/introspection/tests.py (5 lines added, 4 lines removed)
Up to file-list django/contrib/gis/management/commands/inspectdb.py:
| … | … | @@ -131,7 +131,7 @@ class Command(InspectCommand): |
131 |
131 |
if srid != 4326: extra_params['srid'] = srid |
132 |
132 |
else: |
133 |
133 |
try: |
134 |
field_type = connection.introspection. |
|
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.') |
Up to file-list django/core/management/commands/inspectdb.py:
| … | … | @@ -73,7 +73,7 @@ class Command(NoArgsCommand): |
73 |
73 |
extra_params['db_column'] = column_name |
74 |
74 |
else: |
75 |
75 |
try: |
76 |
field_type = connection.introspection. |
|
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.') |
Up to file-list django/db/backends/__init__.py:
| … | … | @@ -384,6 +384,14 @@ class BaseDatabaseIntrospection(object): |
384 |
384 |
def __init__(self, connection): |
385 |
385 |
self.connection = connection |
386 |
386 |
|
387 |
def get_field_type(self, data_type, description): |
|
388 |
"""Hook for a database backend to use the cursor description to |
|
389 |
match a Django field type to a database column. |
|
390 |
||
391 |
For Oracle, the column data_type on its own is insufficient to |
|
392 |
distinguish between a FloatField and IntegerField, for example.""" |
|
393 |
return self.data_types_reverse[data_type] |
|
394 |
||
387 |
395 |
def table_name_converter(self, name): |
388 |
396 |
"""Apply a conversion to the name for the purposes of comparison. |
389 |
397 |
|
| … | … | @@ -466,4 +474,3 @@ class BaseDatabaseValidation(object): |
466 |
474 |
def validate_field(self, errors, opts, f): |
467 |
475 |
"By default, there is no backend-specific validation" |
468 |
476 |
pass |
469 |
Up to file-list django/db/backends/oracle/introspection.py:
| … | … | @@ -26,6 +26,14 @@ class DatabaseIntrospection(BaseDatabase |
26 |
26 |
except AttributeError: |
27 |
27 |
pass |
28 |
28 |
|
29 |
def get_field_type(self, data_type, description): |
|
30 |
# If it's a NUMBER with scale == 0, consider it an IntegerField |
|
31 |
if data_type == cx_Oracle.NUMBER and description[5] == 0: |
|
32 |
return 'IntegerField' |
|
33 |
else: |
|
34 |
return super(DatabaseIntrospection, self).get_field_type( |
|
35 |
data_type, description) |
|
36 |
||
29 |
37 |
def get_table_list(self, cursor): |
30 |
38 |
"Returns a list of table names in the current database." |
31 |
39 |
cursor.execute("SELECT TABLE_NAME FROM USER_TABLES") |
Up to file-list tests/regressiontests/introspection/tests.py:
| … | … | @@ -76,7 +76,7 @@ class IntrospectionTests(TestCase): |
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] |
|
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,7 +86,7 @@ class IntrospectionTests(TestCase): |
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] |
|
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,9 +104,10 @@ class IntrospectionTests(TestCase): |
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. |
|
110 |
dt = connection.introspection.get_field_type(dbtype, description) |
|
110 |
111 |
if type(dt) is tuple: |
111 |
112 |
return dt[0] |
112 |
113 |
else: |
