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

sqlite3数据库接口打包

2012-10-14 
sqlite3数据库接口封装大家好,我现在在用sqlite数据,我要给出这个一个API,提取出数据库里的原始数据,不要

sqlite3数据库接口封装
大家好,我现在在用sqlite数据,我要给出这个一个API,提取出数据库里的原始数据,不要用sqlite3_get_table函数,而要用sqlite3_prepare接收sql语句,
用sqlite3_step的返回值组成循环,
最后调用sqlite3_finalize函数,将得到的结果的所有信息都放到一个char**的结构里,请问我该怎么写呢,谢谢啦!




[解决办法]

C/C++ code
    sqlite3* db = NULL;    sqlite3_stmt* stmt = NULL;    int result = sqlite3_open("xx.dat", &db);    if (SQLITE_OK != result)    {        return;    }    string sql = "select Data from UserData where Key = @key";    result = sqlite3_prepare(db, sql.c_str(), sql.length(), &stmt, NULL);    if (SQLITE_OK == result)    {        result = sqlite3_bind_text(stmt, 1, "filename", -1, SQLITE_TRANSIENT);        result = sqlite3_step(stmt);        string gpsfile = (string)(const char*)sqlite3_column_text(stmt, 0);    }    sqlite3_finalize(stmt);    sqlite3_close(db); 

热点排行