Solution for Custom Query
Added by Samuele Pederzini over 4 years ago
Hi,
I have the problem of making a WTable from a custom query where I don't know the return type.
Are there any possibilities with the DBO?
Ex
SELECT * FROM customers
I expect to design having a WTable having a coloumn each sql fields
Replies (3)
RE: Solution for Custom Query - Added by Korneel Dumon over 4 years ago
Hi Samuele,
this is not possible right now in Wt::Dbo. You can have a look at Session::query() documentation to see how to specify different query return types:
https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a
For the query you show, it seems easiest to me to map the 'customers' table to a c++-class. But of course you have to know the columns to do that.
This might be possible if we add support in SqlStatement and Query classes. If it interests you, please make a feature request.
Korneel
RE: Solution for Custom Query - Added by Korneel Dumon about 4 years ago
This is a bit low-level, but perhaps it works:
- use SqlConnection::prepareStatement to create directly an SqlStatement object
- use SqlStatement::getResult(int column, std::string* value) for each column in the result
I didn't test this, so no guarantees :)
RE: Solution for Custom Query - Added by Samuele Pederzini about 4 years ago
ok it works, but what if the table is not mapped in session?