mirror of
https://github.com/django/django.git
synced 2024-12-24 10:05:46 +00:00
Add a SQlite backend. One test passes!
This commit is contained in:
parent
0b01395108
commit
d3d1e59921
@ -18,6 +18,7 @@ from django.db.backends.signals import connection_created
|
||||
from django.db.backends.sqlite3.client import DatabaseClient
|
||||
from django.db.backends.sqlite3.creation import DatabaseCreation
|
||||
from django.db.backends.sqlite3.introspection import DatabaseIntrospection
|
||||
from django.db.backends.sqlite3.schema import DatabaseSchemaEditor
|
||||
from django.utils.dateparse import parse_date, parse_datetime, parse_time
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.safestring import SafeString
|
||||
@ -336,6 +337,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
if self.settings_dict['NAME'] != ":memory:":
|
||||
BaseDatabaseWrapper.close(self)
|
||||
|
||||
def schema_editor(self):
|
||||
"Returns a new instance of this backend's SchemaEditor"
|
||||
return DatabaseSchemaEditor(self)
|
||||
|
||||
FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
|
||||
|
||||
class SQLiteCursorWrapper(Database.Cursor):
|
||||
|
6
django/db/backends/sqlite3/schema.py
Normal file
6
django/db/backends/sqlite3/schema.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.db.backends.schema import BaseDatabaseSchemaEditor
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
sql_delete_table = "DROP TABLE %(table)s"
|
@ -44,18 +44,18 @@ class SchemaTests(TestCase):
|
||||
# Remove any M2M tables first
|
||||
for field in model._meta.local_many_to_many:
|
||||
try:
|
||||
cursor.execute("DROP TABLE %s CASCADE" % (
|
||||
connection.ops.quote_name(field.rel.through._meta.db_table),
|
||||
))
|
||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||
"table": connection.ops.quote_name(field.rel.through._meta.db_table),
|
||||
})
|
||||
except DatabaseError:
|
||||
connection.rollback()
|
||||
else:
|
||||
connection.commit()
|
||||
# Then remove the main tables
|
||||
try:
|
||||
cursor.execute("DROP TABLE %s CASCADE" % (
|
||||
connection.ops.quote_name(model._meta.db_table),
|
||||
))
|
||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||
"table": connection.ops.quote_name(model._meta.db_table),
|
||||
})
|
||||
except DatabaseError:
|
||||
connection.rollback()
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user