How to disconnect from sqlite db

Forum for posting problems using QxOrm library

How to disconnect from sqlite db

Postby magicu » Wed Feb 08, 2012 10:11 am

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?
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

Re: How to disconnect from sqlite db

Postby QxOrm admin » Wed Feb 08, 2012 10:36 am

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
QxOrm admin
 

Re: How to disconnect from sqlite db

Postby Guest » Sat Feb 11, 2012 6:47 am

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?
Guest
 

Re: How to disconnect from sqlite db

Postby QxOrm admin » Mon Feb 13, 2012 8:26 am

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).
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron