summaryrefslogtreecommitdiff
path: root/django/db/backends/oracle/utils.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-01-12 15:20:40 -0500
committerTim Graham <timograham@gmail.com>2015-01-14 14:16:20 -0500
commit28308078f397d1de36fd0da417ac7da2544ba12d (patch)
tree80207ff582b2350d058c1c7c49072b761391c04f /django/db/backends/oracle/utils.py
parent737d24923ac69bb8b89af1bb2f3f4c4c744349e8 (diff)
downloaddjango-28308078f397d1de36fd0da417ac7da2544ba12d.tar.gz
Fixed #22603 -- Reorganized classes in django.db.backends.
Diffstat (limited to 'django/db/backends/oracle/utils.py')
-rw-r--r--django/db/backends/oracle/utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/django/db/backends/oracle/utils.py b/django/db/backends/oracle/utils.py
new file mode 100644
index 0000000000..c63bf39c1c
--- /dev/null
+++ b/django/db/backends/oracle/utils.py
@@ -0,0 +1,42 @@
+import datetime
+
+from django.utils.encoding import force_bytes, force_text
+
+from .base import Database
+
+# Check whether cx_Oracle was compiled with the WITH_UNICODE option if cx_Oracle is pre-5.1. This will
+# also be True for cx_Oracle 5.1 and in Python 3.0. See #19606
+if int(Database.version.split('.', 1)[0]) >= 5 and \
+ (int(Database.version.split('.', 2)[1]) >= 1 or
+ not hasattr(Database, 'UNICODE')):
+ convert_unicode = force_text
+else:
+ convert_unicode = force_bytes
+
+
+class InsertIdVar(object):
+ """
+ A late-binding cursor variable that can be passed to Cursor.execute
+ as a parameter, in order to receive the id of the row created by an
+ insert statement.
+ """
+
+ def bind_parameter(self, cursor):
+ param = cursor.cursor.var(Database.NUMBER)
+ cursor._insert_id_var = param
+ return param
+
+
+class Oracle_datetime(datetime.datetime):
+ """
+ A datetime object, with an additional class attribute
+ to tell cx_Oracle to save the microseconds too.
+ """
+ input_size = Database.TIMESTAMP
+
+ @classmethod
+ def from_datetime(cls, dt):
+ return Oracle_datetime(
+ dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, dt.second, dt.microsecond,
+ )