Project

General

Profile

Wt query tuple with boost

Added by Samuele Pederzini over 3 years ago

Hi, this is my first time using Wt++.
I have a problem with using tuple and dbo

this is my error:

In file included from /usr/local/include/Wt/Dbo/Impl.h:19:0,
                 from /usr/local/include/Wt/Dbo/Dbo.h:11,
                 from hello.C:9:
/usr/local/include/Wt/Dbo/SqlTraits_impl.h: In instantiation of static Result Wt::Dbo::query_result_traits<Result>::load(Wt::Dbo::Session&, Wt::Dbo::SqlStatement&, int&) [with Result = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int> 
:
/usr/local/include/Wt/Dbo/collection_impl.h:188:37:   required from void Wt::Dbo::collection<C>::iterator::shared_impl::fetchNextRow() [with C = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
/usr/local/include/Wt/Dbo/collection_impl.h:151:15:   required from Wt::Dbo::collection<C>::iterator::shared_impl::shared_impl(const Wt::Dbo::collection<C>&, Wt::Dbo::SqlStatement*) [with C = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
/usr/local/include/Wt/Dbo/collection_impl.h:209:9:   required from Wt::Dbo::collection<C>::iterator::iterator(const Wt::Dbo::collection<C>&, Wt::Dbo::SqlStatement*) [with C = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
/usr/local/include/Wt/Dbo/collection_impl.h:446:44:   required from Wt::Dbo::collection<C>::iterator Wt::Dbo::collection<C>::begin() [with C = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
/usr/local/include/Wt/Dbo/QueryModel_impl.h:300:5:   required from void Wt::Dbo::QueryModel<Result>::cacheRow(int) const [with Result = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
/usr/local/include/Wt/Dbo/QueryModel_impl.h:122:15:   required from int Wt::Dbo::QueryModel<Result>::rowCount(const Wt::WModelIndex&) const [with Result = boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>]
hello.C:225:1:   required from here
/usr/local/include/Wt/Dbo/SqlTraits_impl.h:52:33: error: read is not a member of Wt::Dbo::sql_value_traits<boost::tuples::tuple<Wt::Dbo::ptr<Utente>, int>, void>
   sql_value_traits<Result>::read(result, &statement, column++, -1);

This is my code.
include:

#include <iostream>
//dbo
#include <Wt/Dbo/Dbo.h>
#include <Wt/Dbo/backend/MySQL.h>
#include <Wt/Dbo/SqlStatement.h>
#include <Wt/Dbo/SqlConnection.h>
#include <Wt/Dbo/Transaction.h>
#include <Wt/Dbo/QueryModel.h>
#include <Wt/Dbo/SqlTraits_impl.h>
#include <Wt/Dbo/SqlTraits.h>
#include <Wt/Dbo/Impl.h>
//wt base
#include <Wt/WApplication.h>
#include <Wt/WEnvironment.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>
#include <Wt/WBootstrapTheme.h>
#include <Wt/WBootstrapTheme.h>
#include <Wt/WTableView.h>
#include <Wt/WTable.h>
#include <Wt/WString.h>
#include "utente.h"
#include "test.h"
//boost
#include <boost/tuple/tuple.hpp>

code make a tuple:

typedef boost::tuple<dbo::ptr<Utente>, int> Item;

Wt::Dbo::QueryModel<Item> *model = new Wt::Dbo::QueryModel<Item>();

Utente class:

#include <Wt/Dbo/Dbo.h>
#include <string>


namespace dbo = Wt::Dbo;

class Utente : public dbo::Dbo<Utente>
{
public:
  Utente();
    //int id;
    std::string nome;
    std::string cognome;
    //std::string telefono;

    template<class Action>
    void persist(Action& a)
    {
        //dbo::field(a, id,     "id");
        dbo::field(a, nome, "nome");
        dbo::field(a, cognome,     "cognome");
       // dbo::field(a, telefono,     "telefono");
    }
    ~Utente();
};


DBO_EXTERN_TEMPLATES(Utente)

Thanks so much


Replies (2)

RE: Wt query tuple with boost - Added by Bruce Toll over 3 years ago

Hi,

It seems you are using Wt4 and I believe that Wt4 Dbo has built-in support for std::tuple, as opposed to boost::tuples::tuple.

RE: Wt query tuple with boost - Added by Samuele Pederzini over 3 years ago

Thanks,
It works using

typedef std :: tuple <Wt :: Dbo :: ptr <User>, int> Item;
    (1-2/2)