1 Star 0 Fork 0

jacy/serverpython

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
update_words_time.py 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
import sqlite3
from datetime import datetime
import time
# 注册 datetime 适配器和转换器
def adapt_datetime(dt):
return time.mktime(dt.timetuple())
def convert_datetime(stamp):
return datetime.fromtimestamp(float(stamp))
sqlite3.register_adapter(datetime, adapt_datetime)
sqlite3.register_converter("timestamp", convert_datetime)
def update_words_time():
# 连接到 SQLite 数据库
conn = sqlite3.connect('example.db')
c = conn.cursor()
# 给 words 表添加 add_time 和 last_test_time 列
try:
c.execute('ALTER TABLE words ADD COLUMN add_time DATETIME')
c.execute('ALTER TABLE words ADD COLUMN last_test_time DATETIME')
except sqlite3.OperationalError:
print("列可能已经存在,跳过添加列操作")
# 获取今天的日期
today = datetime.now()
# 更新 words 表中的 add_time 和 last_test_time
c.execute('UPDATE words SET add_time = ?, last_test_time = NULL', (today,))
# 提交更改并关闭连接
conn.commit()
conn.close()
print("数据更新成功!")
if __name__ == "__main__":
update_words_time()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/jacy4code/serverpython.git
git@gitee.com:jacy4code/serverpython.git
jacy4code
serverpython
serverpython
master

搜索帮助