Page 2 of 2

Re: Table with keyword as its name

PostPosted: Wed Jun 06, 2018 6:35 pm
by qxorm
as I'm concurrently connecting to MSSQL and MySQL databases on various threads ... change to associate these settings per sql generator rather than globally?

For now, you can't specify different SQL generators : it is the same in all the application.
What you can do is just specify your own database connexion before calling a query.

I think that this kind of API could be implemented quite easily : in singleton class qx:QxSqlDatabase which store global settings :

1- for all setXXX() methods, add an optional parameter : bool bJustForCurrentThread, for example :
Code: Select all
void setSqlDelimiterForTableName(const QStringList & lst, bool bJustForCurrentThread = false);


2- for all getXXX() methods, we keep current definition, so :
* it gets setting defined in the thread if it exists,
* Otherwise, it gets setting defined at global level.

What do you think with this API ?

Re: Table with keyword as its name

PostPosted: Thu Jun 07, 2018 6:36 am
by JonCat
I should add that occasionally a thread may get reused for either type of database (or even SQLite in some cases)...!

Ideally we should have the ability to set many of the options found in the QxSqlDatabase singleton at the database type level rather than globally, or per thread, to take into account differences in behaviour and configuration of servers. I'm unsure of the best way of identifying this within qxorm given the information you will have available?
Perhaps some information that is found within the QSqlDatabase in use for the current query would be best? Either QSqlDatabase::driverName() or QSqlDatabase::databaseName() as a key into a map of database specific options, and fall back to the singleton options if they aren't defined?

I really appreciate all your work - I'm aware the above suggestion is an incredibly invasive change!

Re: Table with keyword as its name

PostPosted: Thu Jun 07, 2018 6:39 pm
by qxorm
at the database type level rather than globally, or per thread

Here is a new version which implements 3 levels of settings (global >> per thread >> per database) : https://www.qxorm.com/version/QxOrm_1.4.5_BETA_19.zip

All setXXX() methods in qx::QxSqlDatabase class have now 2 optional parameters, for example :
Code: Select all
void setSqlDelimiterForTableName(const QStringList & lst, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);


I didn't test it very much so please let me know if it is working fine.

I really appreciate all your work

Thx !

Re: Table with keyword as its name

PostPosted: Fri Jun 08, 2018 11:40 am
by qxorm
I changed a bit the implementation (it doesn't change the API) + do some optimizations, so here is a new version : https://www.qxorm.com/version/QxOrm_1.4.5_BETA_21.zip
Please let me know if it is working fine.

Re: Table with keyword as its name

PostPosted: Tue Jun 12, 2018 11:49 am
by JonCat
Seems to be working smoothly so far! Thanks!

Re: Table with keyword as its name

PostPosted: Wed Jun 13, 2018 4:22 pm
by qxorm
Seems to be working smoothly so far! Thanks!

Great !

Re: Table with keyword as its name

PostPosted: Thu Aug 16, 2018 7:03 am
by jimmytaker
A small issue with this is still present. Executing the following:
Code: Select all
   QxSqlDatabase::getSingleton()->setDriverName(QStringLiteral("QSQLITE"), true);
        QxSqlDatabase::getSingleton()->setDatabaseName("db.db3", true);
        QxSqlDatabase::getDatabase().open(); //error assert fails


The assert fails here:
Code: Select all
QSqlDatabase QxSqlDatabase::QxSqlDatabaseImpl::getDatabaseByCurrThreadId(QSqlError & dbError)
        if (! isValid())


And this is ofc because after passing "true" for this thread only both m_sDriverName and m_sDatabaseName are empty in:
Code: Select all
bool isValid() const { return (! m_sDriverName.isEmpty() && ! m_sDatabaseName.isEmpty()); }

Re: Table with keyword as its name

PostPosted: Mon Aug 20, 2018 9:32 am
by qxorm
this is ofc because after passing "true" for this thread only both m_sDriverName and m_sDatabaseName are empty in

Yes you are right : there is a small issue with isValid() : the workaround is to define a global setting (not per thread setting) for DriverName and DatabaseName.
I will fix it before releasing the new version.
Thx !