返回信息流☆─────────────────────────────────────☆
dannybaby (牛仔很忙) 于 (Tue Aug 30 17:16:48 2011) 提到:
比如
"select host_name ,(time-" + date2long + ")/3600 as hour ,count(*) as httpnum from " + tablesList[i] + " group by host_name ,hour ;");
这个返回的是host_name,hour,httpnum 3个列表
用C语言如何获得host_name或其他列表呢,把这些列表分别存储起来,求达人指点,不胜感激
☆─────────────────────────────────────☆
zzcc (Binux <足兆叉虫>) 于 (Tue Aug 30 18:20:38 2011) 提到:
if(mysql_real_query(&mysql_, query.c_str(), query.size())) {
LOG(INFO) << "Error in executing SQL statement:" << query;
LOG(INFO) << "Failed due to MySQL Error:" << mysql_error(&mysql_);
return -1;
}
MYSQL_RES* mysql_result = mysql_store_result(&mysql_);
if (mysql_result) {
/* yes; process rows and free the result set */
int num_rows = mysql_num_rows(mysql_result);
int num_fields = mysql_num_fields(mysql_result);
MYSQL_ROW mysql_row;
unsigned long *lengths;
while (mysql_row = mysql_fetch_row(mysql_result)) {
lengths = mysql_fetch_lengths(mysql_result);
vector<string> tmp;
for (int i = 0; i < num_fields; i++) {
tmp.push_back(mysql_row[i] ? string(mysql_row[i], lengths[i]) : "");
}
result.push_back(tmp);
}
mysql_free_result(mysql_result);
☆─────────────────────────────────────☆
doubleKO (九头鸟龙) 于 (Tue Aug 30 23:58:34 2011) 提到:
建议直接查看MySQL C API手册
http://dev.mysql.com/doc/refman/5.6/en/mysql-fetch-row.html
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
{
printf("[%.*s] ", (int) lengths[i],
row[i] ? row[i] : "NULL");
}
printf("\n");
}
【 在 dannybaby 的大作中提到: 】
: 比如
: "select host_name ,(time-" + date2long + ")/3600 as hour ,count(*) as httpnum from " + tablesList[i] + " group by host_name ,hour ;");
: 这个返回的是host_name,hour,httpnum 3个列表
: ...................
这是一条镜像帖。来源:北邮人论坛 / database / #6777同步于 2012/5/20
Database机器人发帖
[合集] 求解,select返回多个值时如何取得一个
doubleKO
2012/5/20镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。