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 implying that output parameters cannot be
handled due to their indeterminate memory requirements, however.
The adodbapi module does have a stored procedure call in its unit tests,
and manages to pass that test, but when I call my own stored procedure
(which retrieves columns into the output parameters rather than using
SET to establish their values) I get back whatever value I supplied as
the output parameter rather than what the stored procedure is returning.
So, can anyone help me to fulfill what must be a very common database
requirement?
regards
Steve
-- http://www.holdenweb.com http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119 5 8150
Steve Holden wrote: 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 implying that output parameters cannot be handled due to their indeterminate memory requirements, however.
The adodbapi module does have a stored procedure call in its unit tests, and manages to pass that test, but when I call my own stored procedure (which retrieves columns into the output parameters rather than using SET to establish their values) I get back whatever value I supplied as the output parameter rather than what the stored procedure is returning.
So, can anyone help me to fulfill what must be a very common database requirement?
regards Steve
Hmmm, following up, added another test to adodbapi to retrieve a value
from a table into an output parameter it works, so this puts the
suspicion on to the stored procedure. Since this was written by the
client I'll take a look at it later (when I'm back in the office) and
see what the problem might be.
happily-talking-away-to-myself-ly y'rs - steve
-- http://www.holdenweb.com http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Steve Holden wrote: Hmmm, following up, added another test to adodbapi to retrieve a value from a table into an output parameter it works, so this puts the suspicion on to the stored procedure. Since this was written by the client I'll take a look at it later (when I'm back in the office) and see what the problem might be.
happily-talking-away-to-myself-ly y'rs - steve
However, the stored procedure below appears to consistently return zero
for the link_id when called with:
columnist_id, url, title, description, link_id = \
curs.callproc("sp_InsertArticle",
(columnist_id, url, title, description, 0))
so maybe there really *is* something wrong. Or, hopefully, I'm just
making a simple mistake in the calls? Whatever value is used as the
fifth (output) parameter seems to get returned, despite the apparent
change in the stored procedure.
Create PROCEDURE dbo.sp_InsertArticle
(
@columnist_id int,
@url varchar(255),
@title varchar(99),
@description text,
@link_id int OUTPUT
)
AS
BEGIN
INSERT INTO link (columnist_id,url,title,description)
VALUES (@columnist_id,@url,@title,@description)
SELECT @link_id = @@IDENTITY
END
GO
not-quite-so-happi-ly y'rs - steve
-- http://www.holdenweb.com http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
In article <HHWmd.10924$nj.1324@lakeread01>,
Steve Holden <st***@holdenweb.com> wrote: 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 implying that output parameters cannot be handled due to their indeterminate memory requirements, however.
Keep in mind that it's been several years since I used Python with SQL
Server and about all I remember is that we used stored procedures
heavily with no problems. I have no clue whether we tried using stored
procedures with output parameters, but I wonder why you can't just use a
SELECT to call the stored procedure and return the values. Or at least
right another stored proc that does something roughly similar.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/
WiFi is the SCSI of the 21st Century -- there are fundamental technical
reasons for sacrificing a goat. (with no apologies to John Woods)
In article <cn**********@panix1.panix.com>, Aahz <aa**@pythoncraft.com> wrote: Keep in mind that it's been several years since I used Python with SQL Server and about all I remember is that we used stored procedures heavily with no problems. I have no clue whether we tried using stored procedures with output parameters, but I wonder why you can't just use a SELECT to call the stored procedure and return the values. Or at least right another stored proc that does something roughly similar.
s/right/write/, but you knew that.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/
WiFi is the SCSI of the 21st Century -- there are fundamental technical
reasons for sacrificing a goat. (with no apologies to John Woods)
Steve Holden <st***@holdenweb.com> wrote in message news:<oSYmd.10931$nj.6308@lakeread01>... Steve Holden wrote:
Hmmm, following up, added another test to adodbapi to retrieve a value from a table into an output parameter it works, so this puts the suspicion on to the stored procedure. Since this was written by the client I'll take a look at it later (when I'm back in the office) and see what the problem might be.
happily-talking-away-to-myself-ly y'rs - steve
However, the stored procedure below appears to consistently return zero for the link_id when called with:
columnist_id, url, title, description, link_id = \ curs.callproc("sp_InsertArticle", (columnist_id, url, title, description, 0))
so maybe there really *is* something wrong. Or, hopefully, I'm just making a simple mistake in the calls? Whatever value is used as the fifth (output) parameter seems to get returned, despite the apparent change in the stored procedure.
Create PROCEDURE dbo.sp_InsertArticle ( @columnist_id int, @url varchar(255), @title varchar(99), @description text, @link_id int OUTPUT ) AS BEGIN INSERT INTO link (columnist_id,url,title,description) VALUES (@columnist_id,@url,@title,@description)
SELECT @link_id = @@IDENTITY END
GO
I had a similar problem doing this once before that I think was
related to the connection string. Changing to use the SQLOLEDB
provider solved it. I've just tested the below script here and got
the expected results:
Stored procedure:
CREATE PROCEDURE TestSP
@param INTEGER OUTPUT
AS
BEGIN
select @param = 10
END
Python test:
import adodbapi
server='localhost'
dbname='brian'
user='sa'
password=''
db=adodbapi.connect('Provider=SQLOLEDB.1;Data Source=%s;Initial
Catalog=%s;User ID=%s;Password=%s;'%(server, dbname,user,password))
cur = db.cursor()
print cur.callproc('TestSP',(999,))
[10]
--
Brian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ivan divandelen |
last post by:
Hi, How can i pass a parameter SQL stored Procedure from ASP pages
|
by: Michael |
last post by:
This one's really got me. I have a VB.NET (version 1.1.4322) project
that provides an easy way to execute stored procedures on a generic
level. When I run the code on computer A (running SQL...
|
by: Dino L. |
last post by:
How can I run stored procedure (MSSQL) ?
|
by: Mike L |
last post by:
I'm able to connect to my stored procedure in my local database but not able
to connect to my stored procedure in the remote database.
I use several different UserID and Password that all should...
|
by: Mr Not So Know It All |
last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL
Server stored procedure with an input parameter and output parameter
CREATE PROCEDURE .
@in_rc varchar(8)
@out_eList...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: jed |
last post by:
I have created this example in sqlexpress
ALTER PROCEDURE .
@annualtax FLOAT
AS
BEGIN
SELECT begin1,end1,deductedamount,pecentageextra
FROM tax
|
by: Light |
last post by:
Hi all,
I posted this question in the sqlserver.newusers group but I am not getting
any response there so I am going to try it on the fine folks here:).
I inherited some legacy ASP codes in my...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |