【发布时间】:2021-01-16 03:19:22
【问题描述】:
我已经使用 sqlite3 和带有 python 的烧瓶框架开发了一个 APIful webapp,我有一个发送 POST 请求的外部客户端,它可以正常工作。
在我的 Windows 环境中,更新查询正常工作,当我尝试在我的 CentOS 环境中执行所有查询时,我的查询返回语法错误,以下代码是:
@app.route('/apis/rcvInfo', methods=['POST'])
def form_to_json():
if request.method == "POST":
table=request.form['table']
status=str(request.form['status'])
####query operations
nEntries = (sendQuery("SELECT COUNT (*) AS RowCnt FROM "+table))[0]
if (nEntries > 0 ):
sendQuery("UPDATE "+table+" SET status = "+status+", lastcheck=CURRENT_TIMESTAMP ORDER BY lastcheck DESC LIMIT 1")
else:
sendQuery("INSERT INTO "+table+" (status) VALUES ("+status+")")
db.get_db().commit()
return json.dumps({'success':True}), 200, {'ContentType':'application/json'} ```
def sendQuery(query):
cursor = db.get_db().cursor()
print (query)
cursor.execute(query)
records = cursor.fetchone()
return records
在我的 Windows 环境中,UPDATE 语句可以正常工作,更新第一行。
但在我的 CentOS 环境中,我收到以下错误消息:
sqlite3.OperationalError: near "ORDER": syntax error
参数(表格、状态)正确。
【问题讨论】:
-
UPDATE 在 SQLite 中真的有 ORDER BY 子句吗?
-
看不到这个错误是如何与操作系统相关的。一般在 SQL 中,
ORDER BY不用于UPDATE动作。 -
From: sqlite.org/lang_update.html#optional_limit_and_order_by_clauses: 如果 SQLite 是使用 SQLITE_ENABLE_UPDATE_DELETE_LIMIT 编译时选项构建的,那么 UPDATE 语句的语法会使用可选的 ORDER BY 和 LIMIT 进行扩展 所以不,在 SQLite 的常见版本中,UPDATE 不支持 ORDER BY。
-
@jarlh 为什么在我的 Windows 环境中它可以工作?
标签: sql python-3.x sqlite flask sql-update