[odb-users] Pointer as a member of Class

nima chavooshi nima0102 at gmail.com
Tue Sep 16 15:56:00 EDT 2014


Hi again,

Thanks for your guidance. I could resolve the issues.

On Tue, Sep 16, 2014 at 11:29 PM, nima chavooshi <nima0102 at gmail.com> wrote:

> Hi again,
>
> I compiled again my header files with odb and this time, I passed 2
> headers at once into odb. The generated schema has foreign key and
> reference to contact table.
>
>
>
> On Tue, Sep 16, 2014 at 9:28 PM, nima chavooshi <nima0102 at gmail.com>
> wrote:
>
>> Hi Boris,
>>
>> Thanks a lot for your attention. About improvement, I agree with you, but
>> this is only a test program.What I am trying in my main program is :
>>
>> Person * PersonObject;
>> PersonObject = new Person(30,"Nima","Chavoshi","Tehran","09127907641");
>>
>> <removed some codes>
>> auto_ptr<database> db (create_database (argc, argv));
>> transaction t (db->begin ());
>> t.commit ();
>> <removed some codes>
>>
>> About including contact header file to person, I must say, yes. it is
>> already included.
>> Regarding the commands I executed:
>>
>>  odb -d mysql --generate-query --generate-schema person.h
>>  odb -d mysql --generate-query --generate-schema contact.h
>>
>>
>> Best Regards,
>> Nima Chavoshi
>>
>>
>> On Tue, Sep 16, 2014 at 8:18 PM, Boris Kolpackov <boris at codesynthesis.com
>> > wrote:
>>
>>> Hi Nima,
>>>
>>> nima chavooshi <nima0102 at gmail.com> writes:
>>>
>>> > I think I could not explain what I expect. Please kindly see my
>>> classes:
>>>
>>> You are still not telling me what you do and when you expect! I
>>> see your classes and there is nothing particularly wrong with
>>> them (there is a lot of room for improvement from the "good
>>> C++" point of view, but that's another story).
>>>
>>> So based on your previous email I am guessing what you are trying
>>> to do is something like this:
>>>
>>> Person p;
>>> p.ContactPerson = new Contact;
>>>
>>> db.persist (p);
>>>
>>> And expect this call to persist() to store both Person and
>>> Contact in the database. If so, then re-read my previous
>>> reply, which sums up to: "this is not how ODB works".
>>> Instead, you need to do:
>>>
>>> db.persist (p.ContactPerson);
>>> db.persist (p);
>>>
>>>
>>> > And also I doubt about generated schema, because there is no any
>>> > "REFERENCE" keyword in schema then there is no defined relationship
>>> > between 2 tables.
>>>
>>> There should be a foreign key defined in the table for Person. Make
>>> sure also that you #include your Contact header into Person header.
>>> If that doesn't work, tell me exactly what is wrong. And I mean
>>> exactly: exact command lines that you use to invoke ODB, the
>>> schema that you get, etc.
>>>
>>> Boris
>>>
>>
>>
>


More information about the odb-users mailing list