[PyQt] ODBC QSqlQuery

Linos info at linos.es
Wed Sep 19 11:16:37 BST 2007


Hello, i have a problem with QSqlQuery accessing a dsn in linux, i have no problem with exactly the same code in windows and i check i have correctly
opened the datasource, here i paste the relevant code snippets.


-----------------------------------------------------------------------------------------------------------------------------
import os,  sys, time, re
from PyQt4.QtCore import *
from PyQt4.QtSql import *
from PyQt4.QtGui import *

def conectarMaxdb():
    '''conexion via ODBC con QT a MAXDB'''
    maxdb = QSqlDatabase.addDatabase("QODBC", 'maxdb')
    #maxdb.setDatabaseName("DRIVER={MaxDB (Unicode)};HOSTNAME=192.168.1.20;DATABASE=MAXDB2") --> windows code dsn less
    maxdb.setDatabaseName("DRIVER={MAXDB};ServerNode=192.168.1.20;ServerDB=MAXDB2")  --> linux code dsn less
    #maxdb.setDatabaseName("DATABASE") --> linux code with dsn
    maxdb.setUserName("FAKE")
    maxdb.setPassword("FAKE")
    aperturamaxdb = maxdb.open()
    if not aperturamaxdb:
        QMessageBox.warning(None,  "Error conexion con la DB",  QString("Database Error: %1").arg(maxdb.lastError().text()))
        sys.exit(1)
    return maxdb


if __name__ == "__main__":
    app = QApplication(sys.argv)
    dbmaxdb = conectarMaxdb()
    print dbmaxdb.isOpen() -----> print True
    print dbmaxdb.isValid() ----> print True
    query1maxdb =QSqlQuery(dbmaxdb)
    query1maxdb.exec_(QString("SELECT * FROM DATOS_ANTIGUOS.CLIENTES_ANTIGUO WHERE CLI='011113'"))
    query1maxdb.next()
    print query1maxdb.isValid() ---> print False in linux, True in windows

-----------------------------------------------------------------------------------------------------------------------------


When i use unixODBC commandline  tool isql with "isql DATABASE FAKE FAKE" i can do SQL commands in the datasource, i have tested in gentoo (gentoo
ebuilds) and debian (hand-compiled) with exactly the same results, the same code works well in windows (i only have to uncomment, comment the
setDatabaseName method because changes in param names), anyone knows what can be the problem?


Best Regards,
Miguel Angel.


More information about the PyQt mailing list