469,575 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

ways of mapping c++ classes into DBMS tables

Hi I've been writing some serializing functions to load/store classes into
db tables. There appears to be 2 ways of doing it,

1) iterative, derived classes store their parent's data before storing
themselves, including the pkey of their parents in their own tables.
This results in each level of inheritence having a table solely for data
specific to that inheritence level.

2) wholesale dump of class into one table. this means every level of
inheritence must take care of all data
that its available to it. Seems straights forward, however can get
complicated with classes with lots of data,
and not needing to rewrite the same code for each level of inheritence just
doesn't seem nice.
What are the common ways its being done my the ummm experts?
Right now I'm going with 1, a side effect appears to be that the tables
generated are somewhat normalised, 2nf at least, 3nf in most cases.
Oct 9 '05 #1
2 1548
big vinny wrote:
the ummm experts?


that would be me, baby!
I do it in reverse direction, ie table -> class.
but, if you just need to store class data, why don't you make one
loader/saver, and include (valid) reference to it in your base class.
so that all descendants could do something like
void MyClass::LoadMe(MyString instance_id) {
this.member = this.loader->Load(instance_id, "member_name");
this.other_member = this.loader->Load(instance_id,
"other_member_name");
...

well, something like that. so you'd have only 1 table for everything.

Oct 10 '05 #2
Heh maybe its me, I'm primarily doing stuff in c++, and tend to think the
class->table way.

Yeah i think i get what you mean, I'm using wxWidgets for the ODBC
interface, they've already abstracted a dbTable and column
class, I guess i could just dump the table in the base class and have the
inherited classes add columns to it.
Argh wished i had thought things through, now i'm in the middle of a
complicated but workable solution....guess i'll refactor it....when i get
round to it :(

thanks for the pointer.

<ma************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
big vinny wrote:
the ummm experts?


that would be me, baby!
I do it in reverse direction, ie table -> class.
but, if you just need to store class data, why don't you make one
loader/saver, and include (valid) reference to it in your base class.
so that all descendants could do something like
void MyClass::LoadMe(MyString instance_id) {
this.member = this.loader->Load(instance_id, "member_name");
this.other_member = this.loader->Load(instance_id,
"other_member_name");
...

well, something like that. so you'd have only 1 table for everything.

Oct 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Fred the man | last post: by
3 posts views Thread by Albretch | last post: by
reply views Thread by Bill | last post: by
3 posts views Thread by news.bahnhofbredband.se | last post: by
1 post views Thread by johnny | last post: by
1 post views Thread by Ram | last post: by
reply views Thread by JO | last post: by
reply views Thread by ishakteyran | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.