Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 38
Registered: ‎02-11-2014
My Device: Q10, Z10, Z30, Passport, Classic
My Carrier: None

How do we close SqlDataAccess?

[ Edited ]

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:


    SqlDataAccess *m_sqlDataAccess;



In my DbAdapter.cpp, in a function DbAdapter:: open(void):


    m_sqlDataAccess = new SqlDataAccess(QDir::home().absoluteFilePath(s_databaseFilename));



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:


    delete m_sqlDataAccess;

    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,

Ed Federmeyer



Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How do we close SqlDataAccess?

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.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.