diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-08-18 14:16:52 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-08-18 14:16:52 +0100 |
| commit | d3d1e599211c31e05d095b878de517dbb6fc998c (patch) | |
| tree | 58993c657ad08afb6249876e7e700ed0d493f5b4 | |
| parent | 0b013951086814ebee048f0fa9a620e03f891494 (diff) | |
Add a SQlite backend. One test passes!
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 5 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/schema.py | 6 | ||||
| -rw-r--r-- | tests/modeltests/schema/tests.py | 12 |
3 files changed, 17 insertions, 6 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 0880079189..7918d5d3ef 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -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): diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py new file mode 100644 index 0000000000..bfd943c6fb --- /dev/null +++ b/django/db/backends/sqlite3/schema.py @@ -0,0 +1,6 @@ +from django.db.backends.schema import BaseDatabaseSchemaEditor + + +class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): + + sql_delete_table = "DROP TABLE %(table)s" diff --git a/tests/modeltests/schema/tests.py b/tests/modeltests/schema/tests.py index 18f1abad63..3d0b106405 100644 --- a/tests/modeltests/schema/tests.py +++ b/tests/modeltests/schema/tests.py @@ -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: |
