[PyQt] How to communicate with PostgreSQL?

P. Mathé pmathe at neuf.fr
Sun Jan 27 18:42:05 GMT 2008

Le dimanche 27 janvier 2008, nishith datta a écrit :
> hi all,
> I also have a similar problem, but only with Postgre SQL.
> The db.open() call returns a false and the error says data base driver is not loaded. Can someone advise me how to build postgre support into pyqt.
> I am using pyqt 4.3 on winXP. I also have qt4.3.3 which is open source and compiled with mingw.
> thanks 
> nishith
> ---------------------------------
> Never miss a thing.   Make Yahoo your homepage.

I found pyPgSQL much more "pythonic", this is what I use, as below :

from pyPgSQL import PgSQL as pg

dbName= your_data_base_name

def dbConnect(cClient='utf8'):
        param='::%s' % dbName
        codageClient=str(cClient).replace('_','').replace('-','')  # codageClient must be type str
        if codageClient=='utf8' : cx=pg.connect(param,client_encoding=codageClient,unicode_results=True)
        else : cx=pg.connect(param,client_encoding=codageClient,unicode_results=False)
        curseur.execute("set client_encoding to %s" % codageClient)
        curseur.execute("show client_encoding")
        return [cx,curseur,dbName,codageClient]
        return [None,None,None,None]

More information about the PyQt mailing list