回复: [odb-users] the id value from the qcreator is inconsistent withthe visual studio

不明真相 icewill9999 at vip.qq.com
Thu Aug 15 20:51:41 EDT 2019


thanks, it's worked!


Best Regards


------------------ 原始邮件 ------------------
发件人: "Sten Kultakangas"<ratkaisut at gmail.com>;
发送时间: 2019年8月15日(星期四) 晚上8:42
收件人: "不明真相"<icewill9999 at vip.qq.com>;

主题: Re: [odb-users] the id value from the qcreator is inconsistent withthe visual studio



Hi

This is not related to OBC, but you should not rely on the undefined values of the variables. Some compilers automatically initialize undefined values to 0, others don't. Sometimes it depends on the command-line options of the compiler (e.g., whether the debugging information is to be placed into the object file)


class BasinInfo{
#pragma db id auto
        unsigned long id_ = 0;
}  



db->persist() ignores the value of the identity member variable.




On Thu, Aug 15, 2019 at 2:38 PM 不明真相 <icewill9999 at vip.qq.com> wrote:

Hi all,
 
 
 i started to learn and use odb 2.4.0 in my project, my team members like to use qt creator to develop our application. and i remove all the qt features of the project and use the MSVC as the building tools.
 
 
 i defined a class with an id like this:
 class BasinInfo{
 #pragma db id auto
         unsigned long id_;
 
 }
 
 
 then i code like this:
 shared_ptr<BasinInfo> binfo(new BasinInfo());
                 cout << "id " << binfo->Id() << endl;
 
 
 
 i get the result 3452816845, if i change the type of id to int, then i get -8421501541. all the results are not what i want, because if i run the code in visual studio i always get 0.
 the value of  id is important to me is because i want to use the id value to decide the next operation.
 
 
 if (binfo->Id() > 0) {
                         //binfo was a persistent object, update it!
                         db->update(binfo);
                 }
                 else {
                         //this is a transient object, need to persist into the db
                         db->persist(binfo);
                 }
 
 
 
 anyone knows how to fix it? thanks in advance!
 
 
 Best Regards


More information about the odb-users mailing list