mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
A large number of stylistic cleanups across django/db/
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import re
|
||||
|
||||
from django.db.backends import BaseDatabaseIntrospection, FieldInfo
|
||||
|
||||
|
||||
field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
|
||||
|
||||
|
||||
def get_field_size(name):
|
||||
""" Extract the size number from a "varchar(11)" type name """
|
||||
m = field_size_re.search(name)
|
||||
@@ -46,6 +49,7 @@ class FlexibleFieldLookupDict(object):
|
||||
return ('CharField', {'max_length': size})
|
||||
raise KeyError
|
||||
|
||||
|
||||
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
data_types_reverse = FlexibleFieldLookupDict()
|
||||
|
||||
@@ -76,7 +80,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
# 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(')')]
|
||||
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
|
||||
@@ -96,8 +100,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
result = cursor.fetchall()[0]
|
||||
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]
|
||||
|
||||
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()
|
||||
@@ -121,7 +124,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
# 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(')')]
|
||||
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
|
||||
@@ -166,7 +169,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
# Don't use PRAGMA because that causes issues with some transactions
|
||||
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(')')]
|
||||
results = results[results.index('(') + 1:results.rindex(')')]
|
||||
for field_desc in results.split(','):
|
||||
field_desc = field_desc.strip()
|
||||
m = re.search('"(.*)".*PRIMARY KEY$', field_desc)
|
||||
|
||||
Reference in New Issue
Block a user