Hi all,

I want to store the result of a SQL query into some kind of container.
Typically, a result consists of several columns, each of which has different types - depending on the query.
E.g., 'select productname, price, stock_count from...' leads to 3 result columns: char, float and int.

My Question is: How should I design a type-safe container?

IMHO a column should be represented by a std::vector. So in the example above we would have a vector<string>, a vector<float> and a vector<int>.
Do you agree so far?

Result columns are to be pooled in a container ('Result table').
And that's my real problem: how to hold pointers or references to the columns in this result table? (create the column: vector<string> *pV = new vector<string>(); ==> pV has to be stored.)
Obviously, as the number of columns may vary depending on the query, we need another vector or list of pointers.

However, the types of result columns are not known at compile time.
The time being, I can't see no other way than using void* - arrays, but I don't like that at all.
Do you have any better ideas?

(hope I could explain my problem fairly clear)

Thanks in advance
max

Depending on how you query the database, your result will come back in an array or other collection anyway, so you will only need to inspect the number of columns returned.
You can treat all results as strings, if necessary.

How are you querying the database?

Depending on how you query the database, your result will come back in an array or other collection anyway, so you will only need to inspect the number of columns returned.
You can treat all results as strings, if necessary.

How are you querying the database?

bro can you please help me, here's my thread..
http://www.daniweb.com/software-development/cpp/threads/414109/1767069

How are you querying the database?

I'm using my own ODBC API - based on the very rudimentary Microsoft API.
So the design of the result table is up to me.
The time being, I'm using a void pointer based result table which I don't like any more.
I tried boost::any, but I didn't like that neither.

You are right, using char values solely could help avoid my problem. That would be an obvious solution, because char values are needed when using the result table as a model for any display component (I'm using FLTK).
But that's not what I want - I want my type safe columns ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.