<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Matt Newell <newellm@blur.com></b>
</font>
<p><font size=1 face="sans-serif">04.05.2007 19:45</font>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">An</font></div>
<td valign=top><font size=1 face="sans-serif">pyqt@riverbankcomputing.com,
marion.balthasar@ise.fraunhofer.de</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Kopie</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Thema</font></div>
<td valign=top><font size=1 face="sans-serif">Re: [PyQt] Database Connection</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>On Friday 04 May 2007 06:14, marion.balthasar@ise.fraunhofer.de
wrote:<br>
> Hello list,<br>
><br>
> I'm quite new to Python and PyQt. So I would be very thankful, if
anyone<br>
> could help me with my starting problems...<br>
><br>
> I'm planning to write some Python Plugins for QuantumGIS. The function
of<br>
> those Plugins should be to connect to a PostgreSQL/PostGIS Database
and<br>
> commit SQL-Queries, which in return should export Data through a form<br>
> (written to a comma seperated textfile).<br>
> Does anyone know, if there are any scripting-examples dealing with
that or<br>
> a similar problem, just to get a clou....<br>
><br>
> I'm now experimenting with QtSql Classes, but every try to connect
to my<br>
> database, explained in PyQt's Class reference documentation fails...
(I<br>
> tried with Python interpreter shell)<br>
><br>
> Thanks for every given hint...!<br>
><br>
> greets,<br>
> Marion<br>
<br>
Have you been able to successfully connect to the database via pgadmin
or <br>
another tool from the same machine? What's the error message you
get when <br>
the connect fails(QSqlDatabase.lastError().text())?<br>
<br>
Matt</font></tt>
<br>
<br><tt><font size=2>Hi Matt,</font></tt>
<br>
<br><tt><font size=2>Yes, I've worked with the database many times before
successfully. </font></tt>
<br><tt><font size=2>I've now tried now with somthing like this to manage
access to my database:</font></tt>
<br>
<br><tt><font size=2>from PyQt4.QtSql import *</font></tt>
<br><tt><font size=2>from PyQt4.QtCore import *</font></tt>
<br>
<br><tt><font size=2>class Database:</font></tt>
<br>
<br><tt><font size=2> def __init__(self):</font></tt>
<br>
<br><tt><font size=2> self.db=QSqlDatabase.addDatabase("QPSQL")</font></tt>
<br><tt><font size=2> self.db.setHostName("localhost")</font></tt>
<br><tt><font size=2> self.db.setDatabaseName("klimadaten")</font></tt>
<br><tt><font size=2> self.db.setUserName("postgres")</font></tt>
<br><tt><font size=2> self.db.setPassword("post")</font></tt>
<br><tt><font size=2> </font></tt>
<br><tt><font size=2> self.db.open()</font></tt>
<br><tt><font size=2> self.db.QSqlDatabase.lastError().text()</font></tt>
<br><tt><font size=2> </font></tt>
<br><tt><font size=2> </font></tt>
<br>
<br><tt><font size=2>But when i start "run module" in IDLE there
is no message at all, no error-message, nothing...</font></tt>
<br>
<br><tt><font size=2>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,</font></tt>
<br><tt><font size=2>i have to try out more ways..</font></tt>
<br>
<br><tt><font size=2>I'va also tried </font></tt>
<br>
<br><tt><font size=2>from PyQt4.QtSql import *</font></tt>
<br><tt><font size=2>QSqlDatabase.addDatabase("QPSQL")</font></tt>
<br>
<br><tt><font size=2>in Python Interpreter, then the error-message "QSqlDatabase:
driver not loaded</font></tt>
<br><tt><font size=2>
QSqlDatabase: available drivers <br>
PyQt4.QtSql.QSqlDatabase
object at 0x008E58A0"</font></tt>
<br>
<br><tt><font size=2>I don't really know... I've started the database at
the same time in pgadmin, and everything's fine.</font></tt>
<br><tt><font size=2>Maybe I have to make some more specific determinations
to the driver?</font></tt>
<br><tt><font size=2>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.. :-)</font></tt>
<br>
<br><tt><font size=2>Thanks a lot,</font></tt>
<br>
<br><tt><font size=2>marion</font></tt>
<br>