mirror of https://github.com/django/django.git
Removed code duplicated in SQLite3 and SpatiaLite GeoDjango DB backends.
Moved it to an auxiliary method in the SQLite3 backend cursor class. Did this to reduce the chances of us forgetting to port changes in DB connection setup process from the former to the latter one like it happened e.g. in r17205. Refs #17258. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8a986cb5bc
commit
5a4e63e62a
|
@ -38,22 +38,7 @@ class DatabaseWrapper(SQLiteDatabaseWrapper):
|
||||||
|
|
||||||
def _cursor(self):
|
def _cursor(self):
|
||||||
if self.connection is None:
|
if self.connection is None:
|
||||||
## The following is the same as in django.db.backends.sqlite3.base ##
|
self._sqlite_create_connection()
|
||||||
settings_dict = self.settings_dict
|
|
||||||
if not settings_dict['NAME']:
|
|
||||||
raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
|
|
||||||
kwargs = {
|
|
||||||
'database': settings_dict['NAME'],
|
|
||||||
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
|
|
||||||
}
|
|
||||||
kwargs.update(settings_dict['OPTIONS'])
|
|
||||||
self.connection = Database.connect(**kwargs)
|
|
||||||
# Register extract, date_trunc, and regexp functions.
|
|
||||||
self.connection.create_function("django_extract", 2, _sqlite_extract)
|
|
||||||
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
|
|
||||||
self.connection.create_function("regexp", 2, _sqlite_regexp)
|
|
||||||
self.connection.create_function("django_format_dtdelta", 5, _sqlite_format_dtdelta)
|
|
||||||
connection_created.send(sender=self.__class__, connection=self)
|
|
||||||
|
|
||||||
## From here on, customized for GeoDjango ##
|
## From here on, customized for GeoDjango ##
|
||||||
|
|
||||||
|
|
|
@ -230,39 +230,42 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
self.introspection = DatabaseIntrospection(self)
|
self.introspection = DatabaseIntrospection(self)
|
||||||
self.validation = BaseDatabaseValidation(self)
|
self.validation = BaseDatabaseValidation(self)
|
||||||
|
|
||||||
|
def _sqlite_create_connection(self):
|
||||||
|
settings_dict = self.settings_dict
|
||||||
|
if not settings_dict['NAME']:
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
|
||||||
|
kwargs = {
|
||||||
|
'database': settings_dict['NAME'],
|
||||||
|
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
|
||||||
|
}
|
||||||
|
kwargs.update(settings_dict['OPTIONS'])
|
||||||
|
# Always allow the underlying SQLite connection to be shareable
|
||||||
|
# between multiple threads. The safe-guarding will be handled at a
|
||||||
|
# higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
|
||||||
|
# property. This is necessary as the shareability is disabled by
|
||||||
|
# default in pysqlite and it cannot be changed once a connection is
|
||||||
|
# opened.
|
||||||
|
if 'check_same_thread' in kwargs and kwargs['check_same_thread']:
|
||||||
|
warnings.warn(
|
||||||
|
'The `check_same_thread` option was provided and set to '
|
||||||
|
'True. It will be overriden with False. Use the '
|
||||||
|
'`DatabaseWrapper.allow_thread_sharing` property instead '
|
||||||
|
'for controlling thread shareability.',
|
||||||
|
RuntimeWarning
|
||||||
|
)
|
||||||
|
kwargs.update({'check_same_thread': False})
|
||||||
|
self.connection = Database.connect(**kwargs)
|
||||||
|
# Register extract, date_trunc, and regexp functions.
|
||||||
|
self.connection.create_function("django_extract", 2, _sqlite_extract)
|
||||||
|
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
|
||||||
|
self.connection.create_function("regexp", 2, _sqlite_regexp)
|
||||||
|
self.connection.create_function("django_format_dtdelta", 5, _sqlite_format_dtdelta)
|
||||||
|
connection_created.send(sender=self.__class__, connection=self)
|
||||||
|
|
||||||
def _cursor(self):
|
def _cursor(self):
|
||||||
if self.connection is None:
|
if self.connection is None:
|
||||||
settings_dict = self.settings_dict
|
self._sqlite_create_connection()
|
||||||
if not settings_dict['NAME']:
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
|
|
||||||
kwargs = {
|
|
||||||
'database': settings_dict['NAME'],
|
|
||||||
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
|
|
||||||
}
|
|
||||||
kwargs.update(settings_dict['OPTIONS'])
|
|
||||||
# Always allow the underlying SQLite connection to be shareable
|
|
||||||
# between multiple threads. The safe-guarding will be handled at a
|
|
||||||
# higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
|
|
||||||
# property. This is necessary as the shareability is disabled by
|
|
||||||
# default in pysqlite and it cannot be changed once a connection is
|
|
||||||
# opened.
|
|
||||||
if 'check_same_thread' in kwargs and kwargs['check_same_thread']:
|
|
||||||
warnings.warn(
|
|
||||||
'The `check_same_thread` option was provided and set to '
|
|
||||||
'True. It will be overriden with False. Use the '
|
|
||||||
'`DatabaseWrapper.allow_thread_sharing` property instead '
|
|
||||||
'for controlling thread shareability.',
|
|
||||||
RuntimeWarning
|
|
||||||
)
|
|
||||||
kwargs.update({'check_same_thread': False})
|
|
||||||
self.connection = Database.connect(**kwargs)
|
|
||||||
# Register extract, date_trunc, and regexp functions.
|
|
||||||
self.connection.create_function("django_extract", 2, _sqlite_extract)
|
|
||||||
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
|
|
||||||
self.connection.create_function("regexp", 2, _sqlite_regexp)
|
|
||||||
self.connection.create_function("django_format_dtdelta", 5, _sqlite_format_dtdelta)
|
|
||||||
connection_created.send(sender=self.__class__, connection=self)
|
|
||||||
return self.connection.cursor(factory=SQLiteCursorWrapper)
|
return self.connection.cursor(factory=SQLiteCursorWrapper)
|
||||||
|
|
||||||
def check_constraints(self, table_names=None):
|
def check_constraints(self, table_names=None):
|
||||||
|
|
Loading…
Reference in New Issue