星空网 > 软件开发 > 数据库

Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

https://geert.vanderkelen.org/2014/results-after-procedure-call/

Problem

Using MySQL Connector/Python, you are calling a stored procedure which is also selecting data and you would like to fetch the rows of the result.

Solution

For this example we create a stored procedure which is executing SHOW SLAVE STATUS.

```python cnx = mysql.connector.connect(user=’scott’, password=’tiger’, database=’mining’) cur = cnx.cursor() cur.execute(“DROP PROCEDURE IF EXISTS slave_status”) proc = “CREATE PROCEDURE slave_status () BEGIN SHOW SLAVE STATUS; END” cur.execute() cur.call(“slave_status”)

for result_cursor in cur.stored_results(): for row in result_cursor: print(row[0]) ```

The result from the above would be:

shell $ python foo.py Waiting for master to send event

Discussion

The stored_results() method of cursor object is retiring an iterator object which will go over the results proceeded after calling the stored procedure. Each result is actually a MySQLCursorBuffered object.

You could also use the with_rows cursor property to check if the cursor actually could return rows or not (for example, for SELECT statements). An example is provided in the documentation.




原标题:Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

易周资讯丨TikTok宣布与美国两家公司初步达成三方意向:https://www.ikjzd.com/articles/130342
“巴西周”电子商务收入增长25%——趁此时机打造爆款独立站:https://www.ikjzd.com/articles/130343
亚马逊推出Luxury Stores,进军奢侈品市场:https://www.ikjzd.com/articles/130344
无单放货警告:遇到这种情况小心钱货两空:https://www.ikjzd.com/articles/130345
亚马逊大洗牌!内部渠道被连根拔起:https://www.ikjzd.com/articles/130346
Joom运营小知识-准确申报产品重量:https://www.ikjzd.com/articles/130347
优秀的亚马逊运营每天必做的二十件事:https://www.xlkjsw.com/news/92277.html
对赌嗜血!深圳大卖卖身之后……:https://www.kjdsnews.com/a/1842198.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流