paulftw / hiberlite

C++ ORM for SQLite
BSD 3-Clause "New" or "Revised" License
714 stars 118 forks source link

unsigned long long #16

Closed yuklai closed 8 years ago

yuklai commented 9 years ago

Hi there, I have a member of a model that I would like to use unsigned long long as the type, but compilation failed at hiberlite::access::hibernate's c.hibernate(a) call because "Member reference base type 'unsigned long long' is not a structure or union". I see that long long is allowed.

Is it possible to resolve this? Also, is it possible to use enum and map it to an integer type for example? Thanks!

nirbadichi commented 8 years ago

Hi did you manage to solve the issue? I got the same problem

paulftw commented 8 years ago

Could you provide a code snippet to reproduce this?

nirbadichi commented 8 years ago
// TestApp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace std;

class Person;
class Company;

class Company {
    friend class hiberlite::access;
    template <class Archive>
    void hibernate(Archive& ar)
    {
        ar & HIBERLITE_NVP(name);
        ar & HIBERLITE_NVP(address);
        ar & HIBERLITE_NVP(phone);
        ar & HIBERLITE_NVP(money);
    }
public:
    string name;
    string address;
    string phone;
    unsigned long long money;
};
HIBERLITE_EXPORT_CLASS(Company)

class Person{
    friend class hiberlite::access;
    template<class Archive>
    void hibernate(Archive & ar)
    {
        ar & HIBERLITE_NVP(name);
        ar & HIBERLITE_NVP(age);
        ar & hiberlite::sql_nvp< decltype(employer) >("employer",employer);
        ar & HIBERLITE_NVP(bio);
    }
public:
    string name;
    double age;
    Company employer;
    vector<string> bio;
};
HIBERLITE_EXPORT_CLASS(Person)

hiberlite::Database* getDB() {

    cout << "Database setup ..." << endl;
    hiberlite::Database* db = new hiberlite::Database("test.db");
    db->registerBeanClass<Person>();
    db->registerBeanClass<Company>();
    db->dropModel();
    db->createModel();
    cout << "Database and schema created" << endl;
    return db;
}

void runtest() {

    hiberlite::Database* db = getDB();

    cout << "Creating records" << endl;

    Company myCompany;
    myCompany.name = "Some name";
    myCompany.address = "Some address";
    myCompany.phone = "012345678";

    Person nir;
    nir.name = "Nir";
    nir.employer = myCompany;
    nir.bio.push_back("Text1");
    nir.bio.push_back("Text2");

    cout << "Copying record into db..." << endl;
    hiberlite::bean_ptr<Person>  p = db->copyBean(nir);
    hiberlite::bean_ptr<Company> c = db->copyBean(myCompany);

    delete db;
    cout << "DB destoryed, test done." << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
    runtest();
}

The error will be due to this line ar & HIBERLITE_NVP(money);because money is unsigned long long