Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值_Python_Sqlite - Fatal编程技术网

搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值

搜索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

我需要搜索searchQuerys列表中的所有值,并使用Python和sqlite获取标题或内容列中显示的所有值

searchQuerys=[苹果、香蕉、无花果] searchQuerys=[苹果、香蕉]

下面的代码工作得很好,但我不喜欢它,而且我觉得它很容易被SQL注入。有没有办法提高它

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_语句,参数