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的更多相关文章
- An Introduction to Stored Procedures in MySQL 5
https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...
- 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 ...
- Spring, Hibernate and Oracle Stored Procedures
一篇英文博文,写的是利用hibernate处理存储过程中的游标等等: Motivation: While there are a few resources available online for ...
- Cursors in MySQL Stored Procedures
https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...
- 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 ...
- MySQL Error Handling in Stored Procedures 2
Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...
- [转]How to: Execute Oracle Stored Procedures Returning RefCursors
本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...
- 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 ...
- [MySQL] Stored Procedures 【转载】
Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...
随机推荐
- C# 对包含文件或目录路径信息的 System.String 实例执行操作
在字符串操作中有一类比较特殊的操作,就是对包含文件或目录路径信息的 System.String 实例执行操作.比如根据一个表示路径的字符串获取其代表的文件名称.文件夹路径.文件扩展名等.在很多时候,我 ...
- Java框架介绍-13个不容错过的框架项目
本文转自互联网,个人收藏所用. 下面,我们将一同分享各有趣且颇为实用的Java库,大家请任取所需.不用客气~ 1.极致精简的Java Bootique是一项用于构建无容器可运行Java应用的极简技术. ...
- Javascript中构造函数与new命令2
典型的面向对象编程语言(比如C++和Java),存在"类"(class)这个概念.所谓"类"就是对象的模板,对象就是"类"的实例.但是,在J ...
- Java中static的理解
static表示"全局"或者"静态"的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static ...
- Atitit.gui api自动化调用技术原理与实践
Atitit.gui api自动化调用技术原理与实践 gui接口实现分类(h5,win gui, paint opengl,,swing,,.net winform,)1 Solu cate1 Sol ...
- Android TextView 常用技巧
Android ListView 常用技巧 Android TextView 常用技巧 TextView在Android中实现文字说明等功能,基本的使用都很简单,那么除了基本展示文字的使用,我们还能够 ...
- 简述移动端IM开发的那些坑:架构设计、通信协议和客户端
1.前言 有过移动端开发经历的开发者都深有体会:移动端IM的开发,与传统PC端IM有很大的不同,尤其无线网络的不可靠性.移动端硬件设备资源的有限性等问题,导致一个完整的移动端IM架构设计和实现都充满着 ...
- Java基础-接口看下图实现如下接口和类,并完成Adventure中的主方法
package hanqi; public interface CanSwim { void swim(); } package hanqi; public interface CanFly { pu ...
- leancloud 手机注册用户(调用API) 教程
// 从storybord 连线过来的button方法(注册按钮) - (IBAction)regist:(UIButton *)sender { AFHTTPSessionManager *mana ...
- 信息加密之消息摘要算法的MAC
MAC是消息摘要算法的第三种实现方式,另外两种方式分别为:MD2\4\5.SHA. MAC的jdk实现:1.默认密钥方式 private static void MAC_JDK(){ try { Ke ...