Oracle OCCI - get column by name instead of index

2.8k views Asked by At

Using oracle OCCI is it possible instead of supplying an index for the column when requesting data from a query resultset, to actually pass the column name and get the data?

So instead of doing: (pseudocode)

std::string query = "SELECT NAME FROM CUSTOMERS;";

std::string myresult = oracle.getString(1); // name column in query

you'd do this:

std::string myresult = oracle.getString("NAME"); //column name to get string from

is there any way to do this? I have looked around, but been unable to find anything, besides perhaps going to fetch the table's metadata.

1

There are 1 answers

2
Cheers and hth. - Alf On BEST ANSWER

I just read the documentation.

It says ResultSet has a method getColumnListMetaData(), which produces a vector of MetaData.

Most probably you can then use MetaData::getString to find the name of column.

And if so then you can use a std::map<string, int> to map the column names back to indices.

And with that nameindex mapping in place you can then implement a getString that takes a query result and column name as arguments.

Possibly someone who has used this particular database can help you better, but it seems that all that was needed was to take a look at the documentation.

Cheers & hth.,