How to disconnect from sqlite db

Posted:
Wed Feb 08, 2012 10:11 am
by magicu
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
qx::QxSqlDatabase::getSingleton()->setDatabaseName(dbPath);
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
qx::QxSqlDatabase::getSingleton()->setUserName("root");
qx::QxSqlDatabase::getSingleton()->setPassword("");
After the code above executed, the file was locked by QxOrm. Then I want disconnect the link, and delete the db file, how to do?
Re: How to disconnect from sqlite db

Posted:
Wed Feb 08, 2012 10:36 am
by QxOrm admin
Then I want disconnect the link, and delete the db file, how to do?
You can get the current connection used by QxOrm library and close it, like this :
- Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();
For more informations about
QSqlDatabase type, goto Qt documentation :
http://developer.qt.nokia.com/doc/qt-4. ... abase.html
Re: How to disconnect from sqlite db

Posted:
Sat Feb 11, 2012 6:47 am
by Guest
QxOrm admin wrote:Then I want disconnect the link, and delete the db file, how to do?
You can get the current connection used by QxOrm library and close it, like this :
- Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();
For more informations about
QSqlDatabase type, goto Qt documentation :
http://developer.qt.nokia.com/doc/qt-4. ... abase.html
If QxOrm havn't connected to sqlite, qx::QxSqlDatabase::getDatabase() will show an assert error. How to detect db is connected or not?
Re: How to disconnect from sqlite db

Posted:
Mon Feb 13, 2012 8:26 am
by QxOrm admin
If you have an assert, I think you have also a trace in your debugger window, maybe 1 of the following :
- [QxOrm] qx::QxSqlDatabase : parameters are not valid ;
- [QxOrm] qx::QxSqlDatabase : unable to open connection to database ;
- [QxOrm] qx::QxSqlDatabase : unable to find current thread id.
Maybe you have the assert because you have not already defined all parameters to connect to database ?
In that case, it's normal => you must define all parameters to connect to database earlier (first lines of your main for example).