如何使用django sqlite中的RAW SQL查询执行搜索操作
I'm trying to search string in the STAT
table's detection
field like below:
query = "select detection_class, stream_id, track_id, detection_time, " \
"frame_id" \
" FROM stats where stream_id = %s "\
"detection_class like %%s%% group by track_id; "
with connection.cursor() as cursor:
cursor.execute(query,[stream_id, detection_class])
Here, when I give the word or some character which are contained in detection_class, it returns an error像这样的消息typeError(“不是在字符串格式化期间转换的所有参数”),
。 而且,如果我尝试喜欢dintection_class =%s
它在给出时可以正常工作,而否则将返回无。
I'm trying to search string in the STAT
table's detection
field like below:
query = "select detection_class, stream_id, track_id, detection_time, " \
"frame_id" \
" FROM stats where stream_id = %s "\
"detection_class like %%s%% group by track_id; "
with connection.cursor() as cursor:
cursor.execute(query,[stream_id, detection_class])
Here, when I give the word or some character which are contained in detection_class, it returns an error message like thisTypeError('not all arguments converted during string formatting')),
.
and also if I try like detection_class=%s
it works properly when gives while word else it returns None.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行查询时不要使用字符串格式。而是使用占位符或命名参数。
我相信也可以使用占位持有人方法进行操作,如下所示。
Don't use string formatting when executing queries. Instead use a placeholder OR a named parameter.
I believe it is also possible to do it using the placeholder method as well, as shown below.