我试图用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中它只返回一个值。你知道吗
有人知道为什么吗?你知道吗
我建议您仔细阅读文档,看看您要做什么:
https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.fetchone
此外,这里有一篇博客文章,介绍了您正在尝试使用“fetchone”做的事情。你基本上没有正确处理你的结果集。你知道吗
这并不是使用您正在使用的确切模块,但其思想是相同的。你知道吗
http://kushaldas.in/posts/fetching-row-by-row-from-mysql-in-python.html
相关问题 更多 >
编程相关推荐