Chinaunix

标题: sqlite关于sqlite3_free_table的使用问题 [打印本页]

作者: crazyCat    时间: 2008-08-05 14:54
标题: sqlite关于sqlite3_free_table的使用问题
因没找到关于Sqlite数据库的专题,只好先发在这里,请帮忙
情况是这样的:
    sqlite3_open("xxx.db", &db);       
    sqlite3_get_table(m_pdb,"select count(*) from tt",&value,&row,&ncol,&err);               
    sqlite3_free_table(value);  //我知道应该加上这一句,可由于某种原因这一步不能执行,
                                               //不执行这一句对程序稳定性有影响么, 望知道的朋友能告知

    sqlite3_close ( db );
  
作者: Godbach    时间: 2008-08-05 15:27
原帖由 crazyCat 于 2008-8-5 14:54 发表
因没找到关于Sqlite数据库的专题,只好先发在这里,请帮忙
情况是这样的:
    sqlite3_open("xxx.db", &db);       
    sqlite3_get_table(m_pdb,"select count(*) from tt",&value,&row,&ncol,&err);               
    sqlit ...


也可以不加,程序结束后系统会给你释放的。
但是最好显式的加上,尤其是在daemon中是必须加上的

[ 本帖最后由 Godbach 于 2008-8-5 15:28 编辑 ]
作者: Godbach    时间: 2008-08-05 15:28
用通俗的一句话就是,你申请了一块内存,但是你没有释放,出现的问题就是内存泄漏
作者: yecheng_110    时间: 2008-08-05 16:47
为什么不能执行?
作者: crazyCat    时间: 2008-08-05 17:20
处理别人的遗留项目
在执行完sqlite3_get_table后,要在其他地方使用value,所以不能释放掉它
作者: yecheng_110    时间: 2008-08-05 17:23
原帖由 crazyCat 于 2008-8-5 17:20 发表
处理别人的遗留项目
在执行完sqlite3_get_table后,要在其他地方使用value,所以不能释放掉它

那后面用了再释放不就行了
作者: Godbach    时间: 2008-08-05 17:43
原帖由 crazyCat 于 2008-8-5 17:20 发表
处理别人的遗留项目
在执行完sqlite3_get_table后,要在其他地方使用value,所以不能释放掉它



那就在程序推出的时候释放吧。最好还是别让系统干这个事情。
作者: mo_yuan_ming    时间: 2008-08-05 17:59
int main(int argc, char **argv)
{
sqlite3 *db;
char *zErr;
int rc;
char *sql;
208 CHAPTER 6 ■ T HE CORE C API
rc = sqlite3_open("test.db", &db);
if(rc) {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
sql = "create table episodes(id int, name text)";
rc = sqlite3_exec(db, sql, NULL, NULL, &zErr);
if(rc != SQLITE_OK) {
if (zErr != NULL) {
fprintf(stderr, "SQL error: %s\n", zErr);
sqlite3_free(zErr);
}
}
sql = "insert into episodes values (10, 'The Dinner Party')";
rc = sqlite3_exec(db, sql, NULL, NULL, &zErr);
sqlite3_close(db);
return 0;
}


这是官方教程里的一个方法 貌似没有 sqlite3_free_table
作者: yecheng_110    时间: 2008-08-05 19:19
原帖由 mo_yuan_ming 于 2008-8-5 17:59 发表
int main(int argc, char **argv)
{
sqlite3 *db;
char *zErr;
int rc;
char *sql;
208 CHAPTER 6 ■ T HE CORE C API
rc = sqlite3_open("test.db", &db);
if(rc) {
fprintf(stderr, "Can't open dat ...

这里都没有sqlite3_get_table
还调用sqlite3_free_table干什么
作者: xi2008wang    时间: 2008-08-05 20:59
原帖由 crazyCat 于 2008-8-5 17:20 发表
处理别人的遗留项目
在执行完sqlite3_get_table后,要在其他地方使用value,所以不能释放掉它

那就不释放了啊




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2