1
0
mirror of https://github.com/django/django.git synced 2024-12-24 18:16:19 +00:00

Add a SQlite backend. One test passes!

This commit is contained in:
Andrew Godwin 2012-08-18 14:16:52 +01:00
parent 0b01395108
commit d3d1e59921
3 changed files with 17 additions and 6 deletions

View File

@ -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.client import DatabaseClient
from django.db.backends.sqlite3.creation import DatabaseCreation from django.db.backends.sqlite3.creation import DatabaseCreation
from django.db.backends.sqlite3.introspection import DatabaseIntrospection 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.dateparse import parse_date, parse_datetime, parse_time
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.safestring import SafeString from django.utils.safestring import SafeString
@ -336,6 +337,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
if self.settings_dict['NAME'] != ":memory:": if self.settings_dict['NAME'] != ":memory:":
BaseDatabaseWrapper.close(self) 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') FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
class SQLiteCursorWrapper(Database.Cursor): class SQLiteCursorWrapper(Database.Cursor):

View File

@ -0,0 +1,6 @@
from django.db.backends.schema import BaseDatabaseSchemaEditor
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_delete_table = "DROP TABLE %(table)s"

View File

@ -44,18 +44,18 @@ class SchemaTests(TestCase):
# Remove any M2M tables first # Remove any M2M tables first
for field in model._meta.local_many_to_many: for field in model._meta.local_many_to_many:
try: try:
cursor.execute("DROP TABLE %s CASCADE" % ( cursor.execute(connection.schema_editor().sql_delete_table % {
connection.ops.quote_name(field.rel.through._meta.db_table), "table": connection.ops.quote_name(field.rel.through._meta.db_table),
)) })
except DatabaseError: except DatabaseError:
connection.rollback() connection.rollback()
else: else:
connection.commit() connection.commit()
# Then remove the main tables # Then remove the main tables
try: try:
cursor.execute("DROP TABLE %s CASCADE" % ( cursor.execute(connection.schema_editor().sql_delete_table % {
connection.ops.quote_name(model._meta.db_table), "table": connection.ops.quote_name(model._meta.db_table),
)) })
except DatabaseError: except DatabaseError:
connection.rollback() connection.rollback()
else: else: