Python代码大全之sqlite通过参数update数据

Python代码大全之sqlite通过参数update数据

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()



你可能感兴趣的:(sqlite,update,sqlite,python,sqlite)