From d52577b62b3138674807ac74251fab7faed48331 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 28 Apr 2017 16:27:21 +0200 Subject: [PATCH] [1.11.x] Fixed #28138 -- Used output type handler instead of numbersAsStrings on Oracle cursor. Thanks Tim Graham for the review. Backport of 946775227c56d7a4c6a43343b2e88af837f99f49 from master --- django/db/backends/oracle/base.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index be604455cf..65b5e10909 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -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()}