繁体   English   中英

python cursor.callproc() 函数不调用过程

[英]python cursor.callproc() function not calling procedure

新(ish)到 SQL,刚刚发现存储过程。

重构一个整体的 Python 3.7 脚本。

这是我的存储过程:

CREATE PROCEDURE domSel(IN xip VARCHAR(16))
BEGIN
SELECT domain FROM pytest.nodes2 WHERE ip = xip
END;

它根据 IP 选择域。 Python 中的原始代码片段如下所示:

    for i,x,y in ip_ll:
        cursorA.execute("SELECT domain FROM pytest.nodes2 WHERE ip = '" + str(i) + "'")
        hosts_low.append(cursorA.fetchone())
        ips_low_latency.append(i)
        lat_low.append(x)

以下行应该是替换:

# The #s are of course the IP address.
result_arg = cursorA.callproc('domSel', args=('###.##.###.###,))
print(result_arg[1])

但它给了我错误:

Traceback (most recent call last):
  File "./2queryMagic.py", line 45, in <module>
    print(result_arg[1])
IndexError: tuple index out of range

我试图打印 arg[0],但这当然是参数名称。 我尝试在 for 循环中迭代结果,这也不起作用...... Python 似乎没有调用该过程。 希望这是足够的信息,把我的头从办公桌上敲下来。

根据 rdas 的评论,程序需要一个 out 变量,并且必须使用 @var_name 引用

call domSel('###.##.###.###', @dom);

(worked, but ofc relayed the actual domain)
+-------------------+
| domain            |
+-------------------+
| -domain.com      -|
+-------------------+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM