06-01-2014 01:58 PM - edited 06-01-2014 01:59 PM
In my app, I have a pointer to a SqlDataAccess object that get created when the app starts:
In my DbAdapter.h, in the DbAdapter class:
In my DbAdapter.cpp, in a function DbAdapter:: open(void):
m_sqlDataAccess = new SqlDataAccess(QDir::home().absoluteFilePath(s_data
Then I have a bunch of functions in my DbAdapter class to create tables, insert, delete, update, query data, etc, and they all work fine.
Now I want to impliment a function where the code can close the database. It might need to close it so it can delete the database file at user request, or so the database file can be cleanly uploaded to a server, etc.
I added a DbAdapter::close(void) function with:
m_sqlDataAccess = NULL;
After I run this close() function, next time I call open() again, I get this warning in the console output:
QSqlDatabasePrivate::addDatabase: duplicate connection name '(path to my database file)', old connection removed.
How am I supposed to cleanly shut down the SqlDataAccess object?
Is this a bug in the SqlDataAccess destructor? Shouldn't it clean up whatever it set up in the constructor?
I wonder if this is related:
I have tried to add support for transactions using:
But I don't think they are working because I don't see a journal file being created during the transaction in the folder where the database file is, . On other platforms I do see journal file being created and removed during the transactions. The transactions can be lengthy, and I've set breakpoints, so I don't think the journal file is getting created and removed without me seeing it. Could the journal file be in some other place in the filesystem?
When I get the QSqlDatabase object from the ->connection() function, is that only a temporary copy of the connection, which goes away when the code goes out of scope? I was assuming it was a reference to some kind of "one and only permanent conenction object used internally to the SqlDataAccess object".
Thanks for any ideas,
06-01-2014 02:52 PM
This has been discussed a few times in the forums with various solutions put forward, I've tried them all and many others and still see these warnings. In the end I gave up trying to get rid of them and just accepted it, as for what's going on internally it is hard to say.