summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-02-19 10:50:22 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-19 10:50:22 +0100
commit9a3988ca5ad5808fad0d5bd8e25fe560d0d48ec0 (patch)
tree422953052813350596fa06117dc39c83bb9756a7
parent4b9fa49bc0cf5d2e01b6b98dec6d23fed774f254 (diff)
Implemented Oracle version as a cached property.
-rw-r--r--django/db/backends/oracle/base.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index e329ef3191..3fdf67402a 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -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:
- 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 @@ 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):
"""