Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to _outputtypehandler fix: Use module-level function instead of m…

…ethod

(because using a method ends up leaking cursors)
while at it: rename to_unicode ==> _to_unicode to conform with file's standard
  • Loading branch information...
commit d10eaf28c864816e9bb8b0d1467e90b79291792a 1 parent 49b1e59
@shaib authored
Showing with 40 additions and 40 deletions.
  1. +40 −40 django/db/backends/oracle/base.py
View
80 django/db/backends/oracle/base.py
@@ -671,7 +671,7 @@ class FormatStylePlaceholderCursor(object):
def __init__(self, connection):
self.cursor = connection.cursor()
# Necessary to retrieve decimal values without rounding error.
- self.cursor.outputtypehandler = self._outputtypehandler
+ self.cursor.outputtypehandler = _outputtypehandler
# Default arraysize of 1 is highly sub-optimal.
self.cursor.arraysize = 100
@@ -768,47 +768,47 @@ def __getattr__(self, attr):
def __iter__(self):
return iter(self.cursor)
- def _outputtypehandler(self, cursor, name, default_type, length, precision, scale):
- if default_type is Database.NUMBER:
- if scale == -127:
- if precision == 0:
- # NUMBER column: decimal-precision floating point
- # This will normally be an integer from a sequence,
- # but it could be a decimal value.
- return cursor.var(str, 100, cursor.arraysize,
- outconverter=_decimal_or_int)
- else:
- # FLOAT column: binary-precision floating point.
- # This comes from FloatField columns.
- return cursor.var(default_type, arraysize=cursor.arraysize,
- outconverter=float)
- elif precision > 0:
- # NUMBER(p,s) column: decimal-precision fixed point.
- # This comes from IntField and DecimalField columns.
- if scale == 0:
- return cursor.var(default_type, arraysize=cursor.arraysize,
- outconverter=int)
- else:
- return cursor.var(str, 100, cursor.arraysize,
- outconverter=decimal.Decimal)
- else:
- # No type information. This normally comes from a
- # mathematical expression in the SELECT list. Guess int
- # or Decimal based on whether it has a decimal point.
+def _outputtypehandler(cursor, name, default_type, length, precision, scale):
+ if default_type is Database.NUMBER:
+ if scale == -127:
+ if precision == 0:
+ # NUMBER column: decimal-precision floating point
+ # This will normally be an integer from a sequence,
+ # but it could be a decimal value.
return cursor.var(str, 100, cursor.arraysize,
outconverter=_decimal_or_int)
- # datetimes are returned as TIMESTAMP, except the results
- # of "dates" queries, which are returned as DATETIME.
- elif default_type in (Database.TIMESTAMP, Database.DATETIME) and settings.USE_TZ:
- return cursor.var(default_type, arraysize=cursor.arraysize,
- outconverter=_add_tzinfo)
- elif default_type in (Database.STRING, Database.FIXED_CHAR,
- Database.LONG_STRING):
- return cursor.var(default_type, length, cursor.arraysize,
- outconverter=to_unicode)
-
-
-def to_unicode(s):
+ else:
+ # FLOAT column: binary-precision floating point.
+ # This comes from FloatField columns.
+ return cursor.var(default_type, arraysize=cursor.arraysize,
+ outconverter=float)
+ elif precision > 0:
+ # NUMBER(p,s) column: decimal-precision fixed point.
+ # This comes from IntField and DecimalField columns.
+ if scale == 0:
+ return cursor.var(default_type, arraysize=cursor.arraysize,
+ outconverter=int)
+ else:
+ return cursor.var(str, 100, cursor.arraysize,
+ outconverter=decimal.Decimal)
+ else:
+ # No type information. This normally comes from a
+ # mathematical expression in the SELECT list. Guess int
+ # or Decimal based on whether it has a decimal point.
+ return cursor.var(str, 100, cursor.arraysize,
+ outconverter=_decimal_or_int)
+ # datetimes are returned as TIMESTAMP, except the results
+ # of "dates" queries, which are returned as DATETIME.
+ elif default_type in (Database.TIMESTAMP, Database.DATETIME) and settings.USE_TZ:
+ return cursor.var(default_type, arraysize=cursor.arraysize,
+ outconverter=_add_tzinfo)
+ elif default_type in (Database.STRING, Database.FIXED_CHAR,
+ Database.LONG_STRING):
+ return cursor.var(default_type, length, cursor.arraysize,
+ outconverter=_to_unicode)
+
+
+def _to_unicode(s):
"""
Convert strings to Unicode objects (and return all other data types
unchanged).
Please sign in to comment.
Something went wrong with that request. Please try again.