[Qt-interest] QSqlDatabase with Sqlite question
Duane Hebert
spoo at flarn.com
Thu Nov 19 18:48:18 CET 2009
"KC Jones" <kc at asperasoft.com> wrote in message news:844001bb0911190938v6c8d072cw66f6a058f9b7e8f6 at mail.gmail.com...
> Frankly, I do not see why the call to QSqlDatabase::close() is not
> sufficient. If I call close() on a connection, then try an access
> queries previously created on that connection, that would be my bug.
> Calling close() should do exactly what it says -- close the
> connection. What ellse does it do?
>
> I'd almost be willing to overlook the message, but it is fouling up my
> test code, making it hard to differentiate a clean run from a dirty
> one (which is a topic for another thread about how to improve
> QTestLib). I really would like to figure out how to squelch this one.
> So indulge me. If I understand what you're saying, the following
> modified code should be message free. But it is not:
>
> #include <QtCore>
> #include <QtSql>
>
> int main(int argc, char *argv[])
> {
> QCoreApplication a(argc, argv);
>
> QSqlDatabase connection = QSqlDatabase::addDatabase("QSQLITE");
>
> connection.setDatabaseName("./test.db");
> connection.open();
> {
> QSqlQuery* q = new QSqlQuery();
> q->exec("CREATE TABLE foo2 ( id integer PRIMARY KEY, bar integer );");
> delete q;
> }
> connection.close();
>
> QSqlDatabase::removeDatabase(connection.connectionName());
>
> return a.exec();
> }
>
You need to do
connection = QSqlDatabase();
And I don't find that very intuitive either. Calling close() should work as expected
IMO.
More information about the Qt-interest-old
mailing list