Ticket #9628: 9628-r9781.diff

File 9628-r9781.diff, 1.5 KB (added by ramiro, 6 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

  • django/db/backends/sqlite3/base.py

    diff -r 08fa6b05f9ea django/db/backends/sqlite3/base.py
    a b  
    33
    44Python 2.3 and 2.4 require pysqlite2 (http://pysqlite.org/).
    55
    6 Python 2.5 and later use the sqlite3 module in the standard library.
     6Python 2.5 and later use the sqlite3 module in the standard library,
     7unless a newer version of pysqlite2 is installed.
    78"""
    89
    910from django.db.backends import *
     
    1112from django.db.backends.sqlite3.creation import DatabaseCreation
    1213from django.db.backends.sqlite3.introspection import DatabaseIntrospection
    1314from django.utils.safestring import SafeString
     15import sys
    1416
    15 try:
     17Database = None
     18for pkg in ['sqlite3','pysqlite2']:
    1619    try:
    17         from sqlite3 import dbapi2 as Database
    18     except ImportError, e1:
    19         from pysqlite2 import dbapi2 as Database
    20 except ImportError, exc:
    21     import sys
     20        mod = __import__(pkg + '.dbapi2')
     21        if not Database or mod.dbapi2.version_info > Database.version_info:
     22            Database = sys.modules[pkg + '.dbapi2']
     23    except ImportError, exc:
     24        pass
     25if not Database:
    2226    from django.core.exceptions import ImproperlyConfigured
    23     if sys.version_info < (2, 5, 0):
    24         module = 'pysqlite2'
    25     else:
    26         module = 'sqlite3'
    27         exc = e1
    28     raise ImproperlyConfigured, "Error loading %s module: %s" % (module, exc)
     27    raise ImproperlyConfigured, "Error loading %s module: %s" % (pkg, exc)
    2928
    3029try:
    3130    import decimal
Back to Top