Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a SQlite backend. One test passes!

  • Loading branch information...
commit d3d1e599211c31e05d095b878de517dbb6fc998c 1 parent 0b01395
Andrew Godwin authored August 18, 2012
5  django/db/backends/sqlite3/base.py
@@ -18,6 +18,7 @@
18 18
 from django.db.backends.sqlite3.client import DatabaseClient
19 19
 from django.db.backends.sqlite3.creation import DatabaseCreation
20 20
 from django.db.backends.sqlite3.introspection import DatabaseIntrospection
  21
+from django.db.backends.sqlite3.schema import DatabaseSchemaEditor
21 22
 from django.utils.dateparse import parse_date, parse_datetime, parse_time
22 23
 from django.utils.functional import cached_property
23 24
 from django.utils.safestring import SafeString
@@ -336,6 +337,10 @@ def close(self):
336 337
         if self.settings_dict['NAME'] != ":memory:":
337 338
             BaseDatabaseWrapper.close(self)
338 339
 
  340
+    def schema_editor(self):
  341
+        "Returns a new instance of this backend's SchemaEditor"
  342
+        return DatabaseSchemaEditor(self)
  343
+
339 344
 FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
340 345
 
341 346
 class SQLiteCursorWrapper(Database.Cursor):
6  django/db/backends/sqlite3/schema.py
... ...
@@ -0,0 +1,6 @@
  1
+from django.db.backends.schema import BaseDatabaseSchemaEditor
  2
+
  3
+
  4
+class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
  5
+
  6
+    sql_delete_table = "DROP TABLE %(table)s"
12  tests/modeltests/schema/tests.py
@@ -44,18 +44,18 @@ def tearDown(self):
44 44
             # Remove any M2M tables first
45 45
             for field in model._meta.local_many_to_many:
46 46
                 try:
47  
-                    cursor.execute("DROP TABLE %s CASCADE" % (
48  
-                        connection.ops.quote_name(field.rel.through._meta.db_table),
49  
-                    ))
  47
+                    cursor.execute(connection.schema_editor().sql_delete_table % {
  48
+                        "table": connection.ops.quote_name(field.rel.through._meta.db_table),
  49
+                    })
50 50
                 except DatabaseError:
51 51
                     connection.rollback()
52 52
                 else:
53 53
                     connection.commit()
54 54
             # Then remove the main tables
55 55
             try:
56  
-                cursor.execute("DROP TABLE %s CASCADE" % (
57  
-                    connection.ops.quote_name(model._meta.db_table),
58  
-                ))
  56
+                cursor.execute(connection.schema_editor().sql_delete_table % {
  57
+                    "table": connection.ops.quote_name(model._meta.db_table),
  58
+                })
59 59
             except DatabaseError:
60 60
                 connection.rollback()
61 61
             else:

0 notes on commit d3d1e59

Please sign in to comment.
Something went wrong with that request. Please try again.