I'm new to PyQt programming and I was asked to build a GUI for a Postgres database. I'm trying to use the QtSql, but when I try to return a value after executing a query, I don't get the value I'm looking for.
db = QSqlDatabase.addDatabase("QPSQL", "aib")
db.setHostName("my address")
db.setDatabaseName("aib")
db.setUserName("mayonnaise")
db.setPassword("ketchup")
ok = db.open()
if ok:
print "open"
query = QtSql.QSqlQuery(db)
sql= "SELECT provincia FROM incendi.incendio where incendio.\"codInc\"='19810101230801'"
q=query.exec_(sql)
print query.numRowsAffected()
j=query.first()
if j:
print "first record"
if query.isValid():
print "valid"
prov=query.value(0)
print str(prov)
When I try to run it this is the output I get:
open
1
first record
valid
<PyQt4.QtCore.QVariant object at 0x00000000030F5388>
The SQL query works fine in pg-admin and returns the expected value, so is anything wrong in the python code?