473,656 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
testVariableRet urningStoredPro cedure 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_DeleteMeOnly ForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@the Input+@theOther Input

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

Then, the python comes out as :
>>cursor = db.conn.cursor( )
cursor.callpr oc('sp_DeleteMe OnlyForTesting' , ('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 5111
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
testVariableRet urningStoredPro cedure 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_DeleteMeOnly ForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@the Input+@theOther Input

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

Then, the python comes out as :
>>>cursor = db.conn.cursor( )
cursor.callp roc('sp_DeleteM eOnlyForTesting ', ('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=@the Input+@theOther Input

you would write

SELECT * From dbo.testtable
SELECT @theInput+@theO therInput

and then fetch the data using:

cursor.callproc (...)
test_table_resu lt_set = cursor.fetchall ()
cursor.nextset( )
(output_variabl es,) = 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.D atabase.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
_______________ _______________ _______________ _______________ ____________

:::: Try mxODBC.Zope.DA for Windows,Linux,S olaris,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*******@yaho o.comwrote in message
news:b1******** *************** ***********@p35 g2000prm.google groups.com...
Hello,

I need some help getting output values from my stored procedures when
using adodbapi. There's an example
testVariableRet urningStoredPro cedure 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_DeleteMeOnly ForTesting
@theInput varchar(50),
@theOtherInput varchar(50),
@theOutput varchar(100) OUTPUT
AS
SET @theOutput=@the Input+@theOther Input

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

Then, the python comes out as :
>>>cursor = db.conn.cursor( )
cursor.callp roc('sp_DeleteM eOnlyForTesting ', ('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="Drive r={SQL Server};Server= .\\SqlExpress;T rusted_Connecti on=yes;"
sp_name="sp_Del eteMeOnlyForTes ting"

c=win32com.clie nt.gencache.Ens ureDispatch('ad odb.connection' ,0)
c.Open(conn_str )

cmd=win32com.cl ient.Dispatch(' ADODB.Command')
cmd.ActiveConne ction=c
cmd.CommandType = win32com.client .constants.adCm dStoredProc
cmd.CommandText = sp_name

cmd.Parameters( '@theInput').Va lue = 'bork'
cmd.Parameters( '@theOtherInput ').Value = 'borkbork'
rs, rc = cmd.Execute()
rs.NextRecordse t()
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
8278
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, and people are saying bad things about Python as a result :-( mx.ODBC, which I regard as a highly-capable module, does not support the callproc() API, and suggests use of the ODBC call format. It has caveats in (some of) the documentation...
1
2446
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 provider). m = u'BrReg' rs = u'' msg = u'' x = self.cur.callproc('__DocFetchBaseCategories', (0, 0, m, rs, msg))
0
1987
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 furnish values to python. This does not work MY PYTHON CODE IS: import adodbapi connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=sa; Password=tester; Initial Catalog=someDB;Data Source=someSource" db = adodbapi.connect(connStrSQLServer)
0
1948
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 procedure and then I select from that dynamic table to furnish values to python. This does not work MY PYTHON CODE IS: import adodbapi connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=sa; Password=tester; Initial Catalog=someDB;Data...
2
3014
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 varchar(20),
1
2083
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 rows to be updated or inserted into other tables. Filtration is based on certain actual values on forms (form with several subforms). My question is following: How to pass parameters to those stored procedures that are triggered by a button?...
11
11089
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 well. However I want to also return the number of records in the recordset and I can not manage to get any output parameter working. Even if I assign SELECT @mycount=100 (or SET @mycount=100) in the SP the only value set in mycount is always NULL. ...
3
2137
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 stored procedures with input parameters by which they filter rows to be updated or inserted into other tables. Filtration is based on certain actual values on forms (form with several subforms). My question is following: How to pass parameters to...
1
1799
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 having an issue getting the output parameters' values after execution. Here is a snipit of code that calls one for simplicity's sake: I think I am close, i was under the impression I could use the datareader to get at it, but is is always returning ...
0
8382
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8498
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.