Skip to content

Commit

Permalink
[1.11.x] Fixed #28138 -- Used output type handler instead of numbersA…
Browse files Browse the repository at this point in the history
…sStrings on Oracle cursor.

Thanks Tim Graham for the review.

Backport of 9467752 from master
  • Loading branch information
felixxm committed Apr 28, 2017
1 parent e93135b commit d52577b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions django/db/backends/oracle/base.py
Expand Up @@ -400,11 +400,24 @@ class FormatStylePlaceholderCursor(object):

def __init__(self, connection):
self.cursor = connection.cursor()
# Necessary to retrieve decimal values without rounding error.
self.cursor.numbersAsStrings = True
self.cursor.outputtypehandler = self._output_type_handler
# Default arraysize of 1 is highly sub-optimal.
self.cursor.arraysize = 100

@staticmethod
def _output_type_handler(cursor, name, defaultType, length, precision, scale):
"""
Called for each db column fetched from cursors. Return numbers as
strings so that decimal values don't have rounding error.
"""
if defaultType == Database.NUMBER:
return cursor.var(
Database.STRING,
size=255,
arraysize=cursor.arraysize,
outconverter=str,
)

def _format_params(self, params):
try:
return {k: OracleParam(v, self, True) for k, v in params.items()}
Expand Down

0 comments on commit d52577b

Please sign in to comment.