Python
1 前言
一个问题,一篇文章,一出故事。
今天遇到编译版本的Python SQLite版本过低问题,用户代码如下报错如下,
Traceback (most recent call last):
File "test.py", line 6, in
_sqlite3_cursor.execute("update t_TaskLog as a set message='test' where a.id in (select b.id from t_TaskLog2 b where b.id=a.id and b.id<=10)")
sqlite3.OperationalError: near "as": syntax error
执行如下命令查看Python中的SQLite版本,
python -c "import sqlite3; print('Python SQLite Version:', sqlite3.sqlite_version)"
可见如下输出,
Python SQLite Version: 3.7.17
错误是由于当前版本的SQLite不支持as语法关键字,因此报错。
2 最佳实践
2.1 编译安装新版本的SQLite
2.2 确认编译安装后的Python SqLite版本
python -c "import sqlite3; print('Python SQLite Version:', sqlite3.sqlite_version)"
可见如下输出,
Python SQLite Version: 3.51.1
注:代码测试重新跑不报错即可。
没有评论