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

afa at codespeak.net afa at codespeak.net
Sun Nov 15 23:04:49 CET 2009


Author: afa
Date: Sun Nov 15 23:04:49 2009
New Revision: 69308

Modified:
   pypy/trunk/pypy/module/oracle/interp_cursor.py
   pypy/trunk/pypy/module/oracle/interp_variable.py
   pypy/trunk/pypy/module/oracle/roci.py
   pypy/trunk/pypy/module/oracle/test/test_cursor.py
Log:
implement Cursor.callproc


Modified: pypy/trunk/pypy/module/oracle/interp_cursor.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_cursor.py	(original)
+++ pypy/trunk/pypy/module/oracle/interp_cursor.py	Sun Nov 15 23:04:49 2009
@@ -126,9 +126,27 @@
         else:
             args_w = space.unpackiterable(w_parameters)
 
-        return self._call(space, name, retvar, args_w)
+        self._call(space, name, retvar, args_w)
+
+        # determine the results
+        return retvar.getValue(space, 0)
     callfunc.unwrap_spec = ['self', ObjSpace, str, W_Root, W_Root]
 
+    def callproc(self, space, name, w_parameters=None):
+        if space.is_w(w_parameters, space.w_None):
+            args_w = None
+        else:
+            args_w = space.unpackiterable(w_parameters)
+
+        self._call(space, name, None, args_w)
+
+        # create the return value
+        print "AFA", self.bindList
+        ret_w = [v.getValue(space, 0) for v in self.bindList]
+        return space.newlist(ret_w)
+
+    callproc.unwrap_spec = ['self', ObjSpace, str, W_Root]
+
     def _call(self, space, name, retvar, args_w):
         # determine the number of arguments passed
         if args_w:
@@ -160,9 +178,6 @@
 
         self._execute(space, space.wrap(stmt), vars_w)
 
-        if retvar:
-            return retvar.getValue(space, 0)
-
     def _checkOpen(self, space):
         if not self.isOpen:
             raise OperationError(
@@ -709,6 +724,8 @@
                            unwrap_spec=W_Cursor.bindnames.unwrap_spec),
     callfunc = interp2app(W_Cursor.callfunc,
                           unwrap_spec=W_Cursor.callfunc.unwrap_spec),
+    callproc = interp2app(W_Cursor.callproc,
+                          unwrap_spec=W_Cursor.callproc.unwrap_spec),
     var = interp2app(W_Cursor.var,
                      unwrap_spec=W_Cursor.var.unwrap_spec),
 

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	Sun Nov 15 23:04:49 2009
@@ -441,18 +441,23 @@
             rffi.cast(roci.Ptr(roci.OCINumber), self.data),
             pos)
         if isinstance(self, VT_Integer):
-            status = roci.OCINumberToInt(
-                self.environment.errorHandle,
-                dataptr,
-                rffi.sizeof(rffi.LONG),
-                roci.OCI_NUMBER_SIGNED,
-                intergerValuePtr)
-            self.environment.checkForError(
-                status, "NumberVar_GetValue(): as integer")
-            if isinstance(self, VT_Boolean):
-                return space.wrap(integerValuePtr[0])
-            else:
-                return space.w_bool(integerValuePtr[0])
+            integerValuePtr = lltype.malloc(roci.Ptr(lltype.Signed).TO, 1,
+                                            flavor='raw')
+            try:
+                status = roci.OCINumberToInt(
+                    self.environment.errorHandle,
+                    dataptr,
+                    rffi.sizeof(rffi.LONG),
+                    roci.OCI_NUMBER_SIGNED,
+                    rffi.cast(roci.dvoidp, integerValuePtr))
+                self.environment.checkForError(
+                    status, "NumberVar_GetValue(): as integer")
+                if isinstance(self, VT_Boolean):
+                    return space.newbool(integerValuePtr[0])
+                else:
+                    return space.wrap(integerValuePtr[0])
+            finally:
+                lltype.free(integerValuePtr, flavor='raw')
         elif isinstance(self, (VT_NumberAsString, VT_LongInteger)):
             XXX = NumberAsString, LongInteger
         else:

Modified: pypy/trunk/pypy/module/oracle/roci.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/roci.py	(original)
+++ pypy/trunk/pypy/module/oracle/roci.py	Sun Nov 15 23:04:49 2009
@@ -189,12 +189,13 @@
 
 # Bind, Define, and Describe Functions
 
-OCIBindByPos = external(
-    'OCIBindByPos',
+OCIBindByName = external(
+    'OCIBindByName',
     [OCIStmt,      # stmtp
      Ptr(OCIBind), # bindpp
      OCIError,     # errhp
-     ub4,          # position
+     oratext,      # placeholder
+     sb4,          # placeh_len
      dvoidp,       # valuep
      sb4,          # value_sz
      ub2,          # dty
@@ -206,13 +207,12 @@
      ub4],         # mode
     sword)
 
-OCIBindByName = external(
-    'OCIBindByName',
+OCIBindByPos = external(
+    'OCIBindByPos',
     [OCIStmt,      # stmtp
      Ptr(OCIBind), # bindpp
      OCIError,     # errhp
-     oratext,      # placeholder
-     sb4,          # placeh_len
+     ub4,          # position
      dvoidp,       # valuep
      sb4,          # value_sz
      ub2,          # dty
@@ -339,10 +339,19 @@
      Ptr(OCINumber)],  # number
     sword)
 
+OCINumberToInt = external(
+    'OCINumberToInt',
+    [OCIError,         # err
+     Ptr(OCINumber),   # number
+     uword,            # rsl_length
+     uword,            # rsl_flag
+     dvoidp],          # rsl
+    sword)
+
 OCINumberToReal = external(
     'OCINumberToReal',
     [OCIError,         # err
-     Ptr(OCINumber),   # number      
+     Ptr(OCINumber),   # number
      uword,            # rsl_length
      dvoidp],          # rsl
     sword)

Modified: pypy/trunk/pypy/module/oracle/test/test_cursor.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/test/test_cursor.py	(original)
+++ pypy/trunk/pypy/module/oracle/test/test_cursor.py	Sun Nov 15 23:04:49 2009
@@ -66,7 +66,7 @@
                     "begin return 42; end;")
         assert cur.callfunc("pypy_temp_function",
                             oracle.NUMBER) == 42
-        
+
     def test_callFunc1(self):
         cur = self.cnx.cursor()
         try:
@@ -80,4 +80,18 @@
                             oracle.NUMBER, ("Hi", 5))
         assert res == 7
 
-
+    def test_callProc(self):
+        cur = self.cnx.cursor()
+        var = cur.var(oracle.NUMBER)
+        try:
+            cur.execute("drop procedure pypy_temp_procedure")
+        except oracle.DatabaseError:
+            pass
+        cur.execute("create procedure pypy_temp_procedure "
+                    "(x varchar2, y in out number, z out number) as "
+                    "begin "
+                    "  y := 10;"
+                    "  z := 2;"
+                    "end;")
+        results = cur.callproc("pypy_temp_procedure", ("hi", 5, var))
+        assert results == ["hi", 10, 2.0]



More information about the Pypy-commit mailing list