Antwort: Re: [PyQt] Database Connection
marion.balthasar at ise.fraunhofer.de
marion.balthasar at ise.fraunhofer.de
Fri May 4 19:22:47 BST 2007
Matt Newell <newellm at blur.com>
04.05.2007 19:45
An
pyqt at riverbankcomputing.com, marion.balthasar at ise.fraunhofer.de
Kopie
Thema
Re: [PyQt] Database Connection
On Friday 04 May 2007 06:14, marion.balthasar at ise.fraunhofer.de wrote:
> Hello list,
>
> I'm quite new to Python and PyQt. So I would be very thankful, if anyone
> could help me with my starting problems...
>
> I'm planning to write some Python Plugins for QuantumGIS. The function
of
> those Plugins should be to connect to a PostgreSQL/PostGIS Database and
> commit SQL-Queries, which in return should export Data through a form
> (written to a comma seperated textfile).
> Does anyone know, if there are any scripting-examples dealing with that
or
> a similar problem, just to get a clou....
>
> I'm now experimenting with QtSql Classes, but every try to connect to my
> database, explained in PyQt's Class reference documentation fails... (I
> tried with Python interpreter shell)
>
> Thanks for every given hint...!
>
> greets,
> Marion
Have you been able to successfully connect to the database via pgadmin or
another tool from the same machine? What's the error message you get when
the connect fails(QSqlDatabase.lastError().text())?
Matt
Hi Matt,
Yes, I've worked with the database many times before successfully.
I've now tried now with somthing like this to manage access to my
database:
from PyQt4.QtSql import *
from PyQt4.QtCore import *
class Database:
def __init__(self):
self.db=QSqlDatabase.addDatabase("QPSQL")
self.db.setHostName("localhost")
self.db.setDatabaseName("klimadaten")
self.db.setUserName("postgres")
self.db.setPassword("post")
self.db.open()
self.db.QSqlDatabase.lastError().text()
But when i start "run module" in IDLE there is no message at all, no
error-message, nothing...
I think I missed to add parts in the source, but as i'm not really used to
python scripting, i can't figure out now, which one it may be,
i have to try out more ways..
I'va also tried
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"
I don't really know... I've started the database at the same time in
pgadmin, and everything's fine.
Maybe I have to make some more specific determinations to the driver?
I have to study more... if I have news I will tell. It would be great
though if you could tell me more aubout this.. :-)
Thanks a lot,
marion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070504/613f21eb/attachment.html
More information about the PyQt
mailing list