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 ...
随机推荐
- Java程序员的日常——SpringMVC+Mybatis开发流程、推荐系统
今天大部分时间都在写业务代码,然后算是从无到有的配置了下spring与mybatis的集成. SpringMVC+Mybatis Web开发流程 配置数据源 在applicationContext.x ...
- [Spring框架]Spring JDBCTmplate基础入门总结.
前言:前面有讲过 Spring IOC以及AOP的基本使用方法, 这里就再来讲下Spring JDBCTemplate的使用方法. 一, 概述这里先说一下Spring 整合的一些模板: 从上图中可以看 ...
- salesforce 零基础学习(二十七)VF页面等待(loading)效果制作
进行查询的情况下,显示友好的等待效果可以让用户更好的了解目前的状态以及减少用户消极的等待,例如下图所示. VF提供了<apex:actionStatus>标签,,此标签用于显示一个AJAX ...
- Python - 动手写个ORM
Python - 动手写个ORM 任务: 模拟简单的ORM - Object Relational Mapping 为model添加create方法 代码很简单,直接上 字段类型类 class Fie ...
- Script Component 引用package variable
ScriptComponet 的变量分为两种类型,ReadOnly和ReadWrite,使用C#引用这两种类型的变量,有一点不同. 1,创建两个变量 2,将变量传递给script component ...
- Redis基础介绍及安装示例
1.基本概念 Redis是由Salvatore Sanfilippo(意大利)开发的一个开源的高性能键值存储数据库,于2009年发布第一个版本并与同一年开源,官方站点:http://www.redis ...
- 【原创】Newlife.XCode的常见功能使用(一)查询与数据初始化
本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html Newlife XCode组件相关文章目录:http://www ...
- 批处理:Windows主机通过FTP下载远程Linux主机上文件
问题:在Windows上怎么写个批处理把多个文件FTP依次下载到本地某个目录. 批处理脚本示例: @echo off title Download db files. Don't close it!! ...
- Shine.js – 帮助你实现各种好看的阴影效果
Shine.js 是一个用于实现漂亮阴影的 JavaScript 库.您可以设置动态光的位置,可定制的阴影.不依赖于第三方库,兼容 AMD.能在支持 textShadow 或 boxShadow 的浏 ...
- 第1/24周 SQL Server 如何执行一个查询
大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Server如何执行一个查询来建立基础.这个部分非常重要, ...