Oracle OCCI - 按名称而不是索引获取列
使用oracle OCCI 是否可以在从查询结果集中请求数据时不为列提供索引,而是实际传递列名并获取数据?
因此,不要这样做:(伪代码),而是
std::string query = "SELECT NAME FROM CUSTOMERS;";
std::string myresult = oracle.getString(1); // name column in query
这样做:
std::string myresult = oracle.getString("NAME"); //column name to get string from
有什么办法可以做到这一点吗?我环顾四周,但除了可能要获取表的元数据之外,找不到任何东西。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚阅读了文档< /a>.
它说
ResultSet
有一个方法getColumnListMetaData()
,它生成MetaData
的向量
。然后您很可能可以使用 MetaData::getString 来查找列的名称。
如果是这样,那么您可以使用
std::map
将列名称映射回索引。有了 name → index 映射,您就可以实现一个
getString
,它将查询结果和列名作为参数。也许使用过这个特定数据库的人可以更好地帮助您,但似乎所需要的只是查看文档。
干杯&呵呵,,
I just read the documentation.
It says
ResultSet
has a methodgetColumnListMetaData()
, which produces avector
ofMetaData
.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 name → index 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.,