How to persist collections of class data members?

Forum for posting problems using QxOrm library

How to persist collections of class data members?

Postby marat » Tue Jul 17, 2012 8:31 pm

How do I persist datamembers that are defined as collections?

For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

Code: Select all
class ExpTable
{
public:

   std::vector<int> intVec_;

   virtual ~ExpTable() {;}
};

Code: Select all
namespace qx {
template <> void register_class(QxClass<ExpTable>& t)
{
   t.data(&ExpTable::intVec, "intColl');
}


Thanks.
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: How to persist collections of class data members?

Postby QxOrm admin » Wed Jul 18, 2012 8:16 am

Hi,

How do I persist datamembers that are defined as collections?
For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

For std::vector<int>, there is nothing to do, it will be saved into database in XML format automatically.
There is a Q&R in the FAQ about it : http://www.qxorm.com/qxorm_en/faq.html#faq_180
QxOrm admin
 

Re: How to persist collections of class data members?

Postby marat » Wed Jul 18, 2012 3:18 pm

QxOrm admin wrote:Hi,

How do I persist datamembers that are defined as collections?
For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

For std::vector<int>, there is nothing to do, it will be saved into database in XML format automatically.
There is a Q&R in the FAQ about it : http://www.qxorm.com/qxorm_en/faq.html#faq_180


Thanks that works. On a related topic, how do I persist a user defined class (my own) to be persisted via default XML format into a text column?

Code: Select all
Ex:
class UserDefined
{
public:
    UserDefined();
    char* toString();
private:
    int x, y;
};
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: How to persist collections of class data members?

Postby QxOrm admin » Wed Jul 18, 2012 7:16 pm

How do I persist a user defined class (my own) to be persisted via default XML format into a text column ?

If you register your UserDefined class and all its properties into QxOrm context, you have nothing to do => it will be serialized automatically in XML format (default behaviour).
If you don't want to register your own class into QxOrm context, you have to write the boost serialization functions, it's explained in the FAQ here (search ExtObject3D class) : http://www.qxorm.com/qxorm_en/faq.html#faq_180
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 4 guests