[PyQt] Database Connection still does not work...

Marion Balthasar daloonia at gmx.de
Tue May 8 11:29:02 BST 2007



My environment variables:


> > set
> Path=C:\Bin;C:\Bat;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;
> >
> C:\python25;C:\Qt\4.2.3\bin;C:\PyQt4.2\;C:\Programme\qgistrunk;C:\mingw\bin
> >;
> >
> C:\Programme\PostgreSQL\8.2;C:\cmake\bin;C:\mingw\include;C:\Programme\Post
> >greSQL\8.2 set PGLIB=C:\Programme\PostgreSQL\8.2\lib
> > set PGINCLUDE=C:\Programme\PostgreSQL\8.2\include
> > set PGBIN=C:\Programme\PostgreSQL\8.2\bin
> > set PGDATA=C:\Programme\PostgreSQL\8.2\data
> > set PGUSER=postgres
> > set QT_DEBUG_PLUGINS=1
> >
> > when I then run Python from shell and just want to test if it's possible
> to  
> creat a connection, the same errormessage occured...:
> > > >from PyQt4.QtSql import *
> > >
> > > QSqlDatabase.addDatabase("QPSQL")
> > >
> > > in Python Interpreter, then the error-message "QSqlDatabase: driver
> not
> > > loaded
> > > QSqlDatabase:
> > > available drivers
> > >  PyQt4.QtSql.QSqlDatabase object at 0x008E58A0"
> >
> > So, I really don't know what goes wrong with this...
> >
> > Would be so great, if anyone can help me to step forward with this stuff
> > :-)
> >
> > Thanks in advance,
> > Marion.
> 
> 
> Would you please paste the python code you are using to connect to the 
> database. 
> 
> Matt


Hi Matt,

first I tried to create the connection with the QtSql Module, as I had now - after hard compiling work - installed qsqlpsqld.dll and libqsqlpsqld.a - 
by the way, i don't know why during the compilation of QT4 all the files have this "d" in the end of file name for example QtCored4.dll instead of
QtCore4.dll, this was the cause of an error which said, Qt libraries not found in %QTDIR%\4.2.3\lib directory, i changed the search-string to QtCored and then it worked... maybe it's this "d" in the end of the drivers-library-filename which is responsible for not loading the driver QPSQL?!!
I'll have to find out... do you know where I have to look for this...

ok, the code ;-) :

from PyQt4.QtSql import *
from PyQt4.QtCore import *

class Database:

    def __init__(db):

        db=QSqlDatabase.addDatabase("QPSQL")
        
        db.setHostName("localhost")
        db.setDatabaseName("klimadaten")
        db.setUserName("postgres")
        db.setPassword("post")
        
        db.open()
        db.QSqlDatabase.lastError().text()
        
--------------next one:

from PyQt4.QtSql import *
from PyQt4.QtCore import *

class Database(object):

    def __init__(self, db):

        self.db = db
        self.db = Database()

    def dbConnect(self, db):
        
        db = QSqlDatabase.addDatabase("QPSQL")
        db.setHostName("localhost")
        db.setDatabaseName("klimadaten")
        db.setUserName("postgres")
        db.setPassword("post")
        
        
        self.db.open()
        print self.db.lastError().text()

    
#    def runQuery (test):
        
#        test.query=QSqlQuery.exec_("SHOW TABLES")
#        print test.query.isActive()
#        exec_(test.query)

Those two codes just do nothing running in IDLE. In Eric4 it's the same, the second code highlights the () in "test()" green...

I'm sure, i have some logical or syntax errors in my code, as I'm not really used to 
writing programming script ( Ihave to practise hard.. :-) )
but I first just want to make sure, the connection works...)



Then, i tried to create a connection with libpq(pyPgSQL):


#ein neuer test  ---DatabaseConnection---

import sys
from pyPgSQL import libpq

try:
    cnx = libpq.PQconnectdb("xy")
except libpq.Error, msg:
    print "Connection failed!"
    print msg
    sys.exit()

Running this script (no matter on which client), causes an error message from windows, saying something
like this: "the command "0x78001d90" directs to memory in "0x00000000". 
The action could not be executed on the memory"...

Hope I could now demonstrate my problems better,
Thanks for every hint,

Best regards,
Marion.


-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


More information about the PyQt mailing list