QSqlTableModel and PostgreSQL 12

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

QSqlTableModel and PostgreSQL 12

Sibylle Koczian-3
Hello,

After upgrading from PostgreSQL 11.5 to version 12 I can't use
QSqlTableModel any more, and I don't understand what happens.

First, versions of everything:
PostgreSQL 12 on Windows 10;
PyQt 5.13.1 on ArchLinux (in a virtual machine);
Python 3.7.4.

Using a QSqlQuery with one of my PostgreSQL databases works as expected.

Trying to use a QSqlTableModel (this should run if the names replaced by
*** are adapted):

import logging
import sys
from PyQt5 import QtCore
from PyQt5 import QtSql

def fbConn():
     db = QtSql.QSqlDatabase.addDatabase("QPSQL")
     db.setDatabaseName("***")
     db.setHostName("***")
     db.setUserName("***")
     db.setPassword("***")
     ok = db.open()
     msg = "No error" if ok else f"Database Error: {db.lastError().text()}"
     return (ok, msg)

def create_stamm_model():
     model = QtSql.QSqlTableModel()
     logging.debug("Message by model: %s", model.lastError().text())
     db = model.database()
     logging.debug("Data base tables: %s", db.tables())  # <-- correct
answer
     model.setTable("***")  # <-- name is contained in the list from
db.tables()
     logging.debug("Message by model.setTable: %s",
                   model.lastError().text())  # <-- error, see below
     ok = model.select()
     logging.debug("Message by model.select: %s, successful: %s",
                   model.lastError().text(), ok)
     logging.debug("Model definition: %s", model.selectStatement())
     return model

def main(args):
     logging.basicConfig(level=logging.DEBUG)
     app = QtCore.QCoreApplication(args)
     (ok, msg) = fbConn()
     if ok:
         logging.debug("Message by fbConn(): %s", msg)
     else:
         logging.error(msg)
         sys.exit(1)
     create_stamm_model()
     print("Auf Wiedersehen")

if __name__ == "__main__":
     main(sys.argv)

Result of executing this script:

[sib@krise-arch fussball_tests]$ ./fb_qt_mail.py
DEBUG:root:Message by fbConn(): No error
DEBUG:root:Message by model:
DEBUG:root:Data base tables: ['t_manip', 't_spiel', 't_stamm',
't_ewtab', 't_pps', 't_tab']
DEBUG:root:Message by model.setTable:  Unable to find table t_ewtab
DEBUG:root:Message by model.select:  Unable to find table t_ewtab,
successful: False
DEBUG:root:Model definition:
Auf Wiedersehen

Is this a problem with PyQt5 or with Qt?

Thank you for help,
Sibylle
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QSqlTableModel and PostgreSQL 12

Sibylle Koczian-3
Am 09.10.2019 um 14:37 schrieb Sibylle Koczian:
> Hello,
>
> After upgrading from PostgreSQL 11.5 to version 12 I can't use
> QSqlTableModel any more, and I don't understand what happens.
>
...
>
> Is this a problem with PyQt5 or with Qt?
>

Looks like Qt. I found a very similar bug report: QTBUG-79033. It's not
quite the same: it describes QSqlTableModel.select() failing, while I
see setTable() failing, which comes before.

Will try the Qt forum.

Greetings,
Sibylle

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt