Commits

adamv  committed b462d47

Sproc return values now being set on cur.return_value

  • Participants
  • Parent commits cca69e4

Comments (0)

Files changed (2)

File source/sqlserver_ado/dbapi.py

 def format_parameters(parameters, show_value=False):
     """Format a collection of ADO Command Parameters.
     
-    Used by error reporting in _executeHelper.
+    Used by error reporting in _run_command.
     """
     directions = {
         0: 'Unknown',
         """
         self.cmd = None
         self.messages = []
+        self.return_value = None
 
         self._new_command(True, procname)
         # OUTPUT parameters are inspected as INOUT
-        self._executeHelper(procname, True, parameters)
+        self._run_command(procname, True, parameters)
 
         newvalues = list()
         return_value = None
 
         for p in self.cmd.Parameters:
-            py = p.Value # Need to translate this to Python
+            #py = p.Value # Need to translate this to Python
+            
+            # _convert_to_python(cell, ado_type)
+            py = _convert_to_python(p.Value, p.Type)
+            
             if p.Direction == adParamReturnValue:
-                return_value = py
+                self.return_value = py
             else:
                 newvalues.append(py)
 
         else:
             self.cmd.CommandType = adCmdText
 
-    def _executeHelper(self, operation, isStoredProcedureCall, parameters=None):
+    def _run_command(self, operation, isStoredProcedureCall, parameters=None):
         if self.connection is None:
             self._raiseCursorError(Error, None)
             return
         self.cmd = None
         
         self.messages = []
-        self._executeHelper(operation, False, parameters)
+        self._run_command(operation, False, parameters)
 
     def executemany(self, operation, seq_of_parameters):
         """Execute the given command against all parameter sequences or mappings given in seq_of_parameters."""

File tests/api/run.py

             )
     
     # This should create a sproc with a return value.
-    def _retval_setup(self):
-        self._try_run(
+    def _retval_setup(self, cur):
+        self._try_run2(cur,
             """IF OBJECT_ID(N'[dbo].[add_one]', N'P') IS NOT NULL DROP PROCEDURE [dbo].[add_one]""",
             """
 CREATE PROCEDURE add_one (@input int)
             )
 
     def test_retval(self):
-        self._retval_setup()
         con = self._connect()
         try:
             cur = con.cursor()
+            self._retval_setup(cur)
             values = cur.callproc('add_one',(1,))
-            print values
-            self.assertEqual(values[0], 2, 'retval produced invalid reults: %s' % (values[0],))
+            self.assertEqual(values[0], 1, 'input parameter should be left unchanged: %s' % (values[0],))
+            
+            self.assertEqual(cur.description, None,"No resultset was expected.")
+            self.assertEqual(cur.return_value, 2, "Invalid return value: %s" % (cur.return_value,))
+
         finally:
             con.close()
 
-
     # This should create a sproc with an output parameter.
     def _outparam_setup(self, cur):
         self._try_run2(cur,