mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #30593 -- Added _parse_constraint_columns() hook to introspection on MariaDB.
This commit is contained in:
committed by
Mariusz Felisiak
parent
421c4cd2ee
commit
b2aad9ad4d
@@ -147,6 +147,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
return self.connection.features._mysql_storage_engine
|
||||
return result[0]
|
||||
|
||||
def _parse_constraint_columns(self, check_clause):
|
||||
check_columns = OrderedSet()
|
||||
statement = sqlparse.parse(check_clause)[0]
|
||||
tokens = (token for token in statement.flatten() if not token.is_whitespace)
|
||||
for token in tokens:
|
||||
if token.ttype in [sqlparse.tokens.Name, sqlparse.tokens.Literal.String.Single]:
|
||||
check_columns.add(token.value[1:-1])
|
||||
return check_columns
|
||||
|
||||
def get_constraints(self, cursor, table_name):
|
||||
"""
|
||||
Retrieve any constraints or keys (unique, pk, fk, check, index) across
|
||||
@@ -201,14 +210,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
"""
|
||||
cursor.execute(type_query, [table_name])
|
||||
for constraint, check_clause in cursor.fetchall():
|
||||
# Parse columns.
|
||||
columns = OrderedSet()
|
||||
for statement in sqlparse.parse(check_clause):
|
||||
for token in statement.flatten():
|
||||
if token.ttype in [sqlparse.tokens.Name, sqlparse.tokens.Literal.String.Single]:
|
||||
columns.add(token.value[1:-1])
|
||||
constraints[constraint] = {
|
||||
'columns': columns,
|
||||
'columns': self._parse_constraint_columns(check_clause),
|
||||
'primary_key': False,
|
||||
'unique': False,
|
||||
'index': False,
|
||||
|
||||
Reference in New Issue
Block a user