summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/base.py4
-rw-r--r--django/db/backends/sqlite3/introspection.py29
2 files changed, 2 insertions, 31 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 666b367be7..fbad8039d8 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -360,8 +360,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
primary_key_column_name = self.introspection.get_primary_key_column(cursor, table_name)
if not primary_key_column_name:
continue
- key_columns = self.introspection.get_key_columns(cursor, table_name)
- for column_name, referenced_table_name, referenced_column_name in key_columns:
+ relations = self.introspection.get_relations(cursor, table_name)
+ for column_name, (referenced_column_name, referenced_table_name) in relations:
cursor.execute(
"""
SELECT REFERRING.`%s`, REFERRING.`%s` FROM `%s` as REFERRING
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index f1f33579b9..87894967fc 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -170,35 +170,6 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
return relations
- def get_key_columns(self, cursor, table_name):
- """
- Return a list of (column_name, referenced_table_name, referenced_column_name)
- for all key columns in given table.
- """
- key_columns = []
-
- # Schema for this table
- cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"])
- results = cursor.fetchone()[0].strip()
- results = results[results.index('(') + 1:results.rindex(')')]
-
- # Walk through and look for references to other tables. SQLite doesn't
- # really have enforced references, but since it echoes out the SQL used
- # to create the table we can look for REFERENCES statements used there.
- for field_index, field_desc in enumerate(results.split(',')):
- field_desc = field_desc.strip()
- if field_desc.startswith("UNIQUE"):
- continue
-
- m = re.search(r'"(.*)".*references (.*) \(["|](.*)["|]\)', field_desc, re.I)
- if not m:
- continue
-
- # This will append (column_name, referenced_table_name, referenced_column_name) to key_columns
- key_columns.append(tuple(s.strip('"') for s in m.groups()))
-
- return key_columns
-
def get_primary_key_column(self, cursor, table_name):
"""Return the column name of the primary key for the given table."""
cursor.execute(