Author: ikelly
Date: 2010-04-28 12:15:11 -0500 (Wed, 28 Apr 2010)
New Revision: 13043

Modified:
   django/branches/releases/1.1.X/
   django/branches/releases/1.1.X/django/db/backends/oracle/base.py
   django/branches/releases/1.1.X/tests/regressiontests/backends/tests.py
Log:
[1.1.X] Fixed a bug preventing cursor variables from being passed as bind 
parameters in the oracle backend. Backport of r13042 from trunk.


Property changes on: django/branches/releases/1.1.X
___________________________________________________________________
Name: svnmerge-integrated
   - 
/django/trunk:1-11500,11523,11527-11528,11531-11552,11554,11577,11579-11581,11588-11589,11591-11592,11596-11599,11601-11617,11619-11626,11628-11635,11637-11638,11643-11644,11648-11653,11656,11670,11678,11681,11684,11686,11688,11691,11693,11695,11697,11699,11701,11703,11705,11707,11714,11719,11729,11732,11734,11739-11740,11748,11751,11753,11756,11760,11800,11802,11808,11815,11817,11820,11822,11824,11826,11828,11831,11833,11835,11837,11839,11841,11844,11857,11864,11874,11876,11878,11885,11898,11901,11905,11909,11912,11914,11917,11921,11938,11953,11961,11977,11979,11984,11986,11988,11990,11992,11994,11996,11998,12001,12004,12006,12011,12022,12024,12044-12045,12048,12054-12056,12059,12064,12066,12068,12070,12079,12086,12088,12104,12118,12132,12137-12138,12140-12141,12144,12150-12152,12171,12220-12221,12229,12249,12253,12276,12282,12284,12293,12313,12317-12324,12333,12341,12343,12346,12353,12362,12379,12384,12398,12405,12408-12411,12419-12420,12423,12425-12426,12429,12434,12436,12439-12442,12447-12448,12457,12461-12464,12467,12471,12473,12475,12484,12489-12490,12492,12497-12498,12502,12505,12513,12515-12516,12518,12523,12525-12526,12528,12533,12535,12537,12539,12541,12548,12551,12553,12556,12558-12560,12562,12567,12569-12570,12573,12576,12579,12581,12584,12598-12599,12602,12605,12614,12616,12621-12622,12627,12630-12631,12635,12637,12639,12641,12644,12646,12648,12650,12652,12654,12657,12659,12661,12663,12665,12667,12669,12671,12673,12676,12679,12681,12683,12686,12688,12694,12696,12698,12700,12704-12705,12710-12712,12719,12721,12723,12725-12726,12728,12733-12734,12737,12739,12741,12743,12757,12759,12764,12766,12768,12771,12774,12778,12780,12782,12788,12795,12798,12800,12806,12808,12811,12813,12817,12819,12821,12823,12825,12828,12830,12832,12834,12836,12838,12840,12842,12846,12848,12850,12852,12854,12858,12860,12862,12868,12878,12880,12883,12885,12891,12893,12896,12898,12901,12905,12908,12910,12912,12916,12918,12920,12924,12926,12928,12930,12932,12934,12941,12948,12950,12956,12971-12972,12974,12982,12984,12989,13008
   + 
/django/trunk:1-11500,11523,11527-11528,11531-11552,11554,11577,11579-11581,11588-11589,11591-11592,11596-11599,11601-11617,11619-11626,11628-11635,11637-11638,11643-11644,11648-11653,11656,11670,11678,11681,11684,11686,11688,11691,11693,11695,11697,11699,11701,11703,11705,11707,11714,11719,11729,11732,11734,11739-11740,11748,11751,11753,11756,11760,11800,11802,11808,11815,11817,11820,11822,11824,11826,11828,11831,11833,11835,11837,11839,11841,11844,11857,11864,11874,11876,11878,11885,11898,11901,11905,11909,11912,11914,11917,11921,11938,11953,11961,11977,11979,11984,11986,11988,11990,11992,11994,11996,11998,12001,12004,12006,12011,12022,12024,12044-12045,12048,12054-12056,12059,12064,12066,12068,12070,12079,12086,12088,12104,12118,12132,12137-12138,12140-12141,12144,12150-12152,12171,12220-12221,12229,12249,12253,12276,12282,12284,12293,12313,12317-12324,12333,12341,12343,12346,12353,12362,12379,12384,12398,12405,12408-12411,12419-12420,12423,12425-12426,12429,12434,12436,12439-12442,12447-12448,12457,12461-12464,12467,12471,12473,12475,12484,12489-12490,12492,12497-12498,12502,12505,12513,12515-12516,12518,12523,12525-12526,12528,12533,12535,12537,12539,12541,12548,12551,12553,12556,12558-12560,12562,12567,12569-12570,12573,12576,12579,12581,12584,12598-12599,12602,12605,12614,12616,12621-12622,12627,12630-12631,12635,12637,12639,12641,12644,12646,12648,12650,12652,12654,12657,12659,12661,12663,12665,12667,12669,12671,12673,12676,12679,12681,12683,12686,12688,12694,12696,12698,12700,12704-12705,12710-12712,12719,12721,12723,12725-12726,12728,12733-12734,12737,12739,12741,12743,12757,12759,12764,12766,12768,12771,12774,12778,12780,12782,12788,12795,12798,12800,12806,12808,12811,12813,12817,12819,12821,12823,12825,12828,12830,12832,12834,12836,12838,12840,12842,12846,12848,12850,12852,12854,12858,12860,12862,12868,12878,12880,12883,12885,12891,12893,12896,12898,12901,12905,12908,12910,12912,12916,12918,12920,12924,12926,12928,12930,12932,12934,12941,12948,12950,12956,12971-12972,12974,12982,12984,12989,13008,13042

Modified: django/branches/releases/1.1.X/django/db/backends/oracle/base.py
===================================================================
--- django/branches/releases/1.1.X/django/db/backends/oracle/base.py    
2010-04-28 17:08:06 UTC (rev 13042)
+++ django/branches/releases/1.1.X/django/db/backends/oracle/base.py    
2010-04-28 17:15:11 UTC (rev 13043)
@@ -376,6 +376,30 @@
             self.input_size = None
 
 
+class VariableWrapper(object):
+    """
+    An adapter class for cursor variables that prevents the wrapped object
+    from being converted into a string when used to instanciate an OracleParam.
+    This can be used generally for any other object that should be passed into
+    Cursor.execute as-is.
+    """
+
+    def __init__(self, var):
+        self.var = var
+
+    def bind_parameter(self, cursor):
+        return self.var
+
+    def __getattr__(self, key):
+        return getattr(self.var, key)
+
+    def __setattr__(self, key, value):
+        if key == 'var':
+            self.__dict__[key] = value
+        else:
+            setattr(self.var, key, value)
+
+
 class InsertIdVar(object):
     """
     A late-binding cursor variable that can be passed to Cursor.execute
@@ -384,7 +408,7 @@
     """
 
     def bind_parameter(self, cursor):
-        param = cursor.var(Database.NUMBER)
+        param = cursor.cursor.var(Database.NUMBER)
         cursor._insert_id_var = param
         return param
 
@@ -439,7 +463,7 @@
             return self.cursor.execute(query, self._param_generator(params))
         except DatabaseError, e:
             # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
-            if e.args[0].code == 1400 and not isinstance(e, IntegrityError):
+            if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not 
isinstance(e, IntegrityError):
                 e = IntegrityError(e.args[0])
             raise e
 
@@ -463,7 +487,7 @@
                                 [self._param_generator(p) for p in formatted])
         except DatabaseError, e:
             # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
-            if e.args[0].code == 1400 and not isinstance(e, IntegrityError):
+            if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not 
isinstance(e, IntegrityError):
                 e = IntegrityError(e.args[0])
             raise e
 
@@ -523,6 +547,12 @@
             casted.append(value)
         return tuple(casted)
 
+    def var(self, *args):
+        return VariableWrapper(self.cursor.var(*args))
+
+    def arrayvar(self, *args):
+        return VariableWrapper(self.cursor.arrayvar(*args))
+
     def __getattr__(self, attr):
         if attr in self.__dict__:
             return self.__dict__[attr]

Modified: django/branches/releases/1.1.X/tests/regressiontests/backends/tests.py
===================================================================
--- django/branches/releases/1.1.X/tests/regressiontests/backends/tests.py      
2010-04-28 17:08:06 UTC (rev 13042)
+++ django/branches/releases/1.1.X/tests/regressiontests/backends/tests.py      
2010-04-28 17:15:11 UTC (rev 13043)
@@ -22,6 +22,16 @@
         else:
             return True
             
+    def test_cursor_var(self):
+        # If the backend is Oracle, test that we can pass cursor variables
+        # as query parameters.
+        if settings.DATABASE_ENGINE == 'oracle':
+            cursor = connection.cursor()
+            var = cursor.var(backend.Database.STRING)
+            cursor.execute("BEGIN %s := 'X'; END; ", [var])
+            self.assertEqual(var.getvalue(), 'X')
+
+
 class LongString(unittest.TestCase):
 
     def test_long_string(self):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to