Connecting to several databases

Forum for posting problems using QxOrm library

Connecting to several databases

Postby andigor » Fri Jun 08, 2012 12:35 pm

Hi

How can I connect to more than one database in single thread ?
andigor
 
Posts: 14
Joined: Wed May 02, 2012 11:53 am

Re: Connecting to several databases

Postby QxOrm admin » Fri Jun 08, 2012 3:35 pm

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

Re: Connecting to several databases

Postby andigor » Fri Jun 08, 2012 4:57 pm

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 ?
andigor
 
Posts: 14
Joined: Wed May 02, 2012 11:53 am

Re: Connecting to several databases

Postby QxOrm admin » Fri Jun 08, 2012 9:23 pm

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

Re: Connecting to several databases

Postby andigor » Sat Jun 09, 2012 1:24 pm

Ok. Thank you.
andigor
 
Posts: 14
Joined: Wed May 02, 2012 11:53 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 2 guests