从数据库输出第二列
我想返回或从数据库中读取所有列中的所有数据,以便例如检查“电子邮件”列是否包含特定的电子邮件。
如果我这样运行代码,我会正确地获得第一个电子邮件地址,但第二个电子邮件地址没有。
使用我可以正确正确的地方,但是后来我每次都必须查找ID号并调整代码。
如何输出第二列?
from operator import index
from PySide6.QtWidgets import QApplication, QMainWindow
from userpasswort.xy import Ui_MainWindow
from userpasswort.bu.oo import Ui_alper
from PySide6 import QtSql
class fm(QMainWindow, Ui_alper):
def __init__(self):
super().__init__()
self.setupUi(self)
self.newaccount.clicked.connect(self.weiter)
def weiter(self):
main.show()
class Main(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.offene = QtSql.QSqlRelationalTableModel()
self.offene.setTable('info')
self.continue_2.clicked.connect(self.datenbank)
def datenbank(self):
model = self.offene
query = QtSql.QSqlQuery()
query.exec( "SELECT email FROM info ")
query.first()
print(query.value(0)) **#here i get the correct email adress**
print(query.value(1)) **#here i get NON**E
model.select()
db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('userpasswort.sqlite')
app = QApplication()
main = Main()
mf= fm()
mf.show()
app.exec()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如有记录,给您第一个结果。因此,没有其他结果将是此响应的一部分。
我建议用 query.next()在一段时间内:
As documented, query.first() gives you the first result. Hence, no other result will be part of this response.
I would suggest replacing query.first() with query.next() in a while loop: