Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9991: correctly introspect PostgreSQL 'real' types.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ffffdedfd16ec9e8471368afab15782adddf3452 1 parent 374b02e
Jacob Kaplan-Moss authored April 03, 2009
1  django/db/backends/postgresql/introspection.py
@@ -7,6 +7,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
7 7
         21: 'SmallIntegerField',
8 8
         23: 'IntegerField',
9 9
         25: 'TextField',
  10
+        700: 'FloatField',
10 11
         701: 'FloatField',
11 12
         869: 'IPAddressField',
12 13
         1043: 'CharField',
35  tests/regressiontests/introspection/tests.py
... ...
@@ -1,3 +1,4 @@
  1
+from django.conf import settings
1 2
 from django.db import connection
2 3
 from django.test import TestCase
3 4
 from django.utils import functional
@@ -44,11 +45,11 @@ def test_table_names(self):
44 45
                      
45 46
     def test_django_table_names(self):
46 47
         cursor = connection.cursor()
47  
-        cursor.execute('CREATE TABLE django_introspection_testcase_table (id INTEGER);');
  48
+        cursor.execute('CREATE TABLE django_introspection_test_table (id INTEGER);');
48 49
         tl = connection.introspection.django_table_names()
  50
+        cursor.execute("DROP TABLE django_introspection_test_table;")
49 51
         self.assert_('django_introspection_testcase_table' not in tl,
50 52
                      "django_table_names() returned a non-Django table")
51  
-        cursor.execute("DROP TABLE django_introspection_testcase_table;")
52 53
                         
53 54
     def test_installed_models(self):
54 55
         tables = [Article._meta.db_table, Reporter._meta.db_table]
@@ -68,20 +69,20 @@ def test_get_table_description_names(self):
68 69
                          [f.column for f in Reporter._meta.fields])
69 70
     
70 71
     def test_get_table_description_types(self):
71  
-        cursor = connection.cursor()
  72
+        cursor = connection.cursor()            
72 73
         desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
73  
-
74  
-        # Convert the datatype into a string
75  
-        def datatype(dbtype):
76  
-            dt = connection.introspection.data_types_reverse[dbtype]
77  
-            if type(dt) is tuple:
78  
-                return dt[0]
79  
-            else:
80  
-                return dt
81  
-            
82 74
         self.assertEqual([datatype(r[1]) for r in desc],
83 75
                           ['IntegerField', 'CharField', 'CharField', 'CharField'])
84 76
 
  77
+    # Regression test for #9991 - 'real' types in postgres
  78
+    if settings.DATABASE_ENGINE.startswith('postgresql'):
  79
+        def test_postgresql_real_type(self):
  80
+            cursor = connection.cursor()
  81
+            cursor.execute("CREATE TABLE django_introspection_real_test_table (number REAL);") 
  82
+            desc = connection.introspection.get_table_description(cursor, 'django_introspection_real_test_table')
  83
+            cursor.execute('DROP TABLE django_introspection_real_test_table;')
  84
+            self.assertEqual(datatype(desc[0][1]), 'FloatField')
  85
+
85 86
     def test_get_relations(self):
86 87
         cursor = connection.cursor()
87 88
         relations = connection.introspection.get_relations(cursor, Article._meta.db_table)
@@ -96,4 +97,12 @@ def test_get_relations(self):
96 97
     def test_get_indexes(self):
97 98
         cursor = connection.cursor()
98 99
         indexes = connection.introspection.get_indexes(cursor, Article._meta.db_table)
99  
-        self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False})
  100
+        self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False})
  101
+        
  102
+def datatype(dbtype):
  103
+    """Helper to convert a data type into a string."""
  104
+    dt = connection.introspection.data_types_reverse[dbtype]
  105
+    if type(dt) is tuple:
  106
+        return dt[0]
  107
+    else:
  108
+        return dt

0 notes on commit ffffded

Please sign in to comment.
Something went wrong with that request. Please try again.