ways of mapping c++ classes into DBMS tables

B

big vinny

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.
 
M

makc.the.great

big said:
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.
 
B

big vinny

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top