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的更多相关文章

  1. An Introduction to Stored Procedures in MySQL 5

    https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...

  2. Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python

    f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can fol ...

  3. Spring, Hibernate and Oracle Stored Procedures

    一篇英文博文,写的是利用hibernate处理存储过程中的游标等等: Motivation: While there are a few resources available online for ...

  4. Cursors in MySQL Stored Procedures

    https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...

  5. Good Practices to Write Stored Procedures in SQL Server

    Reference to: http://www.c-sharpcorner.com/UploadFile/skumaar_mca/good-practices-to-write-the-stored ...

  6. MySQL Error Handling in Stored Procedures 2

    Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...

  7. [转]How to: Execute Oracle Stored Procedures Returning RefCursors

    本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...

  8. Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one SQL statement

    Is there any way in which I can clean a database in SQl Server 2005 by dropping all the tables and d ...

  9. [MySQL] Stored Procedures 【转载】

    Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...

随机推荐

  1. 404 Not Found !

    MyEclipse中tomcat服务器运行好好的, 却总是报错, 代码没啥问题啊!! 之前都是运行好好的, 难道是我广告不小心改了哪里引起的?于是对比,回退代码,但是结果还是一样的!! 一个简简单单的 ...

  2. sql的OUTER APPLY

    今天写一个查询sql,其中涉及到一个银行卡绑定表(表名:BankBind),我要将这个表的开户行字段的值进行分割出省份.支行, 这个开户行字段存储的值如“广东省广东省分行江门市分行恩平市支行”.“招商 ...

  3. Linux 容器技术史话:从 chroot 到未来

    Linux 容器是一个在单一 Linux 主机上提供多个隔离的 Linux 环境的操作系统级虚拟技术.不像虚拟机(VM),容器并不需要运行专用的访客(guest)操作系统.容器们共享宿主机的(host ...

  4. WebApi系列~基于单请求封装多请求的设计~请求的安全性设计与实现

    回到目录 对于一个Http请求如何保证它的安全,这已经不是一个新的话题,对于请求的安全我们通常考虑的无非就是"请求的被篡改性"和"请求的被复制性",第一个问题我们很容易实现,可以通过参数+密钥的方式, ...

  5. fir.im Weekly - 94 个 iOS 开发资源推荐

    距离 2016 年还有 17 个日夜,而你和回家只隔了一张 12306 验证码的距离,祝大家抢票顺利.本期 fir.im Weekly 收集了一些优秀的 GitHub 源码.开发工具和动画特效,希望对 ...

  6. sql分组(orderBy、GroupBy)获取每组前一(几)条数据

    sql数据库实现分组并取每组的前1(几)条数据 测试数据准备工作: 根据某一个字段分组取最大(小)值所在行的数据: 创建表并且插入数据 ),Val )) , 'a1--a的第一个值') , 'b2b2 ...

  7. 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录

    ASP.NET提供了静态属性System.Web.HttpContext.Current,因此获取HttpContext对象就非常方便了.也正是因为这个原因,所以我们经常能见到直接访问System.W ...

  8. SQL Server排序函数row_number和rank的区别

    SQL Server排序函数row_number和rank的区别 直接看测试结果 declare @table table(name varchar(100),amount int, memo var ...

  9. 将Windows系统编译的.NET Core程序发布到Ubuntu系统

    在可移植方面.NET Core应用程序分为两种,Portable application(便捷,需要目标机器安装.NET Core Runtime)和Self-contained applicatio ...

  10. WCF传输1-你是否使用过压缩或Json序列化?

    1.当遇到需要传输大量数据时,怎么样传输数据? 2.压缩数据有哪几种常见的方式? 问题1解答:通过压缩来传输数据 问题2解答: (1)WCF自带的压缩方式 (2)自定义WCF binding进行压缩 ...