QxOrm without persistent objects?

Open discussion on QxOrm library

QxOrm without persistent objects?

Postby frankiegp » Mon Jun 30, 2014 5:20 pm

Hi to everybody,
I would like to know whether I could exploit QxOrm Query functionalities without creating any C++ classes to be mapped to the tables of a database. I mean:
- I have an existent database managed by a hypothetical DBMS (one among PostgreSQL, MySQL, Oracle, SQLServer and so on);
- I would like to query my database without taking care of the specific dialect of the DBMS.
In other words, I would like to write my queries in some high-level languages (pseudo-sql) and then I would like that my query would be rewritten by QxOrm in the SQL-dialect of the specific DBMS. Is it possible?

Thank you for your consideration, looking forward to your kind reply.

Best,
Pierfrancesco
frankiegp
 
Posts: 4
Joined: Mon Jun 30, 2014 4:59 pm

Re: QxOrm without persistent objects?

Postby qxorm » Mon Jun 30, 2014 7:44 pm

Hello,

Register a class into QxOrm context (using qx::register_class<MyClass> function) is the base thing to do to access to all features provided by QxOrm library.

But you can also use the qx::dao::call_query() function if you want to execute a query without a class registered into QxOrm context.
The first parameter of this function is a qx::QxSqlQuery type : this class provides methods to build a SQL query without having to deal with SGDB specific syntax (for example, it manages the LIMIT keyword for pagination).

The only thing to do is to define a qx::IxSqlGenerator, for example for a PostgreSQL database, you can write :
qx::QxSqlDatabase::getSingleton()->setSqlGenerator(qx::dao::detail::IxSqlGenerator_ptr(new qx::dao::detail::QxSqlGenerator_PostgreSQL()));

You can find more details in the FAQ here : http://www.qxorm.com/qxorm_en/faq.html#faq_280
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: QxOrm without persistent objects?

Postby frankiegp » Tue Jul 01, 2014 10:26 am

Hello,

thank you very much for your prompt reply. I'll try to do what you suggested as soon as possible. If I have issues I will let you know.

Bye
frankiegp
 
Posts: 4
Joined: Mon Jun 30, 2014 4:59 pm

Re: QxOrm without persistent objects?

Postby frankiegp » Tue Jul 01, 2014 4:04 pm

Hi,

I'm sorry to bother you again, I've looked for how to create queries involving more than one table (for instance, joins among different tables or nested queries with IN, NOT IN and so on) but I haven't found anything about this.
More precisely, it's clear how to fetch datas from many tables when you register relations in the QxOrm context. But, in my system, I can't register anything because I don't know nothing about my database at compile-time. I should create my queries on-the-fly at run-time.
You've suggested creating an SQL query by using class qx::QxSqlQuery. But, it seems that qx::QxSqlQuery allows me to fetch data only from one table. Indeed, the qx::QxSqlQuery interface doesn't provide a method to express the FROM clause of an SQL query. How can I do? Thank you in advance.
frankiegp
 
Posts: 4
Joined: Mon Jun 30, 2014 4:59 pm

Re: QxOrm without persistent objects?

Postby qxorm » Tue Jul 01, 2014 9:32 pm

Yes, QxOrm and qx_query have not been designed for that.
But you can try to use the qx::QxSqlQuery::freeText() method to add some custom SQL part to your SQL query.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: QxOrm without persistent objects?

Postby frankiegp » Fri Jul 04, 2014 3:02 pm

Ok, thank you very much for your help.

best,
pierfrancesco
frankiegp
 
Posts: 4
Joined: Mon Jun 30, 2014 4:59 pm


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 13 guests