2014-04-04 94 views
1

從我的python代碼中,我試圖執行存儲過程。存儲過程返回整數值。MS SQL SERVER 2005 + SQLAlchemy +存儲過程+輸出參數

CREATE PROCEDURE MY_PROC 
    @empID char(10), 
    @oldEmpList XML, 
    @newEmpList XML, 
    @Status INT OUTPUT 
AS 
    -- sp body 
    SET @Status = 1 
RETURN 
GO 

蟒蛇

t = text('EXEC MY_PROC :empID, :oldEmpList, :newEmpList, :Status', 
     bindparams=[bindparam('empID', type_=String, value='1234'), 
        bindparam('oldEmpList', type_=TEXT, value='<emp><id>1</id><id>2</id>'), 
        bindparam('newEmpList', type_=TEXT, value='<emp><id>e01</id><id>e02</id>'), 
        bindparam('Status', type_=Integer, value=0, isoutparam=True)]) 
result = CMS_DBSession.execute(t) 
print result.out_parameters 

其打印毫無作爲輸出參數。

如何訪問輸出放慢參數

回答

0

這裏有一個可行的解決方案:https://groups.google.com/forum/#!topic/sqlalchemy/dn-W0rrlwxk

這將使類似:

t = text('SET NOCOUNT ON; declare @Status int; EXEC MY_PROC :empID, :oldEmpList, :newEmpList, @Status; Select @Status; SET NOCOUNT OFF;', 
    bindparams=[bindparam('empID', type_=String, value='1234'), 
       bindparam('oldEmpList', type_=TEXT, value='<emp><id>1</id><id>2</id>'), 
       bindparam('newEmpList', type_=TEXT, value='<emp><id>e01</id><id>e02</id>')) 
result = CMS_DBSession.execute(t) 
# then get the select result