如何调用字典作为存储过程的参数

How to call a dictionary as a parameter for stored procedure

我正在尝试使用参数中的字典来调用存储过程来更新 table,该 table 使用 Dict 中的值作为外键。

字典数据(ID为外键)例如: 服务器1,ID1 服务器 5,ID2

ID 是我正在尝试更新的 table 上的外键,在调用存储过程时需要作为参数。看来,当我将字典作为参数传递时,它正在拉取 server1 而不是 ID1 并导致键错误。

with open('DBstatus.csv') as dbcsvfile:
    dbstatus = csv.DictReader(dbcsvfile)
    for row in dbstatus:

#Create parameters for stored procedure
        guardpointparams = (row['FS Agent Registration Status'], row['FS Agent Version'], row['Guard Path'], serverdict[row['Host Name']], policydict[row['Policy Name']], 0)
        #call stored procedure
        updateguardpointstable = cursor.callproc('update_guardpoints', guardpointparams)

#i created the dictionary from a different script while updating the 
"servers" table where the DB is creating the returnvalue (ID) from the 
stored procedure see sample below:

serverdict[row['Host Name']] = returnvalue[3]

回溯:guardpointparams = (row['FS Agent Registration Status'], row['FS Agent Version'], row['Guard Path'], serverdict[row['Host Name']], policydict [行['Policy Name']], 0) 键错误:'server1'

row['Host Name'] 似乎是 server1。字典 serverdict 没有名为 server1

的键

您的 serverdictpolicydict 似乎未定义。至少你没有在你的例子中提供定义。此外,追溯告诉您其中之一没有您要查找的密钥。