Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed getting max_digits for MySQL decimal fields

Refs #5014.
  • Loading branch information...
commit 51028f50b624efae273dcbe828ec80c1846c74dc 1 parent a01361b
Claude Paroz authored April 01, 2013
11  django/db/backends/mysql/introspection.py
@@ -47,8 +47,17 @@ def get_table_description(self, cursor, table_name):
47 47
                 AND character_maximum_length IS NOT NULL""", [table_name])
48 48
         length_map = dict(cursor.fetchall())
49 49
 
  50
+        # Also getting precision and scale from information_schema (see #5014)
  51
+        cursor.execute("""
  52
+            SELECT column_name, numeric_precision, numeric_scale FROM information_schema.columns
  53
+            WHERE table_name = %s AND table_schema = DATABASE()
  54
+                AND data_type='decimal'""", [table_name])
  55
+        numeric_map = dict([(line[0], tuple([int(n) for n in line[1:]])) for line in cursor.fetchall()])
  56
+
50 57
         cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
51  
-        return [FieldInfo(*(line[:3] + (length_map.get(line[0], line[3]),) + line[4:]))
  58
+        return [FieldInfo(*(line[:3] + (length_map.get(line[0], line[3]),)
  59
+                                     + numeric_map.get(line[0], line[4:6])
  60
+                                     + (line[6],)))
52 61
             for line in cursor.description]
53 62
 
54 63
     def _name_to_index(self, cursor, table_name):
2  tests/inspectdb/tests.py
@@ -57,8 +57,6 @@ def assertFieldType(name, definition):
57 57
         if connection.vendor == 'sqlite':
58 58
             # Ticket #5014
59 59
             assertFieldType('decimal_field', "models.DecimalField(max_digits=None, decimal_places=None)")
60  
-        elif connection.vendor == 'mysql':
61  
-            pass # Ticket #5014
62 60
         else:
63 61
             assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)")
64 62
         assertFieldType('email_field', "models.CharField(max_length=75)")

0 notes on commit 51028f5

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