首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

sqlite3 C++查询有关问题

2012-04-02 
sqlite3 C++查询问题!ret sqlite3_exec(Pdb, create table star_table(Name QString, Resume QString)

sqlite3 C++查询问题!
ret = sqlite3_exec(Pdb, "create table star_table(Name QString, Resume QString)", NULL, NULL, &errMsg);


结构: Name Resume
  wang ......
  zhang ......
  yang ......

问下该如何查询zhang并且输出对应的Resume;

[解决办法]
参考该解说:
http://dev.csdn.net/article/74379.shtm
[解决办法]
//定义一条查询语句,其中条件为当english为target时的中文记录

 //print_result_cb为callback函数,在其中可以得到查询的结果,具体见下文
 sprintf(value, "SELECT chinese FROM eng_to_chn where english='%s' ", target);

rc = sqlite3_exec(pDB,
value,
print_result_cb, 0, &errMsg);

if(rc == SQLITE_OK)
{
// #ifdef_debug
cout << "select the record successful!" << endl;
// #endif
}
else
{
// #ifdef_debug
cout << errMsg << endl; 
// #endif
return false;
}

.......

}

//callback回调函数print_result_cb的编写,其中data为sqlite3_exec中的第四个参数,第二个参数是栏的数目,第三个是栏的名字,第四个为查询得到的值得。这两个函数输出所有查询到的结果

int print_result_cb(void* data, int n_columns, char** column_values,
char** column_names)
{
static int column_names_printed = 0;
int i;
if (!column_names_printed) {
print_row(n_columns, column_names);
column_names_printed = 1;
}

print_row(n_columns, column_values);
return 0;
}

从2L大大帖子里找到的
print_result_cb
可以写个容器数据结构,在这个函数中把查询到的结果都添加到里面
然后判断容器中的记录,如果为空,则返回

剩下LZ自己探索把
[解决办法]
select Resume from star_table where Name='zhang';

热点排行