Commits

adamv committed cca69e4

* Added output parameter test.

Comments (0)

Files changed (3)

source/sqlserver_ado/dbapi.py

         standard .fetch*() methods.
         """
         self.cmd = None
-        
         self.messages = []
+
         self._new_command(True, procname)
-        
+        # OUTPUT parameters are inspected as INOUT
         self._executeHelper(procname, True, parameters)
 
-        values = self._get_return_values()
-        return values
-
-
-    def _get_return_values(self):
-        return_values = list()
+        newvalues = list()
+        return_value = None
 
         for p in self.cmd.Parameters:
+            py = p.Value # Need to translate this to Python
             if p.Direction == adParamReturnValue:
-                return_values = 123
-                
-        return return_values
+                return_value = py
+            else:
+                newvalues.append(py)
+
+        return newvalues
+
 
     def _description_from_recordset(self, recordset):
     	# Abort if closed or no recordset.

tests/api/dbapi20.py

     def _callproc_setup(self):
         pass
 
-    lower_func = 'to_lower'
     def test_callproc(self):
         con = self._connect()
         try:
             cur = con.cursor()
-            if self.lower_func and hasattr(cur,'callproc'):
-                cur.callproc(self.lower_func,('FOO',))
-                r = cur.fetchall()
-                print "callproc: ", r
-                self.assertEqual(len(r),1,'callproc produced no result set')
-                self.assertEqual(len(r[0]),1,
-                    'callproc produced invalid result set'
-                    )
-                self.assertEqual(r[0][0],'foo',
-                    'callproc produced invalid results'
-                    )
+            # Execute and get new parameters
+            values = cur.callproc('to_lower', ('FOO',))
+            self.assertEqual(len(values),1, 'callproc didnt return the input values')
+            self.assertEqual(values[0],'FOO', 'input-only values shouldnt change')
+            
+            r = cur.fetchall()
+            self.assertEqual(len(r),1,'callproc produced no result set')
+            self.assertEqual(len(r[0]),1, 'callproc produced invalid result set')
+            self.assertEqual(r[0][0],'foo', 'callproc produced invalid results')
         finally:
             con.close()
 
         con = self._connect()
         try:
             cur = con.cursor()
-            if hasattr(cur,'callproc'):
-                values = cur.callproc('add_one',(1,))
-                print values
-                self.assertEqual(values[0], 2, 'retval produced invalid reults: %s' % (values[0],))
+            values = cur.callproc('add_one',(1,))
+            print values
+            self.assertEqual(values[0], 2, 'retval produced invalid reults: %s' % (values[0],))
         finally:
             con.close()
+
+
+    # This should create a sproc with an output parameter.
+    def _outparam_setup(self, cur):
+        self._try_run2(cur,
+            """IF OBJECT_ID(N'[dbo].[add_one_out]', N'P') IS NOT NULL DROP PROCEDURE [dbo].[add_one_out]""",
+            """
+CREATE PROCEDURE add_one_out (@input int, @output int OUTPUT)
+AS
+BEGIN
+    SET @output = @input+1
+END
+""",
+            )
+
+    def test_outparam(self):
+        con = self._connect()
+        try:
+            cur = con.cursor()
+            self._outparam_setup(cur)
+            values = cur.callproc('add_one_out',(1,None))
+            self.assertEqual(len(values), 2, 'expected 2 parameters')
+            self.assertEqual(values[0], 1, 'input parameter should be unchanged')
+            self.assertEqual(values[1], 2, 'output parameter should get new values')
+        finally:
+            con.close()            
     
     # Don't need exceptions mirrored on connections.
     def test_ExceptionsAsConnectionAttributes(self): 
             )
 
     def help_nextset_tearDown(self,cur):
-#        self._try_run2(cur,
-#            """IF OBJECT_ID(N'[dbo].[more_than_one]', N'P') IS NOT NULL DROP PROCEDURE [dbo].[more_than_one]""",
-#            )
         pass
    
 suite = unittest.makeSuite(test_dbapi, 'test')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.