[PyQt] Using PostgreSQL

paolo at paolodestefani.it paolo at paolodestefani.it
Mon Oct 17 11:06:34 BST 2011


Hello
I have a problem using PostgreSQL with pyqt. My pc is a Windows 7 32bit,
i've installed postgresql 9.1 with odbc drivers BUT i want to use it in
pyqt with the native driver. I've wrote a small script to test everything
but this work if i use ODBC, if i use PSQL i get an errore "Driver not
loaded".
This is the code:

    app = QCoreApplication(sys.argv)
    db = QSqlDatabase.addDatabase("QPSQL")
    db.setHostName('localhost')
    db.setPort(5432)
    db.setDatabaseName('TestDB')
    db.setUserName('postgres')
    db.setPassword('*****')
    if db.isOpen():
        db.close()
    if not db.open():
        raise Exception("Error opening database:
{0}".format(db.lastError().text()))
    query = QSqlQuery()
    query.exec_("select * from test_table;")
    while query.next():
        print(query.value(0), query.value(1) )

This code return the error "Driver not loaded". If i change only the
database driver, this line:

    db = QSqlDatabase.addDatabase("QODBC")

I get the correct output:

1 Prova paolo
2 Prova Pippo Baudo

So what's wrong ?

I've cheked qsqlpsql4.dll with dependecy walker and i get this log:

Error: At least one required implicit or forwarded dependency was not
found.
Error: At least one module has an unresolved import due to a missing
export function in an implicitly dependent module.
Warning: At least one module has an unresolved import due to a missing
export function in a delay-load dependent module.

The missing librery should be MSVCR90.DLL but even if i dowload this file
from internet i get the same error.
I've tryed to install Microsoft Visual C++ 2010 runtime (vcredist_x86.exe)
with no success.





More information about the PyQt mailing list