Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding variable types

Status
Not open for further replies.

jaybe38

Programmer
Jan 22, 2002
16
NZ
I'm trying to write a piece of code to export a proprietary DB into XML.
I have a chunk of code to write the XML, but I need to pull a structure in and read from it into the chunk.

Easy enough, but the higher powers need it portable, so if the structure/database changes we don't need to change the XML port.

Anyone got a way to:
A) Read a structure, and find out how many members it has and their datatypes?
B) Look at a variable and find its type?

Any help appreciated...

PS - If you have a piece of C code that'll take a structure and output XML complete with heirarchy, I'll listen!

 
Hey buddy,

What you are talkin of is a database driver that can read the structure of the database. Now if you have a propritory DB you'll have to get information of the headers/footers and encryption methods used in DB. This is something which are entry criteria to your application generating XML.

I had a similar thing done Four years down the line where I had to read from FoxPro database and populate a report and a custom billing system. Also had to populate that database from a hardware device. But in that case, the structure was easy and no encryption was used for the records in the DB.

I hope you understand the complexity and the info you need for your DB->XML program. B-)

bye.

Roy.
user.gif
 
Thanks for that,

Unfortunately, I realise how tricky (or at best clunky) it's going to be.
Also unfortunately, it has to be passed structures. We have db retrieval functions for our database, but none of it maps even vaguely to ODBC, SQL or any other standard interface. I'm forced to accept the structures they give me.

Any other ideas?
 
Humm... well after reading your original question again, the points you mentioned... I have some counter points...

A) If you are reading a structure, how come you dont KNOW the members that make a structure? If you are using a structure from a third party, am sure you can locate the contents (members and type) from the header files supplied with it.

B) You can GUESS the type of a variable by its SIZE. Using sizeof() operator will get you the size of that variable but that varies from OS to OS. On DOS
Code:
char = 1, int = 2
etc... but on Windows
Code:
char = 1, int = 4
etc... but you CANT distinguish between
Code:
unsigned int
and just
Code:
int

I hope it was close to what u want! :)

Roy.
user.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top