class DBI(object):
"""database interface"""
def __init__(self, conn):
"""keep connection"""
self_conn = conn
def store(self, sql, data):
"""store data into database with given sql"""
curr = self_conncursor()
currexecutemany(sql, data)
self_conncommit()
currclose()
def execute(self, sql, args, kwgs):
"""execute sql on database"""
curr = self_conncursor()
currexecute(sql, args, kwgs)
self_conncommit()
currclose()
def ipager(serial, pagesize):
"""make serial page by page"""
buff = []
for row in serial:
buffappend(row)
if len(buff) >= pagesize:
send, buff, = buff, []
yield send
if len(buff):
yield buff
def tester():
import csv
import sqlite3
dbi = DBI(sqlite3connect(database=":memory:"))
dbiexecute("create table tb_tester (id, key, val, tm)")
sql="insert into tb_tester values (, , , )"
with open(todofile, 'rb') as handle:
for rows in ipager(csvreader(handle), 512):
dbistore(sql, rows)
csv模块是python处理csv类文件的强大工具; 参考 >
ipager将大数据流按指定大小分页, 以节省资源并提升效率;
DBI提供统一的数据库接口 *** 作方法;
以上就是关于python将exce文件含有多个sheet同时l导入sqlserver数据库全部的内容,包括:python将exce文件含有多个sheet同时l导入sqlserver数据库、后端编程Python3-数据库编程、python如何读取CSV信息存入数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)