mirror of
https://github.com/django/django.git
synced 2025-05-21 06:16:29 +00:00
Inlined DatabaseIntrospection._table_info() for SQLite.
This commit is contained in:
parent
2804b8d215
commit
e19f58fc01
@ -83,18 +83,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||||||
Return a description of the table with the DB-API cursor.description
|
Return a description of the table with the DB-API cursor.description
|
||||||
interface.
|
interface.
|
||||||
"""
|
"""
|
||||||
|
cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(table_name))
|
||||||
return [
|
return [
|
||||||
FieldInfo(
|
FieldInfo(
|
||||||
info['name'],
|
name, data_type, None, get_field_size(data_type), None, None,
|
||||||
info['type'],
|
not notnull, default, pk == 1,
|
||||||
None,
|
)
|
||||||
info['size'],
|
for cid, name, data_type, notnull, default, pk in cursor.fetchall()
|
||||||
None,
|
|
||||||
None,
|
|
||||||
info['null_ok'],
|
|
||||||
info['default'],
|
|
||||||
info['pk'] == 1,
|
|
||||||
) for info in self._table_info(cursor, table_name)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_sequences(self, cursor, table_name, table_fields=()):
|
def get_sequences(self, cursor, table_name, table_fields=()):
|
||||||
@ -211,18 +206,6 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||||||
return m.group(1) if m.group(1) else m.group(2)
|
return m.group(1) if m.group(1) else m.group(2)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _table_info(self, cursor, name):
|
|
||||||
cursor.execute('PRAGMA table_info(%s)' % self.connection.ops.quote_name(name))
|
|
||||||
# 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_foreign_key_constraints(self, cursor, table_name):
|
def _get_foreign_key_constraints(self, cursor, table_name):
|
||||||
constraints = {}
|
constraints = {}
|
||||||
cursor.execute('PRAGMA foreign_key_list(%s)' % self.connection.ops.quote_name(table_name))
|
cursor.execute('PRAGMA foreign_key_list(%s)' % self.connection.ops.quote_name(table_name))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user