1 Star 0 Fork 0

SEALiu/PyMemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DBFun.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
import sqlite3
def connect_db(url):
"""connect the DataBase"""
return sqlite3.connect(url)
def select(url, sql):
"""execute the select sql"""
conn = connect_db(url)
conn.text_factory = str
r = conn.execute(sql).fetchall()
conn.close()
return r
def update(url, sql):
"""execute update, delete and insert SQL"""
conn = connect_db(url)
conn.text_factory = str
result = conn.execute(sql)
conn.commit()
num = 0
for rows in result:
num += 1
conn.close()
return num
def max_lib(column):
"""返回library中指定列最大值"""
select_sql = "SELECT max(" + column + ") FROM library"
result_list = select('db_pymemo.db', select_sql)
max_lib_id = result_list[0][0]
if max_lib_id:
return int(max_lib_id)
else:
return -1
def max_record(column):
"""返回record中指定列的最大值"""
select_sql = "SELECT max(" + column + ") FROM record"
result_list = select('db_pymemo.db', select_sql)
max_record_id = result_list[0][0]
if max_record_id:
return int(max_record_id[:5])
else:
return -1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sealiu/PyMemo.git
git@gitee.com:sealiu/PyMemo.git
sealiu
PyMemo
PyMemo
master

搜索帮助