我已经开始用C++ libcql
库卡珊德拉的工作..我想用C++与libcql库从卡桑德拉检索数据..将结果存储在C++中的Map中,然后迭代它然后打印出来?
每当我去使用cqlsh
在命令行上和不选择这样的 -
select records from profile_user where user_id = '1';
我总是在定制列表命令行和其下面的输出records
列实际上是一个map
其中关键是e1
和价值是HELLO
。以同样的方式关键是e2
和价值是HELLO
再次..当我在CQL创建的表,我创建的记录为地图为我所用CQL的收集功能..
records
--------------------------------
{'e1': 'HELLO', 'e2': 'HELLO'}
现在来到C++世界 -
现在我试图从C++ libcql library
获取同样的事情...我将运行在以上C++选择查询相同,我想回到一个地图,这将有e1, e2 as the key
和HELLO as there value inside that map
...它有可能在C++中做到这一点?
/**
* This method will retrieve the data from Cassandra..
* And then call print_rows method to print it out on the console
*/
void get_attributes(string id){
try{
// some code
//Connection open
connection_open();
execute_query("USE testks;");
//this will give me the result back of the select query
cql_result_t& result = execute_query("select * from profile_user where key ='"+id+"';");
// and this is printing it out on the console
print_rows(result);
// some code
} catch (int e){
// some code here
}
}
下面是这将运行我的C++程序后,打印出来的控制台对结果的方法 -
/**
* This method prints out the result on the console.. *
*
*/
void print_rows(cql::cql_result_t& result) {
while (result.next()) {
for (size_t i = 0; i < result.column_count(); ++i) {
cql::cql_byte_t* data = NULL;
cql::cql_int_t size = 0;
result.get_data(i, &data, size);
std::cout.write(reinterpret_cast<char*>(data), size);
std::cout << " | ";
}
std::cout << std::endl;
}
}
,我在控制台上看到运行我的C以上后,结果++程序是一样的东西这 -
e1HELLOe2HELLO |
但是我期待的是 - 。结果存储在C++中的地图,以这样的方式使得键应该是e1 and e2
在地图中。并且它们的值应该是HELLO
在同一个Map中...然后迭代Map并在C++中输出结果?这可能与我现有的代码有关吗?
如果是的话,任何人都可以提供一个简单的例子吗?谢谢...
它基本上是一个C++的问题,我想..只是检索数据,并把它放到地图......但我面临的问题是我的背景是完全用Java所以有一点困难时期要弄清楚如何做到这一点...
你一定已经考虑过'std :: map'了吧? –
是的..这就是我在想或无序地图,以及效率,因为我正在阅读,无序图是有效的... – ferhan
所以你唯一的问题是如何拉'结果'来到'print_rows'到'std :: map ',对吗? – P0W