Implemented Oracle version as a cached property.

This commit is contained in:
Aymeric Augustin 2013-02-19 10:50:22 +01:00
parent 4b9fa49bc0
commit 9a3988ca5a
1 changed files with 17 additions and 13 deletions

View File

@ -52,6 +52,7 @@ from django.db.backends.oracle.client import DatabaseClient
from django.db.backends.oracle.creation import DatabaseCreation
from django.db.backends.oracle.introspection import DatabaseIntrospection
from django.utils.encoding import force_bytes, force_text
from django.utils.functional import cached_property
from django.utils import six
from django.utils import timezone
@ -502,7 +503,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.oracle_version = None
self.features = DatabaseFeatures(self)
use_returning_into = self.settings_dict["OPTIONS"].get('use_returning_into', True)
self.features.can_return_id_from_insert = use_returning_into
@ -579,18 +579,15 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.operators = self._standard_operators
cursor.close()
try:
self.oracle_version = int(self.connection.version.split('.')[0])
# There's no way for the DatabaseOperations class to know the
# currently active Oracle version, so we do some setups here.
# TODO: Multi-db support will need a better solution (a way to
# communicate the current version).
if self.oracle_version <= 9:
if self.oracle_version is not None and self.oracle_version <= 9:
self.ops.regex_lookup = self.ops.regex_lookup_9
else:
self.ops.regex_lookup = self.ops.regex_lookup_10
except ValueError:
pass
try:
self.connection.stmtcachesize = 20
except:
@ -624,6 +621,13 @@ class DatabaseWrapper(BaseDatabaseWrapper):
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
@cached_property
def oracle_version(self):
try:
return int(self.connection.version.split('.')[0])
except ValueError:
return None
class OracleParam(object):
"""