cursor

pymysql指南

匿名 (未验证) 提交于 2019-12-02 22:51:30
1 引言 mysql应该说是如今使用最为普遍的数据库了,没有之一,而Python作为最为流行的语言之一,自然少不了与mysql打交道,pymysql就是使用最多的工具库了。 2 创建库、表 我们先从创建数据库、数据表说起,有了库表,后面的增删改查才有根据。 2.1 创建数据库 pymysql的所有对数据库的操作都必选先与数据库服务建立连接,然后创建游标为基础执行具体的sql语句。创建数据库方法如下: # -*- coding: utf-8 -*- import pymysql conn = pymysql.connect( # 创建数据库连接 host='10.10.11.131', # 要连接的数据库所在主机ip user='chb', # 数据库登录用户名 password='123456!', # 登录用户密码 charset='utf8' # 编码,注意不能写成utf-8 ) cursor = con.cursor() cursor .execute("create database test_db character set utf8;") # 执行完之后别忘了关闭游标和数据库连接 cursor.close() conn.close() 上面代码执行完后,就创建了一个名为test_db的数据库: 2.2 创建数据表 # -*- coding: utf-8 -*-

pymysql的使用

匿名 (未验证) 提交于 2019-12-02 22:06:11
MySQL基于TCP协议之上开发,但是网络连接之后,传输的数据必须遵循MySQL的协议.封装好MySQL协议的包,就是驱动程序. 先建立一个数据传输的数据通道--连接. pymysql.connect()方法返回的是connections模块下的connection类实例. connect方法传参就是给connection类的 __init__ 提供参数 connection初始化参数 说明 host 主机 user 用户名 password 密码 database 数据库 port 端口 connection.ping()方法,测试数据库服务器是否存活,有一个参数reconnect表示断开与服务器连接是否重连. 操作数据库,必须使用游标,首先要获取一个游标对象. connection.cousor(cursor=none)方法返回一个新的游标对象. 连接没有过关闭前,游标对象可以反复使用. cursor参数,可以指定一个cursor类,如果为none,默认使用cursor类. 数据库操作需要使用cursor类的实例,提供execute()方法,执行SQL语句,成功返回影响的行数. 增删相同,注意要conn.commit() ,sql语句实现具体功能 import pymysql ### 连接数据库的参数 conn = pymysql.connect(host='localhost

Python3 操作Mysql数据库

匿名 (未验证) 提交于 2019-12-02 22:06:11
Pymysql介绍 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,而Python2中则使用mysqldb。 PyMySQL 遵循 Python 数据库 API v2.0 规范,并包含了 pure-Python MySQL 客户端库。 通用步骤: 1.引入模块 2.获取与数据库的连接 3.执行SQL语句和存储过程 4.关闭数据库连接 PyMySQL 安装 1.打开cmd命令 cd C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts #切换目录 pip install pymysql 数据库连接 import pymysql #模块导入 #打开数据库连接 db = pymysql.connect( host='数据库ip', user='用户名, passwd='密码', db='数据库名', port=3306, charset='utf8' ) #使用 cursor() 方法创建一个游标对象 cursor cursor = db.cursor() #使用 execute() 方法执行 SQL 查询 cursor.execute("SELECT VERSION()") #使用 fetchone() 方法获取单条数据. data = cursor

How to make popover appear where my mouse enters the hover target?

三世轮回 提交于 2019-12-02 21:09:37
This is an example code to show the popover window display below my button: $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, { placement: 'bottom', content: '' Now I want the popover window appear on the place where my cursor moves on(not only top/bottom/left/right, but a specific location which depends on where user put their cursor on). How to get it? In bootstrap-tooltip.js, replace (at about line 72) , enter: function (e) { with , enter: function (e) { var mousePos = { x: -1, y: -1 }; mousePos.x = e.pageX; mousePos.y = e.pageY; window.mousePos = mousePos; and replace (at about

Make the divider of an NSSplitView undraggable and don't show the dragging cursor

为君一笑 提交于 2019-12-02 20:34:31
I have an NSSplitView ( NO UISplitView(Controller)!! ) with three subviews. Now, for the last divider (index 1 ), I want the divider to not show the dragging cursor (two arrows pointing out of eachother). I have this to stop the dragging, but the cursor is still showing up: - (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex { if (dividerIndex == 1) { return [splitView frame].size.width - 161; } } Note that I only want to hide the cursor for the divider at index 1 . Can anyone help me? Thanks. :) No, I don't want to

What happens when you forget to close and deallocate cursor?

妖精的绣舞 提交于 2019-12-02 20:07:05
Leaving cursor open is known as a bad practice. But what really happens when you forget to close and/or deallocate it? How does it affect SQL Server, connection/session? Are there any differences in consequences for queries, stored procedures and triggers using cursors? It depends on whether you declared the cursor locally or globally (and what the default is in your environment - default is global but you can change it). If the cursor is global, then it can stay "alive" in SQL Server until the last piece of code is touched in the scope in which it was created. For example if you call a stored

Java: resultset is empty while calling stored procedure with ref cursor as OUT

佐手、 提交于 2019-12-02 19:32:57
问题 I am trying to call a StoredProcedure from Java, but the result returned is always false . In reality, it has to return 100's of records. The connection is established good. I have a stored procedure , PROCEDURE get_records ( grp1 IN a.name%TYPE DEFAULT NULL ,grp2 IN a.name%TYPE DEFAULT NULL ,grp3 IN a.name%TYPE DEFAULT NULL ,grp4 IN a.name%TYPE DEFAULT NULL ,grp5 IN a.name%TYPE DEFAULT NULL ,flag1 IN a.flag%TYPE DEFAULT 'F' ,flag2 IN a.flag%TYPE DEFAULT 'F' ,refercursor_out OUT SYS_REFCURSOR

MYSQL cursor loop, runs one extra round, why?

守給你的承諾、 提交于 2019-12-02 19:18:17
I'm looping through a cursor result set in a MYSQL stored procedure. I'm facing an issue which is that the loop always run thorough the last record twice. Here is my code, BEGIN DECLARE not_found_creadit INT DEFAULT 0; DECLARE cur_credit CURSOR FOR SELECT customer_id, amount, status, user_type, employee, note FROM credit WHERE status = 'approved' AND customer_id = int_cust_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found_creadit = 1; OPEN cur_credit; SET not_found_creadit = 0; credit_loop : LOOP IF not_found_creadit THEN CLOSE cur_credit; LEAVE credit_loop; END IF; FETCH cur_credit

Merging data in a single SQL table without a Cursor

别来无恙 提交于 2019-12-02 18:41:17
I have a table with an ID column and another column with a number. One ID can have multiple numbers. For example ID | Number 1 | 25 1 | 26 1 | 30 1 | 24 2 | 4 2 | 8 2 | 5 Now based of this data, in a new table, I want to have this ID | Low | High 1 | 24 | 26 1 | 30 | 30 2 | 4 | 5 2 | 8 | 8 As you can see, I want to merge any data where the numbers are consecutive, like 24, 25, 26. So now the low was 24, the high was 26, and then 30 is still a separate range. I am dealing with large amounts of data, so I would prefer to not use a cursor for performance sake (which is what I was previously doing

Volley or Service with cursor loader

时光总嘲笑我的痴心妄想 提交于 2019-12-02 18:29:12
I almost always use a Service when I download data from a web service. I store the result in a database and displays the result in my view using a cursor loader. But after Google released the network library Volley I have become a bit confused. The volley library uses async tasks instead of a Service and it doesn't use cursors. I thought that I was supposed to avoid async task and store my data in a database so that I could handle orientation changes properly - without loosing data and having the need to download the data again. So my question is, when should I use Volley instead of my own