Page 1 of 1

How to close mysql connections?

PostPosted: Tue Nov 22, 2016 8:38 am
by behtgod
For example,I insert data into mysql database with multithread.
In each thread,I call
qx::dao::insert()
.
This will create some connection to connect the database for insert operation,of cause.
But, these connection never been closed until the application shutdown.
That make me a trouble because the connection has a max limit.
Is there had function to close the connection?

Re: How to close mysql connections?

PostPosted: Tue Nov 22, 2016 10:05 am
by qxorm
Hello,

Is there had function to close the connection?

Yes of course.
To get the connection to database for current thread and close it, just write this code :
Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();


QSqlDatabase is a Qt class, the documentation is here : http://doc.qt.io/qt-5/qsqldatabase.html
About QxOrm qx::QxSqlDatabase class, there are some details in the QxOrm manual here : http://www.qxorm.com/qxorm_en/manual.html#manual_310

Re: How to close mysql connections?

PostPosted: Wed Nov 23, 2016 3:10 am
by behtgod
qxorm wrote:Hello,

Is there had function to close the connection?

Yes of course.
To get the connection to database for current thread and close it, just write this code :
Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();


QSqlDatabase is a Qt class, the documentation is here : http://doc.qt.io/qt-5/qsqldatabase.html
About QxOrm qx::QxSqlDatabase class, there are some details in the QxOrm manual here : http://www.qxorm.com/qxorm_en/manual.html#manual_310


Thank you very much!