PDA

View Full Version : Qt and Database connection best option



guidupas
18th February 2015, 20:20
Hello all!

Whats is the best solution for database connections using Qt, open the connection when the program starts and close it when the program closes or open and close it every time it is needed?

Thanks a lot.

jefftee
18th February 2015, 22:10
The answer of course is... it depends. There is more overhead opening and closing a database continuously, but if your app only accesses the database once a day or otherwise infrequently, then opening/access/closing would be an acceptable approach.

If you decide to leave the database open for the duration of your program's execution, make sure you commit or rollback transactions as appropriate and QSqlQuery::finish() any prepare statements you may use, as well as QSqlQuery::finish() any queries where you have only read some of the result set. i.e. You should try not to do anything that holds a lock on the database or its tables for a long period of time, etc.

Hope that helps.

Edit: Other considerations are the DB engine, the platform, etc. You didn't state what DB engine you're using, whether the database is accessed via the network or local disk file on your computer, etc.

guidupas
19th February 2015, 13:58
Thanks jthomps, you help me a lot.

I am using firebird database locally in OsX Windows 7 and 8.

Lesiok
19th February 2015, 14:08
Depends on what application is using the database. Write some more.