Skip to content

Commit

Permalink
Add a SQlite backend. One test passes!
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Aug 18, 2012
1 parent 0b01395 commit d3d1e59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions django/db/backends/sqlite3/base.py
Expand Up @@ -18,6 +18,7 @@
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
Expand Down Expand Up @@ -336,6 +337,10 @@ def close(self):
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):
Expand Down
6 changes: 6 additions & 0 deletions 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"
12 changes: 6 additions & 6 deletions tests/modeltests/schema/tests.py
Expand Up @@ -44,18 +44,18 @@ def tearDown(self):
# 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:
Expand Down

0 comments on commit d3d1e59

Please sign in to comment.