Code

Ticket #9628: 9628-r9791-optionA.diff

File 9628-r9791-optionA.diff, 1.5 KB (added by ramiro, 5 years ago)

Patch implementing strategy A as per django-dev discussion

Line 
1diff -r fa344eb7dd92 django/db/backends/sqlite3/base.py
2--- a/django/db/backends/sqlite3/base.py        Sat Jan 24 12:16:25 2009 -0200
3+++ b/django/db/backends/sqlite3/base.py        Tue Jan 27 15:09:58 2009 -0200
4@@ -11,20 +11,20 @@
5 from django.db.backends.sqlite3.creation import DatabaseCreation
6 from django.db.backends.sqlite3.introspection import DatabaseIntrospection
7 from django.utils.safestring import SafeString
8+from django.conf import settings
9+import sys
10 
11+if sys.version_info < (2, 5, 0):
12+    module = 'pysqlite2'
13+else:
14+    module = 'sqlite3'
15+if hasattr(settings, 'DATABASE_OPTIONS'):
16+    module = settings.DATABASE_OPTIONS.get('module', module)
17 try:
18-    try:
19-        from sqlite3 import dbapi2 as Database
20-    except ImportError, e1:
21-        from pysqlite2 import dbapi2 as Database
22+    __import__(module + '.dbapi2')
23+    Database = sys.modules[module + '.dbapi2']
24 except ImportError, exc:
25-    import sys
26     from django.core.exceptions import ImproperlyConfigured
27-    if sys.version_info < (2, 5, 0):
28-        module = 'pysqlite2'
29-    else:
30-        module = 'sqlite3'
31-        exc = e1
32     raise ImproperlyConfigured, "Error loading %s module: %s" % (module, exc)
33 
34 try:
35@@ -163,6 +163,7 @@
36                 'database': settings.DATABASE_NAME,
37                 'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
38             }
39+            self.options.pop('module', None)
40             kwargs.update(self.options)
41             self.connection = Database.connect(**kwargs)
42             # Register extract, date_trunc, and regexp functions.