搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值
我需要搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值 searchQuerys=[苹果、香蕉、无花果] searchQuerys=[苹果、香蕉] 下面的代码工作得很好,但我不喜欢它,而且我觉得它很容易被SQL注入。有没有办法提高它搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值,python,sqlite,Python,Sqlite,我需要搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值 searchQuerys=[苹果、香蕉、无花果] searchQuerys=[苹果、香蕉] 下面的代码工作得很好,但我不喜欢它,而且我觉得它很容易被SQL注入。有没有办法提高它 selectStmt = "select id, content, title from table where (content like '%"+searchQuerys[0] +&q
selectStmt = "select id, content, title from table where (content like '%"+searchQuerys[0] +"%' or title like '%" + searchQuerys[0] + "%')"
i=1
while i < len(searchQuerys):
selectStmt += " and (content like '%"+searchQuerys[i] +"%' or title like '%" + searchQuerys[i] + "%')"
i+=1
print(selectStmt)
res = conn.execute (selectStmt)
连接=sqlite3。连接:内存:
只是为了调试
connection.set\u trace\u callbackprint
cursor=connection.cursor
搜索\查询=[苹果、香蕉、无花果]
select_语句=
从表\u name where{where\u子句}.format中选择id、内容、标题
其中,_子句=或.join
内容怎么样?或者像这样的标题?
对于rangelensearch\u查询中的i
复制参数+用百分号换行
参数=[
%{}%.formatsearch_项
对于zipsearch_查询中的tup,请搜索_查询
用于在tup中搜索\u项
]
response=cursor.executeselect_语句,参数