Python code complete update of the parameter data sqlite

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/iCloudEnd/article/details/100523258

Python code complete update of the parameter data sqlite

import sqlite3
'''
from update import *
#数据库名
dbname='a.db'
#唯一标识
mkey='mkey'
#原表名称
a_table='mword'
#原表列名称
a_col='pinyin'
#更新数据来源
select_sql="select pypinyin_dict.pinyin ,pypinyin_dict.mkey from mword ,pypinyin_dict  where mword.mkey = pypinyin_dict.mkey and mword.pinyin like '' "
#更新语句
update_sql="update "+a_table+" set "+a_col +" =? where "+mkey+"=?"

vlist=sql2list(dbname,select_sql)
sql2update(dbname,update_sql,vlist)
'''

def sql2list(dbname,select_sql):
	conn = sqlite3.connect(dbname)
	cursor =conn.execute(select_sql)
	wlist=[]
	for it in cursor:
		wlist.append(it)
	conn.close()
	return wlist



def sql2update(dbname,update_sql,vlist):
	conn = sqlite3.connect(dbname)
	cur = conn.cursor()
	for item in vlist:
		sql = update_sql
		print(sql,item)
		cur.execute(sql, item)
	conn.commit()
	conn.close()



Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/100523258