How do you get output parameters from a stored procedure in Python?

前端 未结 9 1807
既然无缘
既然无缘 2020-12-20 13:40

I\'ve googled around a bit, but maybe I didn\'t put the correct magik incantation into the search box.

Does anyone know how to get output parameters from a stored p

9条回答
  •  臣服心动
    2020-12-20 14:21

    I was able to get an output value from a SQL stored procedure using Python. I could not find good help getting the output values in Python. I figured out the Python syntax myself, so I suspect this is worth posting here:

    import sys, string, os, shutil, arcgisscripting
    from win32com.client import Dispatch
    from adoconstants import *
    
    #skip ahead to the important stuff
    
    conn = Dispatch('ADODB.Connection')
    conn.ConnectionString = "Provider=sqloledb.1; Data Source=NT38; Integrated Security = SSPI;database=UtilityTicket"
    conn.Open()
    
    #Target Procedure Example: EXEC TicketNumExists @ticketNum = 8386998, @exists output
    
    Cmd = Dispatch('ADODB.Command')
    Cmd.ActiveConnection = conn
    
    Cmd.CommandType = adCmdStoredProc
    Cmd.CommandText = "TicketNumExists"
    
    Param1 = Cmd.CreateParameter('@ticketNum', adInteger, adParamInput)
    Param1.Value = str(TicketNumber)
    Param2 = Cmd.CreateParameter('@exists', adInteger, adParamOutput)
    
    Cmd.Parameters.Append(Param1)
    Cmd.Parameters.Append(Param2)
    
    Cmd.Execute()
    
    Answer = Cmd.Parameters('@exists').Value
    

提交回复
热议问题