Page 1 of 1

Connecting to several databases

PostPosted: Fri Jun 08, 2012 12:35 pm
by andigor
Hi

How can I connect to more than one database in single thread ?

Re: Connecting to several databases

PostPosted: Fri Jun 08, 2012 3:35 pm
by QxOrm admin
Hi,

How can I connect to more than one database in single thread ?

Each functions of qx::dao namespace have an optional parameter : QSqlDatabase * pDatabase = NULL.
NULL value means that the connection to database is managed by QxOrm library.
Using this parameter (so without NULL value), you can connect to multiple databases.
So you can create an instance of QSqlDatabase type and pass it to all qx::dao functions...

For more details about QSqlDatabase class, goto the documentation of Qt : http://doc-snapshot.qt-project.org/4.8/ ... abase.html
And for more details about qx::dao namespace, goto here : http://www.qxorm.com/doxygen/html/names ... _1dao.html

Re: Connecting to several databases

PostPosted: Fri Jun 08, 2012 4:57 pm
by andigor
Ok. But it seems that QxOrm library also uses QxSqlDatabase::getSingleton(). So whether the passing of my own QSqlDatabase pointer to qx::dao functions is correct ?

Re: Connecting to several databases

PostPosted: Fri Jun 08, 2012 9:23 pm
by QxOrm admin
As I said in my previous message, if you don t use the optional parameter (so a NULL value is passed by default), then the connection to database is managed automatically by QxOrm library (using qx::QxSqlDatabase singleton).
If you want to provide your own connection to database (for example to use multiple databases), create an instance of QSqlDatase and pass the pointer to all functions of qx::dao namespace (then qx::QxSqlDatabase singleton will not be used).

Re: Connecting to several databases

PostPosted: Sat Jun 09, 2012 1:24 pm
by andigor
Ok. Thank you.