[odb-users] Raw SQL statement

Adnan RIHAN axel50397 at gmail.com
Thu Dec 11 05:15:26 EST 2014


Hi Boris,

I have another question related to this one and your most interesting answer:

On 8 décembre 2014 at 12:47:59, Boris Kolpackov (boris at codesynthesis.com(mailto:boris at codesynthesis.com)) wrote:

> #pragma db view object(person)
> struct person_count
> {
> #pragma db column("COUNT(" + person::id_ + ")")
> std::size_t count;
> };
>  
> typedef odb::query query;
>  
> db.query (query::name == "John”);

Let’s say, I have an Invoice table and a Warehouse table. An Invoice can have 2 types: “Sell” and “Inventory” (The first one is obvious, while the second one is to know my current stock).

 ---------
| Invoice |
|---------|
| - _id_  |
| - type  |
| - date  |
 ---------

class Invoice
{
    uint32     m_id;
    QString    m_type;
    QDateTime  m_date;
}


 -----------
| Warehouse |
|-----------|
| - _date1_ |
| - _date2_ |
 -----------

class Warehouse
{
    QDateTime  m_openDate;  // [date1]
    QDateTime  m_closeDate; // [date2]
    Invoice    m_lastStock; // SELECT `id`
                            // FROM `invoices`
                            // WHERE `type` == 'Inventory'
                            // AND `date` > [date1]
                            // AND `date` < [date2]
}


The SQL query is there to know what would be the “query” if I had to write it. Is it possible for ODB, when querying a Warehouse, to automatically set the “m_lastStock”?
I see approximately how it could be done with views, but I don’t see how to tell ODB to find an invoice base on the class date (without manually writing it as an odb::query<>()).

Thanks for your help.
--  
Cordialement, Adnan RIHAN.
Directeur-Gérant de Eolis-Software, société de services informatiques.  

GPG: 5675-62BA (https://keybase.io/max13/key.asc)
-> Si vous n'utilisez pas GPG mais souhaitez quand même m’envoyer un e-mail chiffré: (https://encrypt.to/0x567562BA).



More information about the odb-users mailing list