summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-04-04 19:03:55 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-04-04 19:03:55 +0000
commit48e01d2b3db28be153feae7f3cecb09941a4e41b (patch)
tree4473bab708609bd913e80e3016304c842f3838d5 /django
parentbb31cf37ff2bcb8432753f27c40998467d42585c (diff)
Fixed up the introspection code and tests added for #9779 to run under Python 2.3, which has neither set nor rsplit.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10392 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/sqlite3/introspection.py72
1 files changed, 36 insertions, 36 deletions
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 50d53bbe0b..b58e6a7faf 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -56,54 +56,54 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
info['null_ok']) for info in self._table_info(cursor, table_name)]
def get_relations(self, cursor, table_name):
- """
- Returns a dictionary of {field_index: (field_index_other_table, other_table)}
- representing all relationships to the given table. Indexes are 0-based.
- """
-
- # Dictionary of relations to return
- relations = {}
-
- # Schema for this table
- cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table_name])
- results = cursor.fetchone()[0].strip()
- results = results.split('(', 1)[1]
- results = results.rsplit(')', 1)[0]
-
+ """
+ Returns a dictionary of {field_index: (field_index_other_table, other_table)}
+ representing all relationships to the given table. Indexes are 0-based.
+ """
+
+ # Dictionary of relations to return
+ relations = {}
+
+ # Schema for this table
+ cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table_name])
+ 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
-
+ for field_index, field_desc in enumerate(results.split(',')):
+ field_desc = field_desc.strip()
+ if field_desc.startswith("UNIQUE"):
+ continue
+
m = re.search('references (.*) \(["|](.*)["|]\)', field_desc, re.I)
- if not m:
- continue
-
+ if not m:
+ continue
+
table, column = [s.strip('"') for s in m.groups()]
-
+
cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table])
result = cursor.fetchone()
if not result:
continue
- other_table_results = result[0].strip()
- other_table_results = other_table_results.split('(', 1)[1]
- other_table_results = other_table_results.rsplit(')', 1)[0]
-
- for other_index, other_desc in enumerate(other_table_results.split(',')):
- other_desc = other_desc.strip()
- if other_desc.startswith('UNIQUE'):
- continue
-
- name = other_desc.split(' ', 1)[0].strip('"')
- if name == column:
+ other_table_results = result[0].strip()
+ li, ri = other_table_results.index('('), other_table_results.rindex(')')
+ other_table_results = other_table_results[li+1:ri]
+
+
+ for other_index, other_desc in enumerate(other_table_results.split(',')):
+ other_desc = other_desc.strip()
+ if other_desc.startswith('UNIQUE'):
+ continue
+
+ name = other_desc.split(' ', 1)[0].strip('"')
+ if name == column:
relations[field_index] = (other_index, table)
break
-
+
return relations
-
+
def get_indexes(self, cursor, table_name):
"""
Returns a dictionary of fieldname -> infodict for the given table,