Code

Ticket #9628: 9628-r9781.diff

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

Another attempt at a patch for this that attampts to: Be more correct (no undefined exc, e1 vars), simpler, and appying what I learned from #8193

Line 
1diff -r 08fa6b05f9ea django/db/backends/sqlite3/base.py
2--- a/django/db/backends/sqlite3/base.py        Tue Jan 20 10:23:48 2009 -0200
3+++ b/django/db/backends/sqlite3/base.py        Thu Jan 22 21:19:43 2009 -0200
4@@ -3,7 +3,8 @@
5 
6 Python 2.3 and 2.4 require pysqlite2 (http://pysqlite.org/).
7 
8-Python 2.5 and later use the sqlite3 module in the standard library.
9+Python 2.5 and later use the sqlite3 module in the standard library,
10+unless a newer version of pysqlite2 is installed.
11 """
12 
13 from django.db.backends import *
14@@ -11,21 +12,19 @@
15 from django.db.backends.sqlite3.creation import DatabaseCreation
16 from django.db.backends.sqlite3.introspection import DatabaseIntrospection
17 from django.utils.safestring import SafeString
18+import sys
19 
20-try:
21+Database = None
22+for pkg in ['sqlite3','pysqlite2']:
23     try:
24-        from sqlite3 import dbapi2 as Database
25-    except ImportError, e1:
26-        from pysqlite2 import dbapi2 as Database
27-except ImportError, exc:
28-    import sys
29+        mod = __import__(pkg + '.dbapi2')
30+        if not Database or mod.dbapi2.version_info > Database.version_info:
31+            Database = sys.modules[pkg + '.dbapi2']
32+    except ImportError, exc:
33+        pass
34+if not Database:
35     from django.core.exceptions import ImproperlyConfigured
36-    if sys.version_info < (2, 5, 0):
37-        module = 'pysqlite2'
38-    else:
39-        module = 'sqlite3'
40-        exc = e1
41-    raise ImproperlyConfigured, "Error loading %s module: %s" % (module, exc)
42+    raise ImproperlyConfigured, "Error loading %s module: %s" % (pkg, exc)
43 
44 try:
45     import decimal