Page 1 of 1

Max Min in QxORM

PostPosted: Thu Aug 04, 2011 1:01 pm
by mtfk
Hi,

How can I make query to get min, max value from table?
some thing like that:
"SELECT MAX(id) FROM BOOKS;"

I just found on this forum, that creating complex query is right now impossible - QxOrm (version 1.1.3) but it was quite old post.
Any thing in this topic has change?

If not anyone can show some example how to use directly QtSql query (can I use the same connection that I opened by QxOrm or I need create new one?)

Thanks a lot of any advice.

Re: Max Min in QxORM

PostPosted: Sat Aug 06, 2011 2:43 pm
by QxOrm admin
Hi,

To create complex SQL query, you have to use QtSql module.
This is not supported yet by QxOrm library (version 1.1.7).

To use the same connexion that QxOrm opened, you need the singleton qx::QxSqlDatabase :
Code: Select all
qx::QxSqlDatabase::getDatabase()

This code returns a QSqlDatabase object of Qt library : this is the connexion used by QxOrm library (for current thread).

If not anyone can show some example how to use directly QtSql query

You have a lot of sample on the web.
Here a quick sample :
Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
QSqlQuery   query("SELECT etc...", db);
bool ok = query.exec();