import sqlite3
class SqliteUtil():
def __init__(self, file):
# 连接到 SQlite数据库
# 数据库文件是 api_test.s3db,不存在,则自动创建
self.conn = sqlite3.connect('api_test.s3db')
self.cursor = self.conn.cursor()
# def get_cursor(self):
# # 创建一个cursor:
# self.cursor = self.conn.cursor()
# return self.cursor
def exec_sql(self, sql_str):
#执行一条SQL语句
self.cursor.execute(sql_str)
# 返回影响行数
return self.cursor.fetchall()
def commit(self):
#提交事务:
self.conn.commit()
def close(self):
# 关闭cursor
# 关闭conn
self.cursor.close()
self.conn.close()