mysql纯python客户端
来源:互联网 发布:获取svn数据java接口 编辑:程序博客网 时间:2024/06/06 10:45
下载纯python的mysql API, https://pypi.python.org/pypi/mysql-connector-python/2.0.4 mysql-connector-python2.0.4
http://dev.mysql.com/doc/connector-python/en/index.html
from __future__ import print_functionfrom decimal import Decimalfrom datetime import datetime, date, timedeltaimport mysql.connector# Connect with the MySQL Servercnx = mysql.connector.connect(user='scott', database='employees')# Get two buffered cursorscurA = cnx.cursor(buffered=True)curB = cnx.cursor(buffered=True)# Query to get employees who joined in a period defined by two datesquery = ( "SELECT s.emp_no, salary, from_date, to_date FROM employees AS e " "LEFT JOIN salaries AS s USING (emp_no) " "WHERE to_date = DATE('9999-01-01')" "AND e.hire_date BETWEEN DATE(%s) AND DATE(%s)")# UPDATE and INSERT statements for the old and new salaryupdate_old_salary = ( "UPDATE salaries SET to_date = %s " "WHERE emp_no = %s AND from_date = %s")insert_new_salary = ( "INSERT INTO salaries (emp_no, from_date, to_date, salary) " "VALUES (%s, %s, %s, %s)")# Select the employees getting a raisecurA.execute(query, (date(2000, 1, 1), date(2000, 12, 31)))# Iterate through the result of curAfor (emp_no, salary, from_date, to_date) in curA: # Update the old and insert the new salary new_salary = int(round(salary * Decimal('1.15'))) curB.execute(update_old_salary, (tomorrow, emp_no, from_date)) curB.execute(insert_new_salary, (emp_no, tomorrow, date(9999, 1, 1,), new_salary)) # Commit the changes cnx.commit()cnx.close()
阅读全文
0 0
- mysql纯python客户端
- python模拟mysql多客户端并发操作
- python 2048 纯console
- Windows/Linux下安装python的mysql客户端接口
- python 字符串转换,mysql插入带引号字符串,获取html纯文字
- Mysql 客户端
- Silverlight4控件纯客户端注册验证
- 【MySQL】MySQL客户端实现
- Mysql纯命令行添加用户
- mysql 表名 纯数字
- mysql生成纯文本文件备份
- JDBC纯驱动连接MySQL
- Python的SIP客户端
- python 文件传输客户端程序
- Python FTP 客户端
- python memcached 客户端比较
- python客户端访问WebService
- Python:DNS客户端实现
- vue.js豆瓣书网站
- html5桌面提醒功能(浏览器支持的不好)
- Ubuntu国内可用sources.list
- Java 动态代理
- jfinal框架文件下载功能代码
- mysql纯python客户端
- MFC显示JPG、JIF图片
- SSM组合+ springmvc+mybatis
- Failed to initiate service connection to simulator Error returned in reply: Connection invalid
- 05 与编程相关的计算机硬件
- vue-devtools 必备开发工具
- opencv之fitline直线拟合
- springMVC学习java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet
- shell下使用expect遍历服务器