Ticket #9628: 9628-r9791-optionA.diff

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

Patch implementing strategy A as per django-dev discussion

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

    diff -r fa344eb7dd92 django/db/backends/sqlite3/base.py
    a b  
    1111from django.db.backends.sqlite3.creation import DatabaseCreation
    1212from django.db.backends.sqlite3.introspection import DatabaseIntrospection
    1313from django.utils.safestring import SafeString
     14from django.conf import settings
     15import sys
    1416
     17if sys.version_info < (2, 5, 0):
     18    module = 'pysqlite2'
     19else:
     20    module = 'sqlite3'
     21if hasattr(settings, 'DATABASE_OPTIONS'):
     22    module = settings.DATABASE_OPTIONS.get('module', module)
    1523try:
    16     try:
    17         from sqlite3 import dbapi2 as Database
    18     except ImportError, e1:
    19         from pysqlite2 import dbapi2 as Database
     24    __import__(module + '.dbapi2')
     25    Database = sys.modules[module + '.dbapi2']
    2026except ImportError, exc:
    21     import sys
    2227    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
    2828    raise ImproperlyConfigured, "Error loading %s module: %s" % (module, exc)
    2929
    3030try:
     
    163163                'database': settings.DATABASE_NAME,
    164164                'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
    165165            }
     166            self.options.pop('module', None)
    166167            kwargs.update(self.options)
    167168            self.connection = Database.connect(**kwargs)
    168169            # Register extract, date_trunc, and regexp functions.
Back to Top