gpt4 book ai didi

python - sqlite 用 python 中的日期更新列

转载 作者:太空宇宙 更新时间:2023-11-03 18:31:07 25 4
gpt4 key购买 nike

嗨,我在 sqlite 中有一个表,我在其中添加了一个名为“日期”的列

add_sql = 'ALTER table ' + table_name +' ADD MyDate text;'

然后我想更新此列以包含特定日期。

update_sql = "update " + table_name + " SET MyDate = '2013-03-12';"
con.execute(add_sql)
con.execute(update_sql)

这些命令在命令行中工作正常,但当我从 python 脚本执行时却不行。我得到了日期列,但所有单元格都是空白的。

最佳答案

Python 的 sqlite3 模块试图变得聪明并且 commit automatically before some commands, but not before others .

您应该在需要时调用 commit(),或将 isolation_level 设置为 None

关于python - sqlite 用 python 中的日期更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22368373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com