[pypy-svn] r69366 - in pypy/trunk/pypy/module/oracle: . test

afa at codespeak.net afa at codespeak.net
Wed Nov 18 11:58:36 CET 2009


Author: afa
Date: Wed Nov 18 11:58:35 2009
New Revision: 69366

Modified:
   pypy/trunk/pypy/module/oracle/interp_variable.py
   pypy/trunk/pypy/module/oracle/test/test_stringvar.py
Log:
implement getvalue() for array variables


Modified: pypy/trunk/pypy/module/oracle/interp_variable.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_variable.py	(original)
+++ pypy/trunk/pypy/module/oracle/interp_variable.py	Wed Nov 18 11:58:35 2009
@@ -295,9 +295,14 @@
         # XXX outConverter
         return value
 
+    def getArrayValue(self, space, numElements):
+        return space.newlist(
+            [self.getSingleValue(space, i)
+             for i in range(numElements)])
+
     def getValue(self, space, pos=0):
         if self.isArray:
-            return self.getArrayValue(self, self.actualElements)
+            return self.getArrayValue(space, self.actualElementsPtr[0])
         return self.getSingleValue(space, pos)
     getValue.unwrap_spec = ['self', ObjSpace, int]
 

Modified: pypy/trunk/pypy/module/oracle/test/test_stringvar.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/test/test_stringvar.py	(original)
+++ pypy/trunk/pypy/module/oracle/test/test_stringvar.py	Wed Nov 18 11:58:35 2009
@@ -14,7 +14,7 @@
 
     def test_array(self):
         cur = self.cnx.cursor()
-        array = map(str, range(20))
+        array = ["n%d" % d for d in range(20)]
         tablelen = cur.var(oracle.NUMBER)
         output = cur.var(oracle.STRING)
         statement = """
@@ -33,7 +33,7 @@
 
     def test_array_bysize(self):
         cur = self.cnx.cursor()
-        array = map(str, range(20))
+        array = ["n%d" % d for d in range(20)]
         tablelen = cur.var(oracle.NUMBER)
         output = cur.var(oracle.STRING)
         cur.setinputsizes(array=[oracle.STRING, 10])
@@ -53,7 +53,7 @@
 
     def test_arrayvar(self):
         cur = self.cnx.cursor()
-        array = map(str, range(20))
+        array = ["n%d" % d for d in range(20)]
         tablelen = cur.var(oracle.NUMBER)
         output = cur.var(oracle.STRING)
         arrayvar = cur.arrayvar(oracle.STRING, array)
@@ -71,3 +71,24 @@
                     output=output)
         assert tablelen.getvalue() == 20
         assert output.getvalue() == ','.join(array)
+
+    def test_arrayvar_out(self):
+        cur = self.cnx.cursor()
+        array = ["n%d" % d for d in range(20)]
+        tablelen = cur.var(oracle.NUMBER)
+        arrayvar = cur.arrayvar(oracle.STRING, 25)
+        statement = """
+                declare
+                  array dbms_utility.uncl_array;
+                begin
+                  dbms_utility.comma_to_table(
+                      :input, :tablelen, array);
+                  :array := array;
+                end;"""
+        cur.execute(statement,
+                    input=','.join(array),
+                    tablelen=tablelen,
+                    array=arrayvar)
+        assert tablelen.getvalue() == 20
+        # dbms_utility.comma_to_table returns a 'NULL-terminated' table
+        assert arrayvar.getvalue() == array + [None]



More information about the Pypy-commit mailing list