Python/PyQt5
[PyQt5] QSqlQuery::value: not positioned on a valid record
컴닥
2022. 1. 9. 00:53
반응형
sql = "SELECT note, rating FROM data WHERE id=1234"
query = QSqlQuery(sql)
query.first()
print(query.value(0))
print(str(query.value(1))
데이터가 없는 데 query.first() 등을 실행할 때
value: not positioned on a valid record
경고가 발생한다.
작동은 되지만 보기 좋지 않다.
sql = "SELECT note, rating FROM data WHERE id=1234"
query = QSqlQuery(sql)
if query.first():
print(query.value(0))
print(str(query.value(1))
이렇게 if문으로 처리해 주면 깔끔....
반응형