mirror of https://github.com/django/django.git
Required sqlparse for SQL splitting per deprecation timeline.
This commit is contained in:
parent
4aa089a9a9
commit
b845951fd4
|
@ -1,7 +1,5 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.core.management.base import CommandError
|
from django.core.management.base import CommandError
|
||||||
from django.db import models, router
|
from django.db import models, router
|
||||||
|
@ -168,22 +166,6 @@ def sql_all(app_config, style, connection):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _split_statements(content):
|
|
||||||
# Private API only called from code that emits a RemovedInDjango19Warning.
|
|
||||||
comment_re = re.compile(r"^((?:'[^']*'|[^'])*?)--.*$")
|
|
||||||
statements = []
|
|
||||||
statement = []
|
|
||||||
for line in content.split("\n"):
|
|
||||||
cleaned_line = comment_re.sub(r"\1", line).strip()
|
|
||||||
if not cleaned_line:
|
|
||||||
continue
|
|
||||||
statement.append(cleaned_line)
|
|
||||||
if cleaned_line.endswith(";"):
|
|
||||||
statements.append(" ".join(statement))
|
|
||||||
statement = []
|
|
||||||
return statements
|
|
||||||
|
|
||||||
|
|
||||||
def emit_pre_migrate_signal(verbosity, interactive, db):
|
def emit_pre_migrate_signal(verbosity, interactive, db):
|
||||||
# Emit the pre_migrate signal for every application.
|
# Emit the pre_migrate signal for every application.
|
||||||
for app_config in apps.get_app_configs():
|
for app_config in apps.get_app_configs():
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db.backends import utils
|
from django.db.backends import utils
|
||||||
from django.utils import six, timezone
|
from django.utils import six, timezone
|
||||||
from django.utils.dateparse import parse_duration
|
from django.utils.dateparse import parse_duration
|
||||||
from django.utils.deprecation import RemovedInDjango19Warning
|
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,7 +254,7 @@ class BaseDatabaseOperations(object):
|
||||||
"""
|
"""
|
||||||
return 'DEFAULT'
|
return 'DEFAULT'
|
||||||
|
|
||||||
def prepare_sql_script(self, sql, _allow_fallback=False):
|
def prepare_sql_script(self, sql):
|
||||||
"""
|
"""
|
||||||
Takes a SQL script that may contain multiple lines and returns a list
|
Takes a SQL script that may contain multiple lines and returns a list
|
||||||
of statements to feed to successive cursor.execute() calls.
|
of statements to feed to successive cursor.execute() calls.
|
||||||
|
@ -264,21 +263,13 @@ class BaseDatabaseOperations(object):
|
||||||
cursor.execute() call and PEP 249 doesn't talk about this use case,
|
cursor.execute() call and PEP 249 doesn't talk about this use case,
|
||||||
the default implementation is conservative.
|
the default implementation is conservative.
|
||||||
"""
|
"""
|
||||||
# Remove _allow_fallback and keep only 'return ...' in Django 1.9.
|
|
||||||
try:
|
try:
|
||||||
# This import must stay inside the method because it's optional.
|
|
||||||
import sqlparse
|
import sqlparse
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if _allow_fallback:
|
raise ImproperlyConfigured(
|
||||||
# Without sqlparse, fall back to the legacy (and buggy) logic.
|
"sqlparse is required if you don't split your SQL "
|
||||||
warnings.warn(
|
"statements manually."
|
||||||
"Providing initial SQL data on a %s database will require "
|
)
|
||||||
"sqlparse in Django 1.9." % self.connection.vendor,
|
|
||||||
RemovedInDjango19Warning)
|
|
||||||
from django.core.management.sql import _split_statements
|
|
||||||
return _split_statements(sql)
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
else:
|
else:
|
||||||
return [sqlparse.format(statement, strip_comments=True)
|
return [sqlparse.format(statement, strip_comments=True)
|
||||||
for statement in sqlparse.split(sql) if statement]
|
for statement in sqlparse.split(sql) if statement]
|
||||||
|
|
|
@ -86,7 +86,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def no_limit_value(self):
|
def no_limit_value(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def prepare_sql_script(self, sql, _allow_fallback=False):
|
def prepare_sql_script(self, sql):
|
||||||
return [sql]
|
return [sql]
|
||||||
|
|
||||||
def quote_name(self, name):
|
def quote_name(self, name):
|
||||||
|
|
Loading…
Reference in New Issue