[PyQt] managing multiple db connections
Scott Frankel
frankel at circlesfx.com
Sat May 29 16:32:38 BST 2010
Using the 2-parameter version of addDatabase() fixes the errors on
launch. Thanks Colin.
Still searching for best ways to access multiple db connections (docs
say it's possible, but don't describe how), I finally came upon the
following two links.
This is an article by Jasmin Blanchette & Mark Summerfield on C++
programming with QT4 Databases: http://www.informit.com/articles/article.aspx?p=1405550
. It points to a QSqlQuery constructor that accepts a db argument.
Bingo!
Here's an article from Linux Journal, by Dave Berton, on asynchronous
DB access: http://www.linuxjournal.com/article/9602?page=0,0.
Scott
On May 29, 2010, at 3:12 AM, Colin McPhail wrote:
> Hi,
>
> On 28 May 2010, at 23:11, Scott Frankel wrote:
>
>>
>> Hi all,
>>
>> What's the best way to manage multiple database connections in an
>> application? Specifically, how can I manage which db connection is
>> used for models, queries, &c.?
>>
>>
>> The documentation says that multiple connections can be declared
>> with a unique name for each on calling addDatabase(). My simple
>> implementation yields errors and doesn't seem to provide a means
>> to load data or call queries on one or the other. For example,
>>
>> db2 = QtSql.QSqlDatabase.addDatabase("QPSQL")
>> db2.setDatabaseName("foo_db")
>>
>> db1 = QtSql.QSqlDatabase.addDatabase("QSQLITE")
>> db1.setDatabaseName(":memory:")
>>
>> This yields the following errors:
>>
>> ...
>
> Have you tried using the two-parameter version of addDatabase(),
> where the second parameter is the unique name? I believe that the
> code above is creating, and then re-creating, the 'default' database.
>
> Regards,
> -- CMcP
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
More information about the PyQt
mailing list