Python和Sqlite3返回多行

Python和Sqlite3返回多行,python,sqlite,Python,Sqlite,我试图用python在sqlite中进行查询,但当我在数据库中进行研究时,它只返回最后的输入。像这样 def Busca(self): conn = sqlite3.connect('teste.db') cursor = conn.cursor() valorAtual = str(self.comboBox.currentText()) if valorAtual == "CNPJ": sqlqry =

我试图用python在sqlite中进行查询,但当我在数据库中进行研究时,它只返回最后的输入。像这样

def Busca(self):
        conn = sqlite3.connect('teste.db')
        cursor = conn.cursor()

        valorAtual = str(self.comboBox.currentText())
        if valorAtual == "CNPJ":
            sqlqry = 'SELECT * FROM OrdemServico WHERE CNPJ =' + self.lineEdit_9.text()
            c = cursor.execute(sqlqry)
            retorno = str(c.fetchone())
            retorno = retorno.replace("'","")
            self.textEdit.setText(retorno)
因此,sqlite浏览器中的这个查询返回三个值,但在python中它只返回一个值


有人知道为什么吗?

我建议您仔细阅读文档,看看您想做什么:

此外,这里还有一篇博客文章,介绍了您正在尝试使用“fetchone”进行的操作。您几乎没有正确处理结果集

这并不是使用您正在使用的确切模块,但其思想是相同的


您应该使用returno=strc.fetchall来获得所有结果。按照人们在答案中的建议阅读这些文档会很好。祝你好运谢谢,我需要用fetchall