Link to home
Start Free TrialLog in
Avatar of aderounm
aderounmFlag for United States of America

asked on

Saving user defined variables as objects in databases

Is it possible to read and write a user defined struct variable into a DB2, Oracle, or Informix database (or any other database) as a single object?  I want to save structs which contain arrays, for example,


struct MyStruct
{
int firstmember[100]
char secondmember[200]
.....
}


I want to read and write whole structs to the database fields without breaking them down into individual data members. Please refer me to a source of technical info.
Thanks!



Avatar of davidf
davidf

I don't have any technical references to give you but I think I can steer you in the right direction...

Look into what sort of support your DB has for BLOB fields (Binary Large OBjects).  Without support for binary data you won't be able to store C structures in your DB.

 Personally I know little about Oracle and DB2 since I've use
 codebase (dbase compatible) btrieve, ctree or other kinds of
 DB softwares. However some princips are identicals: you need
 to have a field that accept binary codes, special codes that
 are not a well known letter and this was the case of a char
 field in codebase as far I can remember. I've an oracle book  with me (old however) and it seems that a long datatype for a
 field can be as large as 65,536 characters, so enough to store
 a struct. You can use also a random access file in pure C
 that you create yourself if you have compatibility problems to
 cast binary numbers  into a numerical field, but normally it  should work with oracle. all you need is to cast your structure
(ex: in a specific database you'd write

write( (char *) &Mystruct)

 rather than write(MY_array_of_chars)

 and to retrieve it you cast the same way: x=(Mystruct *)read();

 These are arbitrary api's, depend of the database you use, you can replace read and write in such a case. The only thing you
have to do is to cast your structure and make a call by reference.
Avatar of aderounm

ASKER

Please include a technical reference so I can know where to look for info. Thanks.
Adjusted points to 130
ASKER CERTIFIED SOLUTION
Avatar of cwestin
cwestin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a million!