[PyQt] sql database questions
Scott Frankel
frankel at circlesfx.com
Tue Feb 24 21:33:27 GMT 2009
After reading the documentation and working through example code, I'm
still left with a number of questions regarding how to add, close, and
remove databases. Although my app appears to be working properly, I'm
getting an error msg that I'd like to understand and clean up:
QSqlDatabasePrivate::removeDatabase: connection
'qt_sql_default_connection' is still in use, all queries will cease to
work.
When I add a database, I attempt to set its name:
self.db = QtSql.QSqlDatabase.addDatabase("QPSQL")
self.db.setDatabaseName("foo")
The docs say that the connection is referred to by the
connectionName. Though when I call
QtSql.QSqlDatabase.database().connectionName(), it returns
'qt_sql_default_connection'. The QT docs I found for
setDatabaseName() show an example that does not look at all like a
simple name: (DRIVER={Microsoft Access Driver ... And the example
that ships with PyQt demonstrates how to load a db in memory.
Is it possible/wise to remove the default database? Should I call its
close() method first? e.g.:
connectionName = QtSql.QSqlDatabase.database().connectionName()
QtSql.QSqlDatabase.removeDatabase(connectionName)
Thanks in advance for suggestions on how to manage my db connections!
Scott
More information about the PyQt
mailing list