Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented Oracle version as a cached property.

  • Loading branch information...
commit 9a3988ca5ad5808fad0d5bd8e25fe560d0d48ec0 1 parent 4b9fa49
@aaugustin aaugustin authored
Showing with 17 additions and 13 deletions.
  1. +17 −13 django/db/backends/oracle/base.py
View
30 django/db/backends/oracle/base.py
@@ -52,6 +52,7 @@ def _setup_environment(environ):
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 @@ def init_connection_state(self):
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:
- self.ops.regex_lookup = self.ops.regex_lookup_9
- else:
- self.ops.regex_lookup = self.ops.regex_lookup_10
- except ValueError:
- pass
+ # 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 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
+
try:
self.connection.stmtcachesize = 20
except:
@@ -624,6 +621,13 @@ def _commit(self):
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):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.