473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

adodbapi and output parameters in stored procedures

Hello,

I need some help getting output values from my stored procedures when
using adodbapi. There's an example
testVariableReturningStoredProcedure in adodbapitest.py, and that
works for my system. But my stored procedure also inserts and
accesses a table in the database. Here's what I have it boiled down
to:

So, when I have
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@theInput+@theOtherInput

Then, I can run in python:
>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'hellobye']
If I redefined the procedure as
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SELECT * From dbo.testtable
SET @theOutput=@theInput+@theOtherInput

Then, the python comes out as :
>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'']

My search on the web found a couple of posts with similar problems,
but no solutions. I am using SQLOLEDB.1 as Provider, connecting to
SQL Server 2005.

Any help appreciated. I just need one method of passing an output
parameter back to python.

Thanks,
Li
Nov 7 '08 #1
3 5081
On 2008-11-07 15:04, le*******@yahoo.com wrote:
Hello,

I need some help getting output values from my stored procedures when
using adodbapi. There's an example
testVariableReturningStoredProcedure in adodbapitest.py, and that
works for my system. But my stored procedure also inserts and
accesses a table in the database. Here's what I have it boiled down
to:

So, when I have
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@theInput+@theOtherInput

Then, I can run in python:
>>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'hellobye']
If I redefined the procedure as
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SELECT * From dbo.testtable
SET @theOutput=@theInput+@theOtherInput

Then, the python comes out as :
>>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'']

My search on the web found a couple of posts with similar problems,
but no solutions. I am using SQLOLEDB.1 as Provider, connecting to
SQL Server 2005.

Any help appreciated. I just need one method of passing an output
parameter back to python.
Note that if you can, you should try to avoid output parameters
in stored procedures.

It's much more efficient to use multiple result sets for these,
so instead of doing

SELECT * From dbo.testtable
SET @theOutput=@theInput+@theOtherInput

you would write

SELECT * From dbo.testtable
SELECT @theInput+@theOtherInput

and then fetch the data using:

cursor.callproc(...)
test_table_result_set = cursor.fetchall()
cursor.nextset()
(output_variables,) = cursor.fetchone()

I don't know whether the above works for adodbapi. It does for mxODBC
and most other DB-API compatible modules that support .nextset().

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Nov 07 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Nov 7 '08 #2
Thanks for that excellent pointer!

I was able to do just what you said with

But if my procedure has an insert statement in its midst, it doesn't
work. The cursor.fetchall() gets an exception.
Any ideas?

--Li
Nov 7 '08 #3

<le*******@yahoo.comwrote in message
news:b1**********************************@p35g2000 prm.googlegroups.com...
Hello,

I need some help getting output values from my stored procedures when
using adodbapi. There's an example
testVariableReturningStoredProcedure in adodbapitest.py, and that
works for my system. But my stored procedure also inserts and
accesses a table in the database. Here's what I have it boiled down
to:

So, when I have
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@theInput+@theOtherInput

Then, I can run in python:
>>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'hellobye']
If I redefined the procedure as
CREATE PROCEDURE sp_DeleteMeOnlyForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SELECT * From dbo.testtable
SET @theOutput=@theInput+@theOtherInput

Then, the python comes out as :
>>>cursor = db.conn.cursor()
cursor.callproc('sp_DeleteMeOnlyForTesting', ('hello', 'bye', ''))
[u'hello', u'bye', u'']

My search on the web found a couple of posts with similar problems,
but no solutions. I am using SQLOLEDB.1 as Provider, connecting to
SQL Server 2005.

Any help appreciated. I just need one method of passing an output
parameter back to python.

Thanks,
Li
--
http://mail.python.org/mailman/listinfo/python-list
Output parameters aren't actually retrieved until you've iterated
thru all record sets. The below works using ADO objects
directly, not sure how it would translate into adodbapi.

import win32com.client

conn_str="Driver={SQL Server};Server=.\\SqlExpress;Trusted_Connection=ye s;"
sp_name="sp_DeleteMeOnlyForTesting"

c=win32com.client.gencache.EnsureDispatch('adodb.c onnection',0)
c.Open(conn_str)

cmd=win32com.client.Dispatch('ADODB.Command')
cmd.ActiveConnection=c
cmd.CommandType = win32com.client.constants.adCmdStoredProc
cmd.CommandText = sp_name

cmd.Parameters('@theInput').Value = 'bork'
cmd.Parameters('@theOtherInput').Value = 'borkbork'
rs, rc = cmd.Execute()
rs.NextRecordset()
print (cmd.Parameters('@theOutput').Value)

If the NextRecordset line is commented out, the output parm
is None.

Roger


Nov 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve Holden | last post by:
Has anyone, with any driver whatsoever, managed to retrieve output parameters from a SQL Server stored procedure? I've just been rather embarrassed to find out it's not as easy as it might seem,...
1
by: Nikolai Kirsebom | last post by:
I'm trying to use the adodbapi module, but run into the following problem: After initalization (connection, cursor) I have the following call to a stored procedure (SQL Server, using SQLOLEDB.1...
0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, Could someone please help me with an issue I am having. I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a...
2
by: Lepa | last post by:
Hi I'm trying to make this to work and need help Here my SP and I'm building sql with output param. Alter PROCEDURE lpsadmin_getSBWReorderDollars ( @out decimal(10,2) output, @sType...
1
by: zlatko | last post by:
I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter...
11
by: Axel | last post by:
Hi, I am currently creating an ASP page that returns a recordset of search result based on multiple keywords. The where string is dynamically built on the server page and that part work quite...
3
by: Zlatko | last post by:
A question concerning Access Project with SQL Server: I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are...
1
by: Joe Van Meer | last post by:
Hi all, I have an app that currently runs through 3 seperate stored procedures each returning a count of records. What I would like to do is combine these calls into one call, however I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.