summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-12-29 11:41:16 -0500
committerTim Graham <timograham@gmail.com>2015-01-31 12:33:11 -0500
commit75303b01a9cc900eebf1f27ba0bc6508334242fc (patch)
tree2a5da4f8a8036b5f833caa776ecec20dd81774d4 /django/db/backends/sqlite3
parent64a899dc815f1a070dc7a7c22276e8bb41e46ea6 (diff)
Fixed #24245 -- Added introspection for database defaults.
Needed for tests for migrations handling of database defaults.
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/introspection.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 13b658bd6a..a002b79933 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -1,4 +1,5 @@
import re
+from collections import namedtuple
from django.db.backends.base.introspection import (
BaseDatabaseIntrospection, FieldInfo, TableInfo,
@@ -6,6 +7,7 @@ from django.db.backends.base.introspection import (
field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
+FieldInfo = namedtuple('FieldInfo', FieldInfo._fields + ('default',))
def get_field_size(name):
@@ -69,8 +71,18 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
def get_table_description(self, cursor, table_name):
"Returns a description of the table, with the DB-API cursor.description interface."
- return [FieldInfo(info['name'], info['type'], None, info['size'], None, None,
- info['null_ok']) for info in self._table_info(cursor, table_name)]
+ return [
+ FieldInfo(
+ info['name'],
+ info['type'],
+ None,
+ info['size'],
+ None,
+ None,
+ info['null_ok'],
+ info['default'],
+ ) for info in self._table_info(cursor, table_name)
+ ]
def column_name_converter(self, name):
"""
@@ -211,13 +223,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
def _table_info(self, cursor, name):
cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(name))
- # cid, name, type, notnull, dflt_value, pk
- return [{'name': field[1],
- 'type': field[2],
- 'size': get_field_size(field[2]),
- 'null_ok': not field[3],
- 'pk': field[5] # undocumented
- } for field in cursor.fetchall()]
+ # cid, name, type, notnull, default_value, pk
+ return [{
+ 'name': field[1],
+ 'type': field[2],
+ 'size': get_field_size(field[2]),
+ 'null_ok': not field[3],
+ 'default': field[4],
+ 'pk': field[5], # undocumented
+ } for field in cursor.fetchall()]
def get_constraints(self, cursor, table_name):
"""