hi, i'm trying to create some or mapping but my values are always empty

here is my source:

/*
  * E_Token.h
  *
  *  Created on: 08.06.2010
  *      Author: tecdroid
  */

#ifndef TOKEN_H_
#define TOKEN_H_

#include "Entity.h"

#define TOKEN_TABLE "token"

class Token: public Entity {
     private:
         int typus;
         int genus;
         int casus;
         int numerus;
         int valenz;
     public:
         typedef shared_ptr<Token> ptr;

  Token(int const id) : Entity (TOKEN_TABLE, id){

}
  Token(const string pName) : Entity (TOKEN_TABLE, pName) {

}
  Token(const string pName, bool const unique) : Entity (TOKEN_TABLE, 
pName, unique){

}
  Token() {
     // TODO Auto-generated destructor stub
}

         int getCasusID() const {
             return casus;
         }

         int getGenusID() const {
             return genus;
         }

         int getNumerus() const {
             return numerus;
         }

         int getTypusID() const {
             return typus;
         }

         int getValenz() const {
             return valenz;
         }

         void setCasusID(int casus) {
             this->casus = casus;
         }

         void setGenusID(int genus) {
             this->genus = genus;
         }

         void setNumerus(int numerus) {
             this->numerus = numerus;
         }

         void setTypusID(int typus) {
             this->typus = typus;
         }

         void setValenz(int valenz) {
             this->valenz = valenz;
         }

         void persist() {
             if (getId() == 0) {

             }
         }

};

namespace soci {
     template<>
     struct type_conversion<class Token> {
             typedef values base_type;

             static void from_base(values const & v, indicator /* ind */,
                     Token & p) {
                 p.setId(v.get<int> ("ID"));
                 p.setName(v.get<std::string> ("NAME"));
                 p.setTypusID(v.get<int> ("TYPUS"));
                 p.setGenusID(v.get<int> ("GENUS"));
                 p.setCasusID(v.get<int> ("CASUS"));
                 p.setNumerus(v.get<int> ("NUMERUS"));
                 p.setValenz(v.get<int> ("VALENZ"));

             }

             static void to_base(const Token & p, values & v, indicator 
& ind) {
                 v.set("ID", p.getId());
                 v.set("NAME", p.getName());
                 v.set("TYPUS", p.getTypusID());
                 v.set("GENUS", p.getGenusID());
                 v.set("CASUS", p.getCasusID());
                 v.set("NUMERUS", p.getNumerus());
                 v.set("VALENZ", p.getValenz());
                 ind = i_ok;
             }
     };
}
#endif /* E_TOKEN_H_ */

entity is declared as followed

/*
  * Entity.h
  *
  *  Created on: 08.06.2010
  *      Author: tecdroid
  */

#ifndef ENTITY_H_
#define ENTITY_H_

#include "../Database/Database.h"
#include "../helper/TinyLog.h"

using namespace logger;

#include <boost/smart_ptr.hpp>
using namespace boost;

#include <string>
using namespace std;

struct Entity {
     private:
         TinyLog *logger;
         Database *sql;

         char const *table;

         int id;
         string name;

     public:
         Entity(char const *pTable, int const id);
         Entity(char const *pTable, const string pName);
         Entity(char const *pTable, const string pName, bool const unique);
         virtual ~Entity();

         int getId() const;
         string getName() const;

         void setId(int pId);
         void setName (string pName);

         void persist ();
};

namespace soci {
     template<>
     struct type_conversion<Entity> {
             typedef values base_type;
             static void from_base(values const & v, indicator /* ind */,
                     Entity & p) {
                 p.setId(v.get<int> ("ID"));
                 p.setName(v.get<std::string> ("NAME"));

             }

             static void to_base(const Entity & p, values & v, indicator 
& ind) {
                 v.set("ID", p.getId());
                 v.set("NAME", p.getName());
                 ind = i_ok;
             }
     };
}

#endif /* ENTITY_H_ */

with these constructors

Entity::Entity(char const *pTable, const int pId): table(pTable), id(pId) {
     *sql << "select * from " << table << " where id = :ID", use(*this);
}

Entity::Entity(char const *pTable, const string pName, bool unique) :
     table(pTable), id(0), name(pName) {

     if (unique) {
         *sql << "select * from " << table << " where name = :NAME", 
use(*this);
     }

     if (id == 0) {
         *sql << "insert into " << table << "(name) values :NAME", 
use(*this);
         *sql << "select * from " << table << " where id = SELECT 
max(id) FROM "
<< table << " WHERE name = :NAME", use(*this);
     }
}

Entity::Entity(char const *pTable, const string pName) :
     table(pTable), name(pName) {
     sql = Database::getInstance();
     logger = TinyLog::getInstance(this, this->table);
}


my test program just creates a test token from database. 'test' token 
exists in database but  isn't read.

am I doing something wrong?

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to