Programatically create structure [message #40448] |
Wed, 04 August 2004 00:12 |
Michael Wallace
Messages: 409 Registered: December 2003
|
Senior Member |
|
|
I'm far from being a structure guru, but I hope someone out there is.
Is there a clean way to create a structure programmatically? I will
neither know the names of the structure tags nor know their types ahead
of time (i.e. before runtime).
What I want to do is create a structure based on the results returned
from a database query. In the general case, I won't know the columns
returned nor the column types before I execute the query. Once I have
queried the database I can inspect the result set metadata and pull out
column names and column types. Before doing this query I can have a
another query which will return the total number of rows that the second
query will return.
So, I can get the total number of rows, the column names and column
types. What I'd like to do is create a structure appropriate for the
column names and column types. Once the structure is created, I can
replicate it to make an array the same size as number of rows returned.
But how do I create the structure in the middle of my running code?
Everything I've read in the IDL documentation about structures shows the
tag names being set statically. I haven't found any way to set the tag
names to some variable. If I could do that then I'd be past the hurdle
of getting the tag names to match the column names returned. The second
hurdle is to set the correct data type. I suppose I could use some
default at first and then reset the type based on the column type later
on, if necessary. If there were a way to create a structure by first
saying how many fields are present and then march through each of the
field and set the tag name and type, I'd be set. Maybe it exists
somewhere, but it sure doesn't exist the IDL documentation.
I do not have my heart set on using structures if this isn't the way to
go, but I'd like some nice general way to do handle results from a
general query. In certain cases I will know what my query is ahead of
time and then it's no problem since I can create the structure
definition ahead of time, but it break down in the general case. The
general case is always a doozie (just as Einstein).
TIA,
Mike
|
|
|