# encoding: utf-8import sqlite3import _dbiclass LiteDBI(_dbi._DBI): def open(self): ''' 以sqlite3驱动实现创建数据库连接 ''' if 'database' not in self.setting: self.setting['database'] = ':memory:' if not self.conn: self.conn = sqlite3.connect(**self.setting) return def execute(self,script): ''' 以sqlite驱动提供的executescript能力重新定义执行命令 ''' self.conn.executescript(script) self.conn.commit() def Execute(self,scriptfile): ''' 从脚本文件中加载sql命令并执行之 ''' self.execute(open(scriptfile,'r')) def dump(self,ios): ''' 吐出 .dump 的脚本正文 ''' for line in self.conn.iterdump(): ios.write('%s/n' % line)
原文链接:https://www.f2er.com/sqlite/202640.html